-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriangle.cpp
More file actions
39 lines (32 loc) · 879 Bytes
/
triangle.cpp
File metadata and controls
39 lines (32 loc) · 879 Bytes
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
#include "triangle.h"
Triangle::Triangle(float x, float y, Color color)
{
this->x = x;
this->y = y;
this->color = color;
float directionVectorLength = sqrt(x*x + y*y);
directionX = x / directionVectorLength;
directionY = y / directionVectorLength;
}
void Triangle::draw(float time)
{
glPushMatrix();
glTranslatef(x, y, 0.0f);
glTranslatef(directionX * time * flySpeed, directionY * time * flySpeed, 0.0f);
glRotatef(rotateSpeed * time, 0.0f, 0.0f, 1.0f);
glBegin(GL_TRIANGLES);
glColor3f(color.r, color.g, color.b);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, 0.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glEnd();
glPopMatrix();
}
void Triangle::setRotationSpeed(float rotateSpeed)
{
this->rotateSpeed = rotateSpeed;
}
void Triangle::setFlySpeed(float flySpeed)
{
this->flySpeed = flySpeed;
}