// this is used to construct the convex shape for a certain brush void TSRBSPTree::CreateConvex( vector< TSRVector3 >& verts, int brushIndex ) { tBSPBrush* brush = &Brushes[ brushIndex ]; vector< TSRPlane* > planes; int i, j, k; // Go for every brush side for ( i = 0; i < brush->numOfBrushSides; i++ ) { // take a pointer to the brush side and the plane it represent tBSPBrushSide *brushSide = &BrushSides[ brush->brushSide + i ]; tBSPPlane *plane = &Planes[ brushSide->plane ]; if ( brushSide->m_ID != 2 ) { planes.push_back( plane ); } } int numPlanes=(int)planes.size(); TSRVector3 newVertex; //if(planes.size()>16)return; bool inside=true; for ( i = 0; i < numPlanes; i++ ) { for ( j = i + 1; j < numPlanes; j++ ) { for ( k = j + 1; k < numPlanes; k++ ) { if ( IntersectPlanes( planes[ i ], planes[ j ], planes[ k ], newVertex ) ) { inside = true; // make sure its inside for ( int l = 0; l < numPlanes; l++ ) { TSRPlane* pCurrPlane = planes[ l ]; if ( ( pCurrPlane->n.Dot( newVertex ) ) - pCurrPlane->d > 0.1f ) { l =numPlanes; inside = false; } } if ( inside ) { verts.push_back( newVertex ); } } } } } // discriminants vertices outside the brush // show the vertices //for(i=0;i<verts.size();i++) // { // newVertex=verts[i]; // TSRGlobalConstants.PushMatrix(); // TSRGlobalConstants.Translate(newVertex.x,newVertex.y,newVertex.z); // TSRDebugDraw::RenderSphere(10.0f); // TSRGlobalConstants.PopMatrix(); // } // TSRPrintln("Found %d planes in this brush",planes.size()); // TSRPrintln("Found %d verts in this brush",verts.size()); }
void CEnvironment::DrawFog () { TPlane bottom_plane, top_plane; TVector3 left, right; TVector3 topleft, topright; TVector3 bottomleft = NullVec; TVector3 bottomright = NullVec; float height; if (!fog.is_on) return; // the clipping planes are calculated by view frustum (view.cpp) leftclip = get_left_clip_plane (); rightclip = get_right_clip_plane (); farclip = get_far_clip_plane (); bottomclip = get_bottom_clip_plane (); // --------------- calculate the planes --------------------------- float slope = tan (ANGLES_TO_RADIANS (Course.GetCourseAngle())); // TPlane left_edge_plane = MakePlane (1.0, 0.0, 0.0, 0.0); // TPlane right_edge_plane = MakePlane (-1.0, 0.0, 0.0, Course.width); bottom_plane.nml = MakeVector (0.0, 1, -slope); height = Course.GetBaseHeight (0); bottom_plane.d = -height * bottom_plane.nml.y; top_plane.nml = bottom_plane.nml; height = Course.GetMaxHeight (0) + fog.height; top_plane.d = -height * top_plane.nml.y; if (!IntersectPlanes (bottom_plane, farclip, leftclip, &left)) return; if (!IntersectPlanes (bottom_plane, farclip, rightclip, &right)) return; if (!IntersectPlanes (top_plane, farclip, leftclip, &topleft)) return; if (!IntersectPlanes (top_plane, farclip, rightclip, &topright)) return; if (!IntersectPlanes (bottomclip, farclip, leftclip, &bottomleft)) return; if (!IntersectPlanes (bottomclip, farclip, rightclip, &bottomright)) return; TVector3 leftvec = SubtractVectors (topleft, left); TVector3 rightvec = SubtractVectors (topright, right); TVector3 vpoint1 = AddVectors (topleft, leftvec); TVector3 vpoint2 = AddVectors (topright, rightvec); TVector3 vpoint3 = AddVectors (topleft, ScaleVector (3.0, leftvec)); TVector3 vpoint4 = AddVectors (topright, ScaleVector (3.0, rightvec)); // --------------- draw the fog plane ----------------------------- set_gl_options (FOG_PLANE); glEnable (GL_FOG); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); // only the alpha channel is used const GLfloat col[] = { // bottom density 0, 0, 0, 1.0, 0, 0, 0, 1.0, 0, 0, 0, 1.0, 0, 0, 0, 1.0, // top density 0, 0, 0, 0.9, 0, 0, 0, 0.9, // left/right density 0, 0, 0, 0.3, 0, 0, 0, 0.3, // top/bottom density 0, 0, 0, 0.0, 0, 0, 0, 0.0 }; const GLfloat vtx[] = { bottomleft.x, bottomleft.y, bottomleft.z, bottomright.x, bottomright.y, bottomright.z, left.x, left.y, left.z, right.x, right.y, right.z, topleft.x, topleft.y, topleft.z, topright.x, topright.y, topright.z, vpoint1.x, vpoint1.y, vpoint1.z, vpoint2.x, vpoint2.y, vpoint2.z, vpoint3.x, vpoint3.y, vpoint3.z, vpoint4.x, vpoint4.y, vpoint4.z }; glColorPointer(4, GL_FLOAT, 0, col); glVertexPointer(3, GL_FLOAT, 0, vtx); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); }
void CEnvironment::DrawFog () { if (!fog.is_on) return; TPlane bottom_plane, top_plane; TVector3 left, right, vpoint; TVector3 topleft, topright; TVector3 bottomleft, bottomright; // the clipping planes are calculated by view frustum (view.cpp) const TPlane& leftclip = get_left_clip_plane (); const TPlane& rightclip = get_right_clip_plane (); const TPlane& farclip = get_far_clip_plane (); const TPlane& bottomclip = get_bottom_clip_plane (); // --------------- calculate the planes --------------------------- float slope = tan (ANGLES_TO_RADIANS (Course.GetCourseAngle())); // TPlane left_edge_plane = MakePlane (1.0, 0.0, 0.0, 0.0); // TPlane right_edge_plane = MakePlane (-1.0, 0.0, 0.0, Course.width); bottom_plane.nml = TVector3(0.0, 1, -slope); float height = Course.GetBaseHeight (0); bottom_plane.d = -height * bottom_plane.nml.y; top_plane.nml = bottom_plane.nml; height = Course.GetMaxHeight (0) + fog.height; top_plane.d = -height * top_plane.nml.y; if (!IntersectPlanes (bottom_plane, farclip, leftclip, &left)) return; if (!IntersectPlanes (bottom_plane, farclip, rightclip, &right)) return; if (!IntersectPlanes (top_plane, farclip, leftclip, &topleft)) return; if (!IntersectPlanes (top_plane, farclip, rightclip, &topright)) return; if (!IntersectPlanes (bottomclip, farclip, leftclip, &bottomleft)) return; if (!IntersectPlanes (bottomclip, farclip, rightclip, &bottomright)) return; TVector3 leftvec = SubtractVectors (topleft, left); TVector3 rightvec = SubtractVectors (topright, right); // --------------- draw the fog plane ----------------------------- ScopedRenderMode rm(FOG_PLANE); glEnable (GL_FOG); // only the alpha channel is used float bottom_dens[4] = {0, 0, 0, 1.0}; float top_dens[4] = {0, 0, 0, 0.9}; float leftright_dens[4] = {0, 0, 0, 0.3}; float top_bottom_dens[4] = {0, 0, 0, 0.0}; glBegin (GL_QUAD_STRIP); glColor4fv (bottom_dens); glVertex3f (bottomleft.x, bottomleft.y, bottomleft.z); glVertex3f (bottomright.x, bottomright.y, bottomright.z); glVertex3f (left.x, left.y, left.z); glVertex3f (right.x, right.y, right.z); glColor4fv (top_dens); glVertex3f (topleft.x, topleft.y, topleft.z); glVertex3f (topright.x, topright.y, topright.z); glColor4fv (leftright_dens); vpoint = AddVectors (topleft, leftvec); glVertex3f (vpoint.x, vpoint.y, vpoint.z); vpoint = AddVectors (topright, rightvec); glVertex3f (vpoint.x, vpoint.y, vpoint.z); glColor4fv (top_bottom_dens); vpoint = AddVectors (topleft, ScaleVector (3.0, leftvec)); glVertex3f (vpoint.x, vpoint.y, vpoint.z); vpoint = AddVectors (topright, ScaleVector (3.0, rightvec)); glVertex3f (vpoint.x, vpoint.y, vpoint.z); glEnd(); }
void ScanKeyboard( PRENDERER hDisplay, PVECTOR KeySpeed, PVECTOR KeyRotation ) { PVECTOR v; RCOORD max, step; if( !hDisplay ) return; if( !T ) T = CreateTransform(); // how does this HOOK into the camera update functions?! if( IsKeyDown((hDisplay), KEY_X) || IsKeyDown( (hDisplay), KEY_Q ) ) { extern int gbExitProgram; gbExitProgram = TRUE; } if( pFirstObject ) { if( KeyDown( (hDisplay), KEY_A ) ) { PFACETSET pps; VECTOR v; RotateAbs( T, 0.1f, 0, 0 ); pps = pFirstObject->pPlaneSet; ApplyRotation( T, v, pps->pPlanes->d.n ); SetPoint( pps->pPlanes->d.n, v ); IntersectPlanes( pFirstObject->pLinePool, pps, TRUE ); } if( KeyDown( (hDisplay), KEY_Z ) ) { PFACETSET pps; VECTOR v; RotateAbs( T, -0.1f, 0, 0 ); pps = pFirstObject->pPlaneSet; ApplyRotation( T, v, pps->pPlanes->d.n ); SetPoint( pps->pPlanes->d.n, v ); IntersectPlanes( pFirstObject->pLinePool, pps, TRUE ); } } #define Relax(V, n) if( (V[n]>0.001) || ( V[n]<-0.001) ) \ (V[n] /= 2.0f); else (V[n] = 0); #define Accel(V, n) \ if ( V[n] < max ) \ V[n] += step; \ else V[n] = max; #define Decel(V,n) \ if( V[n] > -max ) \ V[n] -= step; \ else V[n] = -max; #define ROTATION (v=KeyRotation, \ max = ROTATION_DELTA, \ step=ROTATION_ACCEL) #define SPEED (v=KeySpeed, \ max = KEY_VELOCITY, \ step = KEY_ACCEL ) #define Inertia( KEY_LESS, KEY_MORE,KEY_LESS2, KEY_MORE2, va ) \ if( IsKeyDown(hDisplay, KEY_LESS ) || IsKeyDown(hDisplay, KEY_LESS2) ) Decel(v, va) \ else if( IsKeyDown(hDisplay, KEY_MORE ) || IsKeyDown(hDisplay, KEY_MORE2) ) Accel(v, va) \ else Relax( v, va ); (ROTATION); Inertia(KEY_DOWN, KEY_UP, 0, 0, vRight ); Inertia(KEY_RIGHT, KEY_LEFT, 0, 0, vUp ); Inertia(KEY_PGUP, KEY_HOME, 0, 0, vForward ); (SPEED); Inertia( KEY_END, KEY_PGDN, 0, 0, vRight ); Inertia( KEY_ENTER, KEY_GRAY_PLUS, 0, KEY_CENTER, vUp ); Inertia( KEY_DELETE, KEY_INSERT, 0, 0, vForward ); }