/*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 SourceList; int SelectedSource = 0; int RenderSource = 0; float StepSize = 0.01; bool RenderSources = false; //size of the volume //vector3D VolumeSize = vector3D(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 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 MinCrop(gpCropMin[0], gpCropMin[1], gpCropMin[2]); vector3D MaxCrop(gpCropMax[0], gpCropMax[1], gpCropMax[2]); //compute the cube size vector3D volS = vector3D(gpVolSize[0], gpVolSize[1], gpVolSize[2]); vector3D s = volS*0.5; vector3D c_min = MinCrop.Times(volS) - s; vector3D c_max = MaxCrop.Times(volS) - s; vector3D t_min = MinCrop; vector3D 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 p = SourceList[l].S.getPosition(); glTranslatef(p.x, p.y, p.z); glutSolidSphere(0.1, 10, 10); glPopMatrix(); } }