commit | author | age
|
69b66f
|
1 |
// G4Hub.cpp: implementation of the CG4Hub class.
|
JS |
2 |
//
|
|
3 |
//////////////////////////////////////////////////////////////////////
|
|
4 |
|
|
5 |
|
|
6 |
#include <GL/gl.h>
|
|
7 |
#include <GL/glu.h>
|
|
8 |
#include "G4Hub.h"
|
|
9 |
#include <string.h>
|
|
10 |
|
|
11 |
//////////////////////////////////////////////////////////////////////
|
|
12 |
// Construction/Destruction
|
|
13 |
//////////////////////////////////////////////////////////////////////
|
|
14 |
CG4Hub::CG4Hub()
|
|
15 |
{
|
|
16 |
memset(m_col,0,sizeof(float)*3); // black
|
|
17 |
for (int i=0;i<3;i++)
|
|
18 |
m_senActive[i]=false;
|
|
19 |
}
|
|
20 |
|
|
21 |
CG4Hub::~CG4Hub()
|
|
22 |
{
|
|
23 |
}
|
|
24 |
|
|
25 |
void CG4Hub::SetPnoData(float *pno,int sens)
|
|
26 |
{
|
|
27 |
// float scale=2.0f;
|
|
28 |
// float scale=0.01;
|
|
29 |
float scale=1.0f;
|
|
30 |
memcpy(m_pno[sens],pno,sizeof(float)*6);
|
|
31 |
for (int i=0;i<3;i++)
|
|
32 |
m_pno[sens][i]*=scale;
|
|
33 |
m_senActive[sens]=true;
|
|
34 |
}
|
|
35 |
|
|
36 |
int CG4Hub::GetId()
|
|
37 |
{
|
|
38 |
return m_id;
|
|
39 |
}
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
void CG4Hub::SetId(int id)
|
|
44 |
{
|
|
45 |
m_id=id;
|
|
46 |
}
|
|
47 |
//#include <stdio.h>
|
|
48 |
void CG4Hub::Render(GLUquadric* quadric,float scale)
|
|
49 |
{
|
|
50 |
for (int i=0;i<G4_SENSORS_PER_HUB;i++){
|
|
51 |
|
|
52 |
if (!m_senActive[i])
|
|
53 |
continue;
|
|
54 |
|
|
55 |
// printf("Rendering hub %d, sens %d\n",m_id,i);
|
|
56 |
// m_pno[i][0]+=(m_id*2);
|
|
57 |
// axes mapping
|
|
58 |
// Trkr OpenGl
|
|
59 |
// x -z
|
|
60 |
// y x
|
|
61 |
// z -y
|
|
62 |
|
|
63 |
glColor3fv(m_col[i]);
|
|
64 |
// printf("%.3f %.3f %.3f\n",m_pno[i][0],m_pno[i][1],m_pno[i][2]);
|
|
65 |
|
|
66 |
glPushMatrix();
|
|
67 |
glTranslatef(m_pno[i][1],-m_pno[i][2],-m_pno[i][0]); // ogl(x,y,z)-> trk(y,-z,-x)
|
|
68 |
glRotatef(m_pno[i][3],0.0f,-1.0f,0.0f); // az rot about trk(z), ogl(-y)
|
|
69 |
glRotatef(m_pno[i][4],1.0f,0.0f,0.0f); // el rot about trk(y), ogl(x)
|
|
70 |
glRotatef(m_pno[i][5],0.0f,0.0f,-1.0f); // rl rot about trk(x), ogl(-z)
|
|
71 |
|
|
72 |
glPushMatrix();
|
|
73 |
//////////
|
|
74 |
glScalef(scale,scale,scale);
|
|
75 |
glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT);
|
|
76 |
glPushMatrix();
|
|
77 |
|
|
78 |
glEnable(GL_LINE_SMOOTH);
|
|
79 |
|
|
80 |
glPushMatrix();
|
|
81 |
|
|
82 |
glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
|
|
83 |
gluCylinder( quadric,
|
|
84 |
0.5f, //GLdouble baseRadius,
|
|
85 |
0.5f, //GLdouble topRadius,
|
|
86 |
3.0f, //GLdouble height,
|
|
87 |
40, //GLint slices,
|
|
88 |
2 ); //GLint stacks
|
|
89 |
glTranslatef(0.0f, 0.0f, 3.0f);
|
|
90 |
gluCylinder( quadric,
|
|
91 |
0.5,
|
|
92 |
0.0,
|
|
93 |
1.0,
|
|
94 |
40,
|
|
95 |
2 );
|
|
96 |
glPopMatrix();
|
|
97 |
|
|
98 |
glPushMatrix();
|
|
99 |
// glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
|
|
100 |
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
|
|
101 |
gluCylinder( quadric,
|
|
102 |
0.5f, //GLdouble baseRadius,
|
|
103 |
0.5f, //GLdouble topRadius,
|
|
104 |
3.0f, //GLdouble height,
|
|
105 |
40, //GLint slices,
|
|
106 |
2 ); //GLint stacks
|
|
107 |
glTranslatef(0.0f, 0.0f, 3.0f);
|
|
108 |
gluCylinder( quadric,
|
|
109 |
0.5,
|
|
110 |
0.0,
|
|
111 |
1.0,
|
|
112 |
40,
|
|
113 |
2 );
|
|
114 |
glPopMatrix();
|
|
115 |
|
|
116 |
// +X axis
|
|
117 |
glPushMatrix();
|
|
118 |
glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
|
|
119 |
/// glRotatef(180.0f, 0.0f, -1.0f, 0.0f); // Flip z around to the pos dir -- JCF 1/20/05
|
|
120 |
gluCylinder( quadric,
|
|
121 |
0.5f, //GLdouble baseRadius,
|
|
122 |
0.5f, //GLdouble topRadius,
|
|
123 |
1.5f, //GLdouble height,
|
|
124 |
40, //GLint slices,
|
|
125 |
2 ); //GLint stacks
|
|
126 |
glPushAttrib(GL_CURRENT_BIT);
|
|
127 |
glColor3fv(m_invCol[i]);
|
|
128 |
|
|
129 |
glTranslatef(0.0f, 0.0f, 1.5f);
|
|
130 |
gluCylinder( quadric,
|
|
131 |
0.5f, //GLdouble baseRadius,
|
|
132 |
0.5f, //GLdouble topRadius,
|
|
133 |
1.5f, //GLdouble height,
|
|
134 |
40, //GLint slices,
|
|
135 |
2 ); //GLint stacks
|
|
136 |
|
|
137 |
glTranslatef(0.0f, 0.0f, 1.5f);
|
|
138 |
gluCylinder( quadric,
|
|
139 |
0.5,
|
|
140 |
0.0,
|
|
141 |
1.0,
|
|
142 |
40,
|
|
143 |
2 );
|
|
144 |
glPopAttrib();
|
|
145 |
glPopMatrix();
|
|
146 |
|
|
147 |
// glutSolidSphere( 0.5, 30, 30 );
|
|
148 |
gluSphere(quadric, 0.5, 30, 30 );
|
|
149 |
|
|
150 |
|
|
151 |
glPopMatrix();
|
|
152 |
glPopAttrib();
|
|
153 |
//////////
|
|
154 |
glPopMatrix();
|
|
155 |
glPopMatrix();
|
|
156 |
m_senActive[i]=false; // reset
|
|
157 |
}//end for i
|
|
158 |
}
|
|
159 |
|
|
160 |
void CG4Hub::SetColor(const float *col)
|
|
161 |
{
|
|
162 |
memcpy(m_col,col,sizeof(float)*9);
|
|
163 |
// get inverse for tip
|
|
164 |
BYTE b;
|
|
165 |
for (int i=0;i<3;i++){
|
|
166 |
for (int j=0;j<3;j++){
|
|
167 |
b=(BYTE)(col[i*3+j]*255.0);
|
|
168 |
b=~b;
|
|
169 |
m_invCol[i][j]=(float)b/255.0f;
|
|
170 |
}
|
|
171 |
}
|
|
172 |
}
|