-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAxis.cpp
84 lines (72 loc) · 2.51 KB
/
Axis.cpp
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
#include "Axis.h"
#include <string.h>
/**
* TAxis class
* Params: l length of the axe
*/
TAxis::TAxis(GLfloat l) : TObject3D()
{
ObjectType = otAxis;
size = l;
float textsize = 0.5;
// To do that, GLContext must be defined
if (glutGet(GLUT_INIT_STATE))
{
font_height = textsize / glutStrokeHeight(GLUT_STROKE_MONO_ROMAN);
font_width = textsize / glutStrokeLength(GLUT_STROKE_MONO_ROMAN, (unsigned char *)"X");
}
material.SetColor(mfFront, msAmbient, {0.0, 0.0, 0.0, 1.0});
material.SetColor(mfFront, msDiffuse, {0.5, 0.5, 1.0, 1.0});
material.SetColor(mfFront, msEmission, {0.2, 0.2, 0.2, 1.0});
material.SetColor(mfFront, msSpecular, {0.0, 0.0, 0.0, 1.0});
}
TAxis::~TAxis()
{
}
void TAxis::DoDisplay(TDisplayMode mode)
{
// Don't draw axing in select mode
if (mode == dmSelect)
return;
glLineWidth(3.0f);
glBegin(GL_LINES);
// X axis red
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, colorRed);
glVertex3d(0.0, 0.0, 0.0);
glVertex3d(size, 0.0, 0.0);
// Y axis green
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, colorGreen);
glVertex3d(0.0, 0.0, 0.0);
glVertex3d(0.0, size, 0.0);
// Z axis blue
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, colorBlue);
glVertex3d(0.0, 0.0, 0.0);
glVertex3d(0.0, 0.0, size);
glEnd();
glPushMatrix();
glTranslatef(size, 0.0, 0.0);
glScalef(font_width, font_height, font_width);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, colorRed);
glRotatef(90, 1.0, 0.0, 0.0);
glutStrokeString(GLUT_STROKE_MONO_ROMAN, (unsigned char *)"X");
glPopMatrix();
glPushMatrix();
glTranslatef(0.0, size, 0.0);
glScalef(font_width, font_height, font_width);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, colorGreen);
glRotatef(90, 1.0, 0.0, 0.0);
glRotatef(90, 0.0, 1.0, 0.0);
glutStrokeString(GLUT_STROKE_MONO_ROMAN, (unsigned char *)"Y");
glPopMatrix();
glPushMatrix();
glTranslatef(0.0, 0.0, size);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, colorBlue);
glScalef(font_width, font_height, font_width);
glRotatef(90, 1.0, 0.0, 0.0);
glRotatef(90, 0.0, 1.0, 0.0);
glutStrokeString(GLUT_STROKE_MONO_ROMAN, (unsigned char *)"Z");
glPopMatrix();
}
// ********************************************************************************
// End of file
// ********************************************************************************