summaryrefslogtreecommitdiffstats
path: root/headtrack_stereo_demo/src/scenerenderer.cpp
blob: 2fc7042582cda8329e9b3da958bd6d0c6e100ddb (plain)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <GL\glut.h>
#include "typedefs.h"

#define _USE_MATH_DEFINES
#include <math.h>

extern GameState_t g_GameState;

void DrawRasterBox()
{
  double l_dHalfHeight = 0.5 * g_GameState.m_FrustumParms.m_dScreenHeightWorld,
         l_dHalfWidth = l_dHalfHeight * g_GameState.m_FrustumParms.m_dScreenAspect,
         l_dDH = g_GameState.m_FrustumParms.m_dScreenHeightWorld/20.0,
         l_dDW = l_dDH * g_GameState.m_FrustumParms.m_dScreenAspect,
         l_dBoxDepth = g_GameState.m_FrustumParms.m_dScreenHeightWorld,
         l_dVariable;
  
  for (int i = 0; i <= 20; i++)
  {
    l_dVariable = -l_dHalfHeight + (double)i * l_dDH;
    //draw U on xz
    glBegin(GL_LINE_STRIP);
    glColor3d(0.0, 0.0, 1.0);
    glVertex3d(-l_dHalfWidth, l_dVariable, 0.0);
    glVertex3d(-l_dHalfWidth, l_dVariable, -l_dBoxDepth);
    glVertex3d(l_dHalfWidth, l_dVariable, -l_dBoxDepth);
    glVertex3d(l_dHalfWidth, l_dVariable, 0.0);
    glEnd();

    //draw U on yz
    l_dVariable = -l_dHalfWidth + (double)i * l_dDW;
    glBegin(GL_LINE_STRIP);
    glVertex3d(l_dVariable, -l_dHalfHeight, 0.0);
    glVertex3d(l_dVariable, -l_dHalfHeight, -l_dBoxDepth);
    glVertex3d(l_dVariable, l_dHalfHeight, -l_dBoxDepth);
    glVertex3d(l_dVariable, l_dHalfHeight, 0.0);
    glEnd();

    //draw square on xy
    l_dVariable = (double)i * -l_dDH;
    glBegin(GL_LINE_LOOP);
    glVertex3d(-l_dHalfWidth, -l_dHalfHeight, l_dVariable);
    glVertex3d(l_dHalfWidth, -l_dHalfHeight, l_dVariable);
    glVertex3d(l_dHalfWidth, l_dHalfHeight, l_dVariable);
    glVertex3d(-l_dHalfWidth, l_dHalfHeight, l_dVariable);
    glEnd();
  }
}

//void RenderTimers()
//{
//  int l_iWidth = glutGet(GLUT_WINDOW_WIDTH),
//      l_iHeight = glutGet(GLUT_WINDOW_HEIGHT);
//
//  //set up a temporary orthographic projection
//  //save the current projection matrix
//  glMatrixMode(GL_PROJECTION);
//  glPushMatrix();
//  glLoadIdentity();
//  //set up an orthographic projection matrix
//  glOrtho(0.0, (GLdouble)l_iWidth, 0.0, (GLdouble)l_iHeight, -1.0, 1.0);
//  glScaled(1.0, -1.0, 1.0); //invert y-axis
//  glTranslated(0.0, (GLdouble)-l_iHeight, 0.0); //translate the origin to the upper left corner of the screen
//
//  glMatrixMode(GL_MODELVIEW);
//  glLoadIdentity();
//
//  //save the current opengl lighting and depth buffering attributes
//  glPushAttrib(GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT);
//  glDisable(GL_LIGHTING); //disable lighting
//  glDisable(GL_DEPTH_TEST); //disable depth testing
//
//  //draw a background rectangle
//  glBegin(GL_POLYGON);
//    glColor3d(0.5, 0.5, 0.5);
//    glVertex2i(0, 0);
//    glVertex2i(0, 50);
//    glVertex2i(250, 50);
//    glVertex2i(250, 0);
//  glEnd();
//
//  //draw the frame timer
//  char l_pFpsString[256];
//
//  sprintf_s(l_pFpsString, 256, "FPS  : %03.1f", g_pFrameTimer->getTicksPerSecond());
//  size_t l_sStrLen = strlen(l_pFpsString);
//  glColor3d(0.0, 0.0, 0.0);
//  glRasterPos2i(5, 13);
//  for (size_t i=0; i<l_sStrLen; i++)
//    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, l_pFpsString[i]);
//
//  sprintf_s(l_pFpsString, 256, "(Avg: %03.1f)", g_pFrameTimer->getAvgTicksPerSecond());
//  l_sStrLen = strlen(l_pFpsString);
//  //glColor3d(0.0, 0.0, 1.0);
//  glRasterPos2i(125, 13);
//  for (size_t i=0; i<l_sStrLen; i++)
//    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, l_pFpsString[i]);
//
//  //draw the poll timer
//  sprintf_s(l_pFpsString, 256, "POLLS: %03.1f", g_pPollTimer->getTicksPerSecond());
//  l_sStrLen = strlen(l_pFpsString);
//  //glColor3d(0.0, 0.0, 1.0);
//  glRasterPos2i(5, 39);
//  for (size_t i=0; i<l_sStrLen; i++)
//    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, l_pFpsString[i]);
//
//  sprintf_s(l_pFpsString, 256, "(Avg: %03.1f)", g_pPollTimer->getAvgTicksPerSecond());
//  l_sStrLen = strlen(l_pFpsString);
//  //glColor3d(0.0, 0.0, 1.0);
//  glRasterPos2i(125, 39);
//  for (size_t i=0; i<l_sStrLen; i++)
//    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, l_pFpsString[i]);
//
//  glPopAttrib(); //restore attributes
//
//  glMatrixMode(GL_PROJECTION);
//  glPopMatrix(); //restore the previous projection matrix
//
//  glMatrixMode(GL_MODELVIEW);
//  glLoadIdentity();
//}

void RenderScene(void)
{
  //set perspective correction according to the head position
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  DrawRasterBox();

  glPushMatrix();
    glColor3d(1.0, 0.0, 0.0);
    glTranslated(-5.0, 5.0, -15.0);
    glutSolidCube(5.0);
    glColor3d(0.0, 1.0, 0.0);
    glTranslated(10.0, 0.0, 0.0);
    glutSolidCube(5.0);
    glColor3d(0.0, 0.0, 1.0);
    glTranslated(0.0, -10.0, 0.0);
    glutSolidCube(5.0);
    glColor3d(1.0, 1.0, 0.0);
    glTranslated(-10.0, 0.0, 0.0);
    glutSolidCube(5.0);
  glPopMatrix();

  glPushMatrix();
    glColor3d(1.0, 1.0, 0.0);
    glTranslated(-5.0, 5.0, -5.0);
    glutSolidCube(5.0);
    glColor3d(0.0, 0.0, 1.0);
    glTranslated(10.0, 0.0, 0.0);
    glutSolidCube(5.0);
    glColor3d(0.0, 1.0, 0.0);
    glTranslated(0.0, -10.0, 0.0);
    glutSolidCube(5.0);
    glColor3d(1.0, 0.0, 0.0);
    glTranslated(-10.0, 0.0, 0.0);
    glutSolidCube(5.0);
  glPopMatrix();
  
  glColor3d(1.0, 0.0, 1.0);
  glPushMatrix();
  glTranslated(0.0, 0.0, 5.0);
  //glScaled(1.0, 1.0, 10.0);
  glutSolidSphere(2.0, 8, 16);
  glPopMatrix();

  glPushMatrix();
  double angle = double(glutGet(GLUT_ELAPSED_TIME)%4000)/1000.0;
  glTranslatef(0.0, 0.0, -10.0);
  glRotatef(angle * 90.0, 0.0, 1.0, 0.0); 
  glutSolidTorus(3.0, 5.0, 16, 64);
  glPopMatrix();
 
}