int main() { { int unidad = 0,modo; mouse.Inicializar(); initgraph (&unidad,&modo,"c:\\bc\\bgi"); if (graphresult() != 0) { cout << "Error al tratar de pasar al modo grafico\n"; getch(); return 1; } mouse.Mostrar(); setcolor(BLUE); Ventana ObjetoV1 (10,20,250,170,0, 0); ObjetoV1.DibujarVentana(); Ventana *ObjetoV2 = new Ventana(40,50,280,200,1,1); ObjetoV2->DibujarVentana(); mouse.LibBotones(); ObjetoV2->Interactuar(); delete ObjetoV2; mouse.LibBotones(); ObjetoV1.Interactuar(); } closegraph(); return 0; }
Ventana::~Ventana() { if (Copia != NULL) { mouse.Esconder(); putimage (X,Y,Copia,COPY_PUT); delete Copia; mouse.Mostrar(); } }
void EscribirMenu(MOUSE &mouse) { mouse.Esconder(); clearviewport(); mouse.LimVert (100,200); mouse.LimHoriz (50,100); for (int i=0; i < 5; i++) outtextxy (100, i * 10 + 50,Menu[i]); mouse.Mostrar(); }
void Accion (struct TipoMensaje *p) { int Boton,Vert,Horiz,c; p->Boton = mouse.Estado (&p->X, &p->Y); getch1(&p->Llave); while (p->Boton == 0 && p->Llave == 0) { p->Boton = mouse.Estado (&p->X, &p->Y); getch1(&p->Llave); } if (p->Boton != 0) p->Tipo = Boton; else p->Tipo = 4; }
int main() { int unidad = DETECT, modo,i,Vert,Horiz,Boton; MOUSE mouse; void uno(MOUSE &),dos(MOUSE &); void tres(MOUSE &),cuatro(MOUSE &),cinco(MOUSE &); void EscribirMenu(MOUSE &); mouse.Inicializar(); initgraph (&unidad,&modo,"c:\\bc\\bgi"); if (graphresult() != 0) { cout << "Error al tratar de pasar al modo grafico\n"; getch(); return 1; } mouse.Mostrar(); EscribirMenu(mouse); Boton = 0; while (Boton != DERECHO) { Boton = mouse.Estado(&Vert, &Horiz); if (Boton == IZQUIERDO) { if (Horiz >= 50 && Horiz <= 59) { uno(mouse); EscribirMenu(mouse); } else if (Horiz >= 60 && Horiz <= 69) { dos(mouse); EscribirMenu(mouse); } else if (Horiz >= 70 && Horiz <= 79) { tres(mouse); EscribirMenu(mouse); } else if (Horiz >= 80 && Horiz <= 89) { cuatro(mouse); EscribirMenu(mouse); } else if (Horiz >= 90 && Horiz <= 99) { cinco(mouse); EscribirMenu(mouse); } mouse.LibBotones(); } } closegraph(); return 0; }
void main (){ int gdriver=0,gmode,opc,opc1,opc2,opc3,opc4,opc5,opc6,opc7,opc8,opc9; float Periodos,Tasa; initgraph(&gdriver,&gmode," "); mouse.Inicializar(); //Inicializa Mouse boton(90,70,500,300,8,15,7,5); barra_titulo(92,72,499,"Ingreso De Datos - Mac Software"); DibujeIcono(97,73,Network(),16,16); boton(483,75,495,87,8,15,7,1);DibujeIcono(485,77,Cerrar(),9,9); marco_grabado(100,98,490,290); Periodos=CuadroDato(115,"Digite Numero de Periodos",""); Tasa=CuadroDato(185,"Digite Tasa de Interes",""); conv_text(125,253,"NOTA: "); conv_text(125,268,"EL PERIODO CERO (0) ES EL MOMENTO INICIAL"); getch(); cleardevice(); printf("Periodo= %f Tasa=%f",Periodos,Tasa); getch(); closegraph();exit(0);restorecrtmode();system("cls"); } //FIN
HRESULT APPLICATION::Update(float deltaTime) { //Set World matrix D3DXMATRIX matWorld; D3DXMatrixIdentity(&matWorld); m_pDevice->SetTransform(D3DTS_WORLD, &matWorld); //Update m_mouse m_mouse.Update(); //Update m_camera m_camera.Update(m_mouse, deltaTime); //Change intersection test type if(KEYDOWN(VK_SPACE)) { Sleep(300); m_intersectType++; if(m_intersectType > 2)m_intersectType = 0; } if(KEYDOWN(VK_ESCAPE)) Quit(); return S_OK; }
void CAMERA::Update(MOUSE &mouse, float timeDelta) { //Restrict focus movment to the xz-plane m_right.y = m_look.y = 0.0f; D3DXVec3Normalize(&m_look, &m_look); D3DXVec3Normalize(&m_right, &m_right); //Move Focus (i.e. Scroll) if(mouse.x < mouse.m_viewport.left + 10) Scroll(-m_right * timeDelta * 30.0f); if(mouse.x > mouse.m_viewport.right - 10) Scroll(m_right * timeDelta * 30.0f); if(mouse.y < mouse.m_viewport.top + 10) Scroll(m_look * timeDelta * 30.0f); if(mouse.y > mouse.m_viewport.bottom - 10) Scroll(-m_look * timeDelta * 30.0f); //Move Camera (i.e. Change Angle) if(KEYDOWN(VK_LEFT))Yaw(-timeDelta); if(KEYDOWN(VK_RIGHT))Yaw(timeDelta); if(KEYDOWN(VK_UP))Pitch(timeDelta); if(KEYDOWN(VK_DOWN))Pitch(-timeDelta); //Zoom (i.e. change fov) if(KEYDOWN(VK_ADD))Zoom(-timeDelta); if(KEYDOWN(VK_SUBTRACT))Zoom(timeDelta); //Change m_radius if(mouse.WheelUp()) ChangeRadius(-1.0f); if(mouse.WheelDown())ChangeRadius(1.0f); //Calculate Eye Position float sideRadius = m_radius * cos(m_beta); float height = m_radius * sin(m_beta); m_eye = D3DXVECTOR3(m_focus.x + sideRadius * cos(m_alpha), m_focus.y + height, m_focus.z + sideRadius * sin(m_alpha)); if(m_pDevice != NULL) { D3DXMATRIX view = GetViewMatrix(); D3DXMATRIX projection = GetProjectionMatrix(); m_pDevice->SetTransform(D3DTS_VIEW, &view); m_pDevice->SetTransform(D3DTS_PROJECTION, &projection); CalculateFrustum(view, projection); } }
void Ventana::DibujarVentana() { int i; mouse.Esconder(); if (Buffer != 0) { i = imagesize (X, Y, X1, Y1); if (i == -1) // Asi debe ser y no como en el programa de la // pagina 565. Favor corregir sobre el texto. Error("Imagen muy grande para almacenar"); Copia = new int [i]; if (Copia == NULL) Error("Memoria Insuficiente"); getimage (X, Y, X1, Y1, Copia); } setcolor (WHITE); rectangle (X, Y, X1, Y1); setfillstyle (SOLID_FILL, LIGHTGRAY); bar (X+1, Y+1, X1-1, Y1-1); if (TieneBorde != 0) { // Implemente aqui el Tipo de Borde deseado } mouse.Mostrar(); }
void cinco(MOUSE &mouse) { int Boton,Vert,Horiz; mouse.LimVert (0,getmaxx() ); mouse.LimHoriz (0,getmaxy() ); mouse.Esconder(); clearviewport(); outtext("cinco"); mouse.Mostrar(); mouse.LibBotones(); while ( (Boton = mouse.Estado (&Vert, &Horiz) ) == 0 ) ; mouse.LibBotones(); }
HRESULT APPLICATION::Update(float deltaTime) { //Control camera D3DXMATRIX matWorld; D3DXMatrixIdentity(&matWorld); m_pDevice->SetTransform(D3DTS_WORLD, &matWorld); //Update mouse m_mouse.Update(); //Update camera m_camera.Update(m_mouse, deltaTime); if(KEYDOWN(VK_ESCAPE)) Quit(); return S_OK; }
int main() { int unidad = DETECT, modo,boton,Horiz,Vert; char a[10],todo[30]; MOUSE mouse; mouse.Inicializar(); initgraph (&unidad,&modo,"c:\\bc\\bgi"); if (graphresult() != 0) { cout << "Error al tratar de pasar al modo grafico\n"; getch(); return 1; } mouse.Mostrar(); getch(); boton = mouse.Estado (&Vert,&Horiz); itoa (Horiz,a,10); strcpy (todo,a); itoa (Vert,a,10); strcat (todo," "); strcat (todo,a); itoa (boton,a,10); strcat (todo," "); strcat (todo,a); mouse.Esconder(); outtextxy (0,0,todo); mouse.Mostrar(); getch(); boton = mouse.Estado (&Vert,&Horiz); itoa (Horiz,a,10); strcpy (todo,a); itoa (Vert,a,10); strcat (todo," "); strcat (todo,a); itoa (boton,a,10); strcat (todo," "); strcat (todo,a); mouse.Esconder(); outtextxy (0,10,todo); mouse.Mostrar(); getch(); boton = mouse.Estado (&Vert,&Horiz); itoa (Horiz,a,10); strcpy (todo,a); itoa (Vert,a,10); strcat (todo," "); strcat (todo,a); itoa (boton,a,10); strcat (todo," "); strcat (todo,a); mouse.Esconder(); outtextxy (0,20,todo); mouse.Mostrar(); getch(); closegraph(); return 0; }
void Update() { //cam.position.DebugPrint(); bool mainloop = false; //std::cout << "Mainloop" << std::endl; //if unpaused and getting a reasonable framerate //if (fps > MIN_FPS && timefactor != 0.0f) if (fps > 0.0f && timefactor != 0.0f) { double time_increment = timefactor / fps; //std::cout << "Time elapsed: " << execution_time << " + " << time_increment << std::endl; execution_time += time_increment; //int num_updates = (int) (execution_time / FRAME_TIME); // double this_frame = (double) num_updates * FRAME_TIME; mouse.Update(cam, SCREEN_WIDTH, SCREEN_HEIGHT, timefactor, fps); cam.dir = mouse.GetDir(); while (execution_time > FRAME_TIME) { //std::cout << "Frame start: " << execution_time << std::endl; #ifdef PERFORMANCE_PROFILE suseconds_t t1, t2; t1 = GetMicroSeconds(); t1 = GetMicroSeconds(); #endif //multiplay.Update(FRAME_TIME); //weather tick #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "multiplay.Update() ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif cam.Update(); //handle input //keyman.DoHeldKeys(timefactor, fps, cam); keyman.DoHeldKeys(1.0, 1.0/FRAME_TIME, cam); #ifdef PERFORMANCE_PROFILE t1 = GetMicroSeconds(); t1 = GetMicroSeconds(); #endif #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "world update ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif keyman.DoOneTimeKeys(cam); //particle.Update(timefactor, fps); //particle.Update(1.0, 1.0/FRAME_TIME); cam.ExtractFrustum(); //float timepassed = (timefactor/fps)/86400.0; float timepassed = (FRAME_TIME)/86400.0; /*if (keyman.keys[keyman.GetKey("AccelTimeVFast")]) timefactor = 10000.0; else if (keyman.keys[keyman.GetKey("AccelTimeFast")]) timefactor = 1000.0; else timefactor = 1.0;*/ //float timepassed = (timefactor/fps)/60.0; //float timepassed = (timefactor/fps)/10.0; abs_time += timepassed; day_time += timepassed; if (day_time > 1.0f) day_time -= 1.0f; #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "Time increment ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif mainloop = true; //terrain.Update(cam, timefactor, fps, day_time); //terrain.Update(cam, 1.0, 1.0/FRAME_TIME, day_time); execution_time -= FRAME_TIME; //num_updates++; //replay.IncrementFrame(); } } else { //print "paused" } if (pauserequest) { if (timefactor != 0.0f) timefactor = 0.0f; pauserequest = false; } if (unpauserequest) { if (timefactor == 0.0f) timefactor = 1.0f; unpauserequest = false; } /*if (!mainloop) multiplay.Update(0);*/ //don't need this anymore because we're stopping things from being paused in multiplayer mode }
/* Here goes our drawing code */ int drawGLScene() { #ifdef PERFORMANCE_PROFILE suseconds_t t1, t2; t1 = GetMicroSeconds(); t1 = GetMicroSeconds(); #endif //glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "RenderReflectedScene() ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif glMatrixMode( GL_PROJECTION ); glLoadIdentity( ); gluPerspective( 45.0f, (float)SCREEN_WIDTH/SCREEN_HEIGHT, 0.1f, settings.GetViewDistance() ); glMatrixMode( GL_MODELVIEW ); glSetup(); glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); //glClearColor( 255.0f, 0.0f, 0.0f, 0.0f ); #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "glSetup() ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif utility.Tex2D(3, false); utility.Tex2D(2, false); utility.Tex2D(1, false); utility.Tex2D(0, true); glStencilMask(~0); glClearStencil(0); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Clear Screen And Depth Buffer glDisable(GL_STENCIL_TEST); GLdouble temp_matrix[16]; int i; cam.PutTransformInto(temp_matrix); glLoadMatrixd(temp_matrix); //reset sun position so it's in the correct frame float lp[4]; lp[0] = LightPosition[0]; lp[1] = LightPosition[1]; lp[2] = LightPosition[2]; lp[3] = 0; //lighting hardcoded to reasonable position lp[0] = 3; lp[1] = 3; lp[2] = 3; lp[3] = 0; glLightfv( GL_LIGHT1, GL_POSITION, lp ); #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "Matrix setup and light setup ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif // model the highlighted vertex belongs to OBJECTMODEL * highlighted_model = NULL; //if (state.GetGameState() != STATE_INITIALMENU) { // bool normal = true; glClear (GL_DEPTH_BUFFER_BIT); #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "DrawSky() ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif glTranslatef(cam.GetPosition().x,cam.GetPosition().y,cam.GetPosition().z); /*GLdouble equation[4]; VERTEX earthnormal = temp - cam.position; earthnormal.y += EARTH_RADIUS; earthnormal = earthnormal.normalize(); equation[0] = earthnormal.x; equation[1] = -earthnormal.y; equation[2] = earthnormal.z; equation[3] = (waterheight); glClipPlane(GL_CLIP_PLANE1, equation); if (underwater) glEnable(GL_CLIP_PLANE1); else glDisable(GL_CLIP_PLANE1); */ #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "terrain.SetFrustum() ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif //glPolygonOffset(1.0,1.0); //glPolygonOffset(0.0,10.0); //glEnable(GL_POLYGON_OFFSET_FILL); /*if (normal) { //GLfloat LightAmbient2[] = { 0.3f, 0.3f, 0.3f, 1.0f }; //glLightfv( GL_LIGHT1, GL_AMBIENT, LightAmbient2 ); glDisable(GL_STENCIL_TEST); #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "terrain.Draw() ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif utility.SelectTU(3); glDisable(GL_TEXTURE_2D); utility.SelectTU(0); glEnable(GL_TEXTURE_2D); #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "trees.Draw() ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif objects.Draw(); #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "objects.Draw() ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif //glLightfv( GL_LIGHT1, GL_AMBIENT, LightAmbient ); } glDisable(GL_POLYGON_OFFSET_FILL);*/ //glClear (GL_DEPTH_BUFFER_BIT); //glDisable(GL_LIGHTING); objects.Draw(); #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "normal draw done" << t2-t1 << endl; t1 = GetMicroSeconds(); #endif /* //draw trees foliage.Draw(terrain, cam); #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "foliage.Draw() ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif //glDisable(GL_CLIP_PLANE1); ships.Draw(false); terrain.Draw(cam, 1.0f, false, false, true, false, timefactor, fps, day_time); //terrain.Draw(cam, 1.0f, false, false, true, false, timefactor, fps, day_time); //rain is drawn over everything else if (!underwater) backdrop.DrawRain(day_time); #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "DrawRain() ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif glDisable(GL_CLIP_PLANE1); */ //glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /*if (0) { //experimental bezier stuff BEZIER patch; VERTEX fl, fr, bl, br; //fl.Set(20,40,0); fl.Set(5,10,0); fr = fl; bl = fl; br = fl; fr.x += 15; fr.y += 3; br.x += 12; br.z += 8; bl.z += 10; bl.y -= 2; patch.SetFromCorners(fl, fr, bl, br); BEZIER nextpatch; VERTEX offset; offset.x += -7; offset.z += -10; fl = fl + offset; fr = fr + offset; bl = bl + offset; br = br + offset; nextpatch.SetFromCorners(fl, fr, bl, br); //patch.Attach(nextpatch); BEZIER thirdpatch; offset.zero(); offset.y += -3; offset.z += -10; fl = fl + offset; fr = fr + offset; bl = bl + offset; br = br + offset; thirdpatch.SetFromCorners(fl, fr, bl, br); //nextpatch.Attach(thirdpatch); TRACK track; ROADSTRIP * teststrip = track.AddNewRoad(); teststrip->Add(patch); teststrip->Add(nextpatch); teststrip->Add(thirdpatch); //teststrip.DeleteLastPatch(); track.VisualizeRoads(true, true); VERTEX down; down.y = -1; VERTEX colpoint; if (patch.Collide(cam.position.ScaleR(-1.0), down, colpoint)) { //colpoint.DebugPrint(); } }*/ VERTEX camray; camray.z = -1; camray = cam.dir.ReturnConjugate().RotateVec(camray); /*camray.z = 1; camray = cam.dir.RotateVec(camray);*/ VERTEX selvert; bool highlightedvert = false; if (objects.FindClosestVert(cam.position.ScaleR(-1.0), camray, selvert, highlighted_model)) { /*cam.position.ScaleR(-1.0).DebugPrint(); selvert.DebugPrint(); cout << endl;*/ //draw a highlighted vert highlightedvert = true; glPushAttrib(GL_ALL_ATTRIB_BITS); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); //glEnable(GL_BLEND); //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glPointSize(4.0); //glColor4f(1,1,0,0.75); glColor4f(1,1,0,1); glBegin(GL_POINTS); glVertex3fv(selvert.v3()); glEnd(); glDisable(GL_BLEND); glColor4f(1,1,1,1); glPopAttrib(); } //left click if (highlightedvert && mouse.ButtonDown(1) && !editordata.mousebounce[1]) { int oldnumbezinput = editordata.numbezinput; //left click on a highlighted vert if (vertmode == TWOVERTS) { if (editordata.numbezinput == 0) editordata.numbezinput = 3; else if (editordata.numbezinput <= 3) editordata.numbezinput = 4; else if (editordata.numbezinput <= 4) editordata.numbezinput = 7; else if (editordata.numbezinput <= 7) editordata.numbezinput = 8; } else { editordata.numbezinput++; if (vertmode == THREEVERTS && (editordata.numbezinput == 2 || editordata.numbezinput == 6)) editordata.numbezinput++; } if (editordata.numbezinput >= 8) { //create bezier patch BEZIER patch; if (vertmode == TWOVERTS) patch.SetFromCorners(editordata.bezinput[4], selvert, editordata.bezinput[0], editordata.bezinput[3]); else { //copy the front and back selected rows to the patch, then tell it to do the math to find the other points // plus center and radius calculations editordata.bezinput[7] = selvert; for (int i = 0; i < 4; i++) patch.points[3][i] = editordata.bezinput[i]; for (int i = 0; i < 4; i++) patch.points[0][i] = editordata.bezinput[i+4]; /*if (vertmode == THREEVERTS) { //recalculate the middle two verts for (int i = 0; i < 4; i += 3) { if ((patch.points[i][1] - patch.points[i][2]).len() < 0.0001) { VERTEX leftslope = patch.points[i][1] - patch.points[i][0]; VERTEX rightslope = patch.points[i][2] - patch.points[i][3]; patch.points[i][1] = patch.points[i][0] + leftslope.ScaleR(0.5); patch.points[i][2] = patch.points[i][3] + rightslope.ScaleR(0.5); } } }*/ patch.CalculateMiddleRows(); } if (activestrip == NULL) { activestrip = track.AddNewRoad(); mq1.AddMessage("New road created to hold new patch."); } activestrip->Add(patch); //editordata.numbezinput = 0; editordata.numbezinput = 4; editordata.bezinput[0] = patch.points[0][0]; editordata.bezinput[1] = patch.points[0][1]; editordata.bezinput[2] = patch.points[0][2]; editordata.bezinput[3] = patch.points[0][3]; } else { editordata.bezinput[oldnumbezinput] = selvert; if (vertmode == THREEVERTS && (oldnumbezinput == 1 || oldnumbezinput == 5)) editordata.bezinput[oldnumbezinput+1] = selvert; } } editordata.mousebounce[1] = mouse.ButtonDown(1); glPushAttrib(GL_ALL_ATTRIB_BITS); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glPointSize(4.0); glColor4f(1,0,0,1); glBegin(GL_POINTS); for (i = 0; i < editordata.numbezinput; i++) { if (vertmode != TWOVERTS || i == 0 || i == 3 || i == 4 || i == 7) { glVertex3fv(editordata.bezinput[i].v3()); } } glEnd(); glColor4f(1,1,1,1); glPopAttrib(); track.VisualizeRoads(true, false, activestrip); for (int l = 0; l < track.NumLapSeqs(); l++) { BEZIER * lapbez = track.GetLapSeq(l); if (lapbez != NULL) { VERTEX reddish; reddish.x = 0.5; reddish.y = 0.2; reddish.z = 0.2; lapbez->Visualize(true, false, reddish); } } //image in the framebuffer is now complete. /*//add a brightness/contrast adjustment glClear (GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glPushAttrib(GL_ALL_ATTRIB_BITS); glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); glDisable(GL_FOG); glDisable(GL_LIGHTING); glTranslatef(0,0,-40.0f); glBlendFunc(GL_ONE, GL_SRC_ALPHA); float rd = (float) weathersystem.GetRainDrops(); float rainscale = 0.7f; float clearscale = 1.1f; float rainbias = 0.035f; float clearbias = 0.0f; float rainmax = 50.0f; float rainfactor = (rd/rainmax); if (rainfactor > 1.0f) rainfactor = 1.0f; float scale = rainfactor*rainscale+(1.0f-rainfactor)*clearscale; float bias = rainfactor*rainbias+(1.0f-rainfactor)*clearbias; glColor4f(bias, bias, bias, scale); float x1, y1, x2, y2; x1 = -30; y1 = -30; x2 = 30; y2 = 30; if (scale > 1.0) { float remainingScale; remainingScale = scale; glBlendFunc(GL_DST_COLOR, GL_ONE); if (remainingScale > 2.0) { glColor4f(1, 1, 1, 1); while (remainingScale > 2.0) { glRectf(x1,y1,x2,y2); remainingScale /= 2.0; } } glColor4f(remainingScale - 1, remainingScale - 1, remainingScale - 1, 1); glRectf(x1,y1,x2,y2); glBlendFunc(GL_ONE, GL_ONE); if (bias != 0) { if (bias > 0) { glColor4f(bias, bias, bias, 0.0); } else { glColor4f(-bias, -bias, -bias, 0.0); //can't do bias < 0 } glRectf(x1,y1,x2,y2); } } else { if (bias > 0) { glColor4f(bias, bias, bias, scale); } else { glColor4f(-bias, -bias, -bias, scale); //can't do bias < 0 } glBlendFunc(GL_ONE, GL_SRC_ALPHA); glRectf(x1,y1,x2,y2); } glPopAttrib();*/ //timer.Draw(); } float w, h; w = 0.02; h = w*(4/3.0); utility.Tex2D(0,true); utility.Draw2D(0.5-w, 0.5-h, 0.5+w, 0.5+h, editordata.cursortex); if (fps > 0.0f) mq1.Draw(timefactor, fps, font); #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "Brightness/contrast adjustment ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif Frames++; frameno++; if (frameno >= 30011) frameno -= 30011; lfps[lfpspos] = pfps; lfpspos++; if (lfpspos >= AVERAGEFRAMES) { lfpspos = lfpspos % AVERAGEFRAMES; lfpsfull = true; } float tfps = 0.0f; int tnum = 0; for (i = 0; i < AVERAGEFRAMES; i++) { if (!(!lfpsfull && i >= lfpspos)) { tfps += lfps[i]; tnum++; } } fps = std::min(1000.0f,tfps / (float) tnum); /*lfps += pfps; { //const int freq = (int) MIN_FPS; const int freq = 60; if (Frames >= freq) { fps = lfps / freq; Frames = 0; lfps = 0; } }*/ char tempchar[1024]; sprintf(tempchar, "Frames per second: %f\n", fps); //font.Print(0.5,0,tempchar,0,0,1,1,0); if (showfps) font.Print( 0.75, 0.0, tempchar, 1, 5, 1.0 ); // print camera position VERTEX pos = cam.GetPosition(); sprintf(tempchar, "Position: %0.2f, %0.2f, %0.2f\n", -pos.x, -pos.y, -pos.z); font.Print( 0.75, 0.025, tempchar, 1, 5, 1.0 ); //VERTEX ang = cam.dir.GetEulerZYX(); //sprintf(tempchar, "Angle: %0.2f, %0.2f, %0.2f\n", 180/M_PI*ang.x, -180/M_PI*ang.y, 180/M_PI*ang.z); //font.Print( 0.75, 0.05, tempchar, 1, 5, 1.0 ); // print object name the highlighted vertex belongs to if (highlighted_model) { string modelname = highlighted_model->name; sprintf(tempchar, "Model: %s\n", modelname.c_str()); font.Print( 0.75, 0.05, tempchar, 1, 5, 1.0 ); } #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "font.Print() ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif //draw help screen(s) if (editordata.helppage > 2) editordata.helppage = 0; if (editordata.helppage == 1) { font.Print(0.1, 0.1, "VDrift Track Editor Keys (press H again for more help)\n" "Mouse left click\n" "Arrow keys\n" "Page Up\n" "A, F\n" "L\n" "K\n" "N\n" "R\n" "S\n" "I\n" "E\n" "- (minus)\n" "2, 3, 4\n" "BACKSPACE\n" "ESCAPE\n" , 1, 5, 1.0); font.Print(0.3, 0.1, "\n" "Select highligted vertex\n" "Move around\n" "Move forward very fast\n" "Automatically try to create the next bezier patch on this road (F: 25 at a time)\n" "Add the current camera position to the list of car start locations\n" "Remove the last start location from the list\n" "Create a new road (the new road is created once you add patches to it)\n" "Select the road under the cursor\n" "Save the track\n" "Print the object that owns the selected vertex to the console\n" "Mark a road segment as part of a lap sequence\n" "Clear all lap sequences\n" "Select vertices 2 at a time, 3 at a time, 4 at a time\n" "Delete the last bezier patch on this road\n" "Quit the editor\n" , 1, 5, 1.0); } if (editordata.helppage == 2) font.Print(0.1, 0.1, "VDrift Track Editor Textual Help\n" "The editor starts in vertex selection mode. Vertices are highlighted yellow as the mouse pointer\n" "gets close to them. Press the left mouse button to select the highlighted vertex. It will turn\n" "red. Select a vertex on the left side of the road, then a vertex on the right side of the road,\n" "with left and right determined by the direction you'd like to create the road in. You can now select\n" "the next two vertices (left and then right), and a green box will be created to indicate a bezier\n" "patch has been created there. Notice that the last two vertices you select are still colored red\n" "(selected). You can now select the next two vertices (left and right), and continue to create bezier\n" "patches around the track. Once you have created a bezier patch, you can alternatively press A to\n" "have the editor try to automatically select the next two vertices and auto-create the next patch.\n" "This works well in straight areas, not so well in curvy areas. Press BACKSPACE at any time to delete\n" "the last patch that was created." , 1, 5, 1.0); /* Draw it to the screen */ SDL_GL_SwapBuffers( ); GLint t = SDL_GetTicks(); //if (t - T0 >= 50) { GLfloat seconds = (t - T0) / 1000.0; pfps = 1 / seconds; //printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps); T0 = t; //Frames = 0; } #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "SwapBuffers() ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); cout << endl; #endif return( TRUE ); }
HRESULT APPLICATION::Render() { //Setup the viewport D3DVIEWPORT9 v, v2; v.Width = 800; v.Height = 600; v.X = 0; v.Y = 0; v.MaxZ = 1.0f; v.MinZ = 0.0f; m_pDevice->SetViewport(&v); v2 = v; // Clear the viewport m_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff4444ff, 1.0f, 0L ); // Begin the scene if(SUCCEEDED(m_pDevice->BeginScene())) { //Render big city m_city.Render(&m_camera); RECT r[] = {{10, 10, 0, 0}, {10, 30, 0, 0}, {10, 50, 0, 0}}; m_pFont->DrawText(NULL, "Mouse Wheel: Change Camera Radius", -1, &r[0], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); m_pFont->DrawText(NULL, "Arrows: Change Camera Angle", -1, &r[1], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); //Render city overview, set viewport v.X = 550; v.Y = 20; v.Width = 230; v.Height = 230; m_pDevice->SetViewport(&v); m_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0L ); //Setup camera view to orthogonal view looking down on city D3DXMATRIX viewTop, projectionTop; D3DXMatrixLookAtLH(&viewTop, &(m_city.GetCenter() + D3DXVECTOR3(0.0f, 100.0f, 0.0f)), &m_city.GetCenter(), &D3DXVECTOR3(0,0,1)); D3DXMatrixOrthoLH(&projectionTop, m_city.m_size.x * TILE_SIZE, m_city.m_size.y * TILE_SIZE, 0.1f, 1000.0f); m_pDevice->SetTransform(D3DTS_VIEW, &viewTop); m_pDevice->SetTransform(D3DTS_PROJECTION, &projectionTop); //Draw city blocks that are in view m_city.Render(NULL); //Restore viewport m_pDevice->SetViewport(&v2); //Draw line around smaller window D3DXVECTOR2 outline[] = {D3DXVECTOR2(550, 20), D3DXVECTOR2(779, 20), D3DXVECTOR2(779, 249), D3DXVECTOR2(550, 249), D3DXVECTOR2(550, 20)}; m_pLine->SetWidth(3.0f); m_pLine->Begin(); m_pLine->Draw(outline, 5, 0xff000000); m_pLine->End(); //Draw mouse m_mouse.Paint(); // End the scene. m_pDevice->EndScene(); m_pDevice->Present(0, 0, 0, 0); } return S_OK; }
HRESULT APPLICATION::Init(HINSTANCE hInstance, int width, int height, bool windowed) { debug.Print("Application initiated"); //Create Window Class WNDCLASS wc; memset(&wc, 0, sizeof(WNDCLASS)); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)::DefWindowProc; wc.hInstance = hInstance; wc.lpszClassName = "D3DWND"; //Register Class and Create new Window RegisterClass(&wc); m_mainWindow = CreateWindow("D3DWND", "Example 5.6: Frustum Culling", WS_EX_TOPMOST, 0, 0, width, height, 0, 0, hInstance, 0); SetCursor(NULL); ShowWindow(m_mainWindow, SW_SHOW); UpdateWindow(m_mainWindow); //Create IDirect3D9 Interface IDirect3D9* d3d9 = Direct3DCreate9(D3D_SDK_VERSION); if(d3d9 == NULL) { debug.Print("Direct3DCreate9() - FAILED"); return E_FAIL; } //Check that the Device supports what we need from it D3DCAPS9 caps; d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps); //Hardware Vertex Processing or not? int vp = 0; if(caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) vp = D3DCREATE_HARDWARE_VERTEXPROCESSING; else vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; //Check vertex & pixelshader versions if(caps.VertexShaderVersion < D3DVS_VERSION(2, 0) || caps.PixelShaderVersion < D3DPS_VERSION(2, 0)) { debug.Print("Warning - Your graphic card does not support vertex and pixelshaders version 2.0"); } //Set D3DPRESENT_PARAMETERS D3DPRESENT_PARAMETERS d3dpp; d3dpp.BackBufferWidth = width; d3dpp.BackBufferHeight = height; d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; d3dpp.BackBufferCount = 1; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3dpp.MultiSampleQuality = 0; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = m_mainWindow; d3dpp.Windowed = windowed; d3dpp.EnableAutoDepthStencil = true; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; d3dpp.Flags = 0; d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; //Create the IDirect3DDevice9 if(FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_mainWindow, vp, &d3dpp, &m_pDevice))) { debug.Print("Failed to create IDirect3DDevice9"); return E_FAIL; } //Release IDirect3D9 interface d3d9->Release(); D3DXCreateFont(m_pDevice, 18, 0, 0, 1, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &m_pFont); //Create m_light ::ZeroMemory(&m_light, sizeof(m_light)); m_light.Type = D3DLIGHT_DIRECTIONAL; m_light.Ambient = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); m_light.Diffuse = D3DXCOLOR(0.9f, 0.9f, 0.9f, 1.0f); m_light.Specular = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); m_light.Direction = D3DXVECTOR3(0.0f, -1.0f, 0.0f); m_pDevice->SetLight(0, &m_light); m_pDevice->LightEnable(0, true); //Set sampler state for(int i=0;i<4;i++) { m_pDevice->SetSamplerState(i, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); m_pDevice->SetSamplerState(i, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); m_pDevice->SetSamplerState(i, D3DSAMP_MIPFILTER, D3DTEXF_POINT); } //Init camera m_camera.Init(m_pDevice); //Load objects LoadObjectResources(m_pDevice); //Create 2D Line D3DXCreateLine(m_pDevice, &m_pLine); //Create city m_city.Init(INTPOINT(25, 25)); m_camera.m_focus = m_city.GetCenter(); //Init mouse m_mouse.InitMouse(m_pDevice, m_mainWindow); return S_OK; }
HRESULT APPLICATION::Render() { // Clear the viewport m_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0L ); // Begin the scene if(SUCCEEDED(m_pDevice->BeginScene())) { for(int i=0;i<(int)m_objects.size();i++) m_objects[i].Render(); //Find intersecting object closest to the camera D3DXMATRIX identity; D3DXMatrixIdentity(&identity); int object = -1; float bestDist = 100000.0f; for(int i=0;i<(int)m_objects.size() - 1;i++) { float dist = -1.0f; //Do intersection tests if(m_intersectType == 0) { m_pDevice->SetTransform(D3DTS_WORLD, &m_objects[i].m_meshInstance.GetWorldMatrix()); RAY ray = m_mouse.GetRay(); dist = ray.Intersect(m_objects[i].m_meshInstance); } else if(m_intersectType == 1) { m_pDevice->SetTransform(D3DTS_WORLD, &identity); RAY ray = m_mouse.GetRay(); dist = ray.Intersect(m_objects[i].m_BBox); } else if(m_intersectType == 2) { m_pDevice->SetTransform(D3DTS_WORLD, &identity); RAY ray = m_mouse.GetRay(); dist = ray.Intersect(m_objects[i].m_BSphere); } m_objects[i].RenderBoundingVolume(m_intersectType); if(dist >= 0.0f && dist < bestDist) { object = i; bestDist = dist; } } //Write m_mouse text if(object != -1) { RECT mr[] = {{m_mouse.x + 2, m_mouse.y + 24, 0, 0}, {m_mouse.x, m_mouse.y + 22, 0, 0}}; m_pFontMouse->DrawText(NULL, m_objects[object].m_name.c_str(), -1, &mr[0], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); m_pFontMouse->DrawText(NULL, m_objects[object].m_name.c_str(), -1, &mr[1], DT_LEFT| DT_TOP | DT_NOCLIP, 0xffff0000); } RECT r[] = {{10, 10, 0, 0}, {10, 30, 0, 0}, {10, 50, 0, 0}}; m_pFont->DrawText(NULL, "Mouse Wheel: Change Camera Radius", -1, &r[0], DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff); m_pFont->DrawText(NULL, "Arrows: Change Camera Angle", -1, &r[1], DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff); m_pFont->DrawText(NULL, "Space: Change Bounding Volume", -1, &r[2], DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff); RECT rc = {500, 10, 0, 0}; if(m_intersectType == 0) m_pFont->DrawText(NULL, "Mesh Intersection Test", -1, &rc, DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff); else if(m_intersectType == 1) m_pFont->DrawText(NULL, "Box Intersection Test", -1, &rc, DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff); else if(m_intersectType == 2) m_pFont->DrawText(NULL, "Sphere Intersection Test", -1, &rc, DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff); //Draw m_mouse m_mouse.Paint(); // End the scene. m_pDevice->EndScene(); m_pDevice->Present(0, 0, 0, 0); } return S_OK; }