Some OpenGL Stuff

I am working with some code that is supposed to help learn openGL stuff. I get some of it, but I am having trouble with one big thing. I am not sure how to get an actor model that is not controlled by the keyboard to move to a specific point on the screen. That is all I want. Just to have a second actor move from say (2,2) to (3,-2). This is just a 2D field with a triangle for the main actor and a square for the second actor. Any suggestions will help.

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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "platform.h"
#include "srt/scheduler.h"

#include "model.h"
#include "controller.h"

#include "model_module.h"
#include "graphics_module.h"

class blob : public actor {
public:
blob(float x, float y) : actor(math::vector2f(x, y)) { }

void render() {
transform();

glBegin(GL_TRIANGLES);
glColor3f(0.5f,0.5f,1.0f);
glVertex3f(0.25f, 0.0f, -5.0f);
glVertex3f(-.5f, 0.25f, -5.0f);
glVertex3f(-.5f, -0.25f, -5.0f);
glEnd();
end_transform();
}
void update(controller& c, float dt) {
if (c.left_key) {
rho += pi / 0.12f * dt;
c.left_key = false;
}
if (c.right_key) {
rho -= pi / 0.12f * dt;
c.right_key = false;
}
if (c.up_key) {
v += .4f * dt;
c.up_key = false;
}
if (c.down_key) {
v -= .1f * dt;
if (v < 0.0) { v = 0.0; }
c.down_key = false;
}
actor::update(c, dt);
rho = 0;
actor::update(c, dt);
}
};

class enemyOne : public actor {
public:
enemyOne(float x, float y) : actor(math::vector2f(x, y)) { }

void render() {
transform();

glBegin(GL_POLYGON);

glVertex3f(-0.2f, -0.2f, 0.0f);
glVertex3f(-0.2f, 0.2f, 0.0f);
glVertex3f(0.2f, 0.2f, 0.0f);
glVertex3f(0.2f, -0.2f, 0.0f);
glEnd();
end_transform();
}
void update(controller& c, float dt) {
while(v < .3){
v += .1f * dt;
rho += pi / 2.0f * dt;
}
actor::update(c, dt);
}
};

int APIENTRY WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
char* lpCmdLine,
int nCmdShow
)
{

model m;
controller control(m);

srt::scheduler scheduler(33);
srt::frame* model_frame = new srt::frame(scheduler.timer(), 0, 1, 2);
srt::frame* render_frame = new srt::frame(scheduler.timer(), 1, 1, 2);
model_frame->add(new model_module(m, control));

render_frame->add(new graphics_module(m));

scheduler.add(model_frame);
scheduler.add(render_frame);

blob* prime = new blob(0.0f, 0.0f);
m.add(prime);
m.set_prime(prime);

enemyOne* primeTwo = new enemyOne(1.0f, 1.0f);
m.add(primeTwo);
m.set_prime(primeTwo);

scheduler.start();
control.start();

return 0;
Last edited on
Anyone?
Topic archived. No new replies allowed.