summaryrefslogtreecommitdiffstats
path: root/dev/rays/example.cc
blob: bfccb0544e8eed342dcb5a6f4acf715b74384211 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/** CSci-4611 In-Class Example */

#include "example.h"

#include "config.h"

#include <iostream>
#include <sstream>



Example::Example() : GraphicsApp(1024,768, "MinGfx Example") {
    // Define a search path for finding data files (images and shaders)
    search_path_.push_back(".");
    search_path_.push_back("./data");
    search_path_.push_back(DATA_DIR_INSTALL);
    search_path_.push_back(DATA_DIR_BUILD);
}


Example::~Example() {
}


void Example::UpdateSimulation(double dt)  {
    cam_.UpdateSimulation(dt, window());
}

// You can look around, like in minecraft, by dragging with the right mouse button.
void Example::OnRightMouseDrag(const Point2& mouse_in_pixels, const Vector2& delta_in_pixels) {
    Vector2 delta_in_ndc = PixelsToNormalizedDeviceCoords(delta_in_pixels);
    cam_.OnMouseMove(delta_in_ndc);
}




void Example::OnLeftMouseDown(const Point2& mouse_in_pixels) {

}

void Example::OnLeftMouseDrag(const Point2& mouse_in_pixels, const Vector2& delta_in_pixels) {

}

void Example::OnLeftMouseUp(const Point2& mouse_in_pixels) {

}






void Example::InitOpenGL() {
    // Set up the camera in a good position to see the entire scene
    proj_matrix_ = Matrix4::Perspective(60.0f, aspect_ratio(), 0.01f, 100.0f);
    cam_.set_view_matrix(Matrix4::LookAt(Point3(0,0,3), Point3(0,0,0), Vector3(0,1,0)));
    glClearColor(1,1,1,1);
 
    // load textures and shaders
    dart_tex_.InitFromFile(Platform::FindFile("dartboard.jpg", search_path_));
}


void Example::DrawUsingOpenGL() {
    Matrix4 view_matrix = cam_.view_matrix();

    // draws a set of axes at the world origin, since we are passing the identity
    // matrix for the "model" matrix.
    Matrix4 identity;
    quick_shapes_.DrawAxes(identity, view_matrix, proj_matrix_);

    Matrix4 boardTransform = Matrix4::RotationX(GfxMath::ToRadians(90));
    quick_shapes_.DrawSquare(boardTransform, view_matrix, proj_matrix_, Color(1, 1, 1), dart_tex_);
}