Blame view

ManageScene.cpp 4.33 KB
ee96a02c   David Mayerich   first commit from...
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
  /*This file manages the scene details, including:
  	o) Transforming between world and texture coordinates
  	o) Keeping track of the lights and camera
  	o) Rendering the cube geometry for the volume
  */
  
  #include "trueeyes.h"
  #include "VolumeSourceStruct.h"
  #include "GL/glut.h"
  
  //camera used for rendering
  //rtsCamera ViewCamera;
  
  //list of rendering sources
  vector<VolumeSource> SourceList;
  int SelectedSource = 0;
  int RenderSource = 0;
  float StepSize = 0.01;
  bool RenderSources = false;
  
  //size of the volume
  //vector3D<float> VolumeSize = vector3D<float>(1.0, 1.0, 1.0);
  float gpVolSize[3] = {1.0, 1.0, 1.0};
  float gpCropMin[3] = {0.0, 0.0, 0.0};
  float gpCropMax[3] = {1.0, 1.0, 1.0};
  
  void DrawCube()
  {
  	//This function draws the cube representing the bounds of the volume
  	//A fragment shader is used to perform ray-casting
  
  	//if there is no shader selected, exit
  	if(SelectedShader < 0)
  		return;
  
  	
  
  	//update all of the source data
  	point3D<float> p;// = SourceList[RS].S.getPosition();
  	//SourceList[RS].pos[0] = p.x*(1.0/gpVolSize[0])+0.5;
  	//SourceList[RS].pos[1] = p.y*(1.0/gpVolSize[1])+0.5;
  	//SourceList[RS].pos[2] = p.z*(1.0/gpVolSize[2])+0.5;
  
  	for(int s=0; s<SourceList.size(); s++)
  	{
  		p = SourceList[s].S.getPosition();
  		SourceList[s].pos[0] = p.x*(1.0/gpVolSize[0])+0.5;
  		SourceList[s].pos[1] = p.y*(1.0/gpVolSize[1])+0.5;
  		SourceList[s].pos[2] = p.z*(1.0/gpVolSize[2])+0.5;
  	}
  
  	vector3D<float> MinCrop(gpCropMin[0], gpCropMin[1], gpCropMin[2]);
  	vector3D<float> MaxCrop(gpCropMax[0], gpCropMax[1], gpCropMax[2]);
  
  	//compute the cube size
  	vector3D<float> volS = vector3D<float>(gpVolSize[0], gpVolSize[1], gpVolSize[2]);
  	vector3D<float> s = volS*0.5;
  
  	vector3D<float> c_min = MinCrop.Times(volS) - s;
  	vector3D<float> c_max = MaxCrop.Times(volS) - s;
  
  	vector3D<float> t_min = MinCrop;
  	vector3D<float> t_max = MaxCrop;
  
  	//AttachShaderVariables();
  	ShaderList[SelectedShader].glProgram.UpdateGlobalUniforms();
  	ShaderList[SelectedShader].glProgram.BeginProgram();
  	//glutSolidCube(1);
  	glBegin(GL_QUADS);
  		//Z-
  		glTexCoord3f(t_min.x, t_min.y, t_min.z);
  		glVertex3f(c_min.x, c_min.y, c_min.z);
  		glTexCoord3f(t_min.x, t_max.y, t_min.z);
  		glVertex3f(c_min.x, c_max.y, c_min.z);
  		glTexCoord3f(t_max.x, t_max.y, t_min.z);
  		glVertex3f(c_max.x, c_max.y, c_min.z);
  		glTexCoord3f(t_max.x, t_min.y, t_min.z);
  		glVertex3f(c_max.x, c_min.y, c_min.z);
  		//Z+
  		glTexCoord3f(t_min.x, t_min.y, t_max.z);
  		glVertex3f(c_min.x, c_min.y, c_max.z);
  		glTexCoord3f(t_max.x, t_min.y, t_max.z);
  		glVertex3f(c_max.x, c_min.y, c_max.z);
  		glTexCoord3f(t_max.x, t_max.y, t_max.z);
  		glVertex3f(c_max.x, c_max.y, c_max.z);
  		glTexCoord3f(t_min.x, t_max.y, t_max.z);
  		glVertex3f(c_min.x, c_max.y, c_max.z);
  		//X-
  		glTexCoord3f(t_min.x, t_min.y, t_min.z);
  		glVertex3f(c_min.x, c_min.y, c_min.z);
  		glTexCoord3f(t_min.x, t_min.y, t_max.z);
  		glVertex3f(c_min.x, c_min.y, c_max.z);
  		glTexCoord3f(t_min.x, t_max.y, t_max.z);
  		glVertex3f(c_min.x, c_max.y, c_max.z);
  		glTexCoord3f(t_min.x, t_max.y, t_min.z);
  		glVertex3f(c_min.x, c_max.y, c_min.z);
  		//X+
  		glTexCoord3f(t_max.x, t_min.y, t_min.z);
  		glVertex3f(c_max.x, c_min.y, c_min.z);
  		glTexCoord3f(t_max.x, t_max.y, t_min.z);
  		glVertex3f(c_max.x, c_max.y, c_min.z);
  		glTexCoord3f(t_max.x, t_max.y, t_max.z);
  		glVertex3f(c_max.x, c_max.y, c_max.z);
  		glTexCoord3f(t_max.x, t_min.y, t_max.z);
  		glVertex3f(c_max.x, c_min.y, c_max.z);
  		//Y-
  		glTexCoord3f(t_min.x, t_min.y, t_min.z);
  		glVertex3f(c_min.x, c_min.y, c_min.z);
  		glTexCoord3f(t_max.x, t_min.y, t_min.z);
  		glVertex3f(c_max.x, c_min.y, c_min.z);
  		glTexCoord3f(t_max.x, t_min.y, t_max.z);
  		glVertex3f(c_max.x, c_min.y, c_max.z);
  		glTexCoord3f(t_min.x, t_min.y, t_max.z);
  		glVertex3f(c_min.x, c_min.y, c_max.z);
  		//Y+
  		glTexCoord3f(t_min.x, t_max.y, t_min.z);
  		glVertex3f(c_min.x, c_max.y, c_min.z);
  		glTexCoord3f(t_min.x, t_max.y, t_max.z);
  		glVertex3f(c_min.x, c_max.y, c_max.z);
  		glTexCoord3f(t_max.x, t_max.y, t_max.z);
  		glVertex3f(c_max.x, c_max.y, c_max.z);
  		glTexCoord3f(t_max.x, t_max.y, t_min.z);
  		glVertex3f(c_max.x, c_max.y, c_min.z);
  
  
  	glEnd();
  	ShaderList[SelectedShader].glProgram.EndProgram();
  }
  void DrawLights()
  {
  	
  	glColor3f(1.0, 0.0, 0.0);
  	//draw a sphere for each light
  	for(int l=1; l<SourceList.size(); l++)
  	{
  		glPushMatrix();
  		point3D<float> p = SourceList[l].S.getPosition();
  		glTranslatef(p.x, p.y, p.z);
  		glutSolidSphere(0.1, 10, 10);
  		glPopMatrix();
  	}
  
  }