int SetupMonitorFace (short nSegment, short nSide, short nCamera, CSegFace *faceP) { CCamera *cameraP = cameraManager.Camera (nCamera); int bHaveMonitorBg, bIsTeleCam = cameraP->GetTeleport (); #if !DBG int i; #endif #if RENDER2TEXTURE int bCamBufAvail = cameraP->HaveBuffer (1) == 1; #else int bCamBufAvail = 0; #endif if (!gameStates.render.bDoCameras) return 0; bHaveMonitorBg = cameraP->Valid () && /*!cameraP->bShadowMap &&*/ (cameraP->Texture ().Texture () || bCamBufAvail) && (!bIsTeleCam || EGI_FLAG (bTeleporterCams, 0, 1, 0)); if (bHaveMonitorBg) { cameraP->GetUVL (faceP, NULL, FACES.texCoord + faceP->nIndex, FACES.vertices + faceP->nIndex); if (bIsTeleCam) { #if DBG faceP->bmBot = &cameraP->Texture (); gameStates.render.grAlpha = 1.0f; #else faceP->bmTop = &cameraP->Texture (); for (i = 0; i < 4; i++) gameData.render.color.vertices [faceP->index [i]].color.alpha = 0.7f; #endif } else if (/*gameOpts->render.cameras.bFitToWall ||*/ (faceP->nOvlTex == 0) || !faceP->bmBot) faceP->bmBot = &cameraP->Texture (); else faceP->bmTop = &cameraP->Texture (); faceP->pTexCoord = cameraP->TexCoord (); } faceP->bTeleport = bIsTeleCam; cameraP->SetVisible (1); return bHaveMonitorBg || gameOpts->render.cameras.bFitToWall; }
void CResourceScene10yCubeNest::play(float _time) { //glEnable(GL_DEPTH_TEST); //glClear(GL_DEPTH_BUFFER_BIT); //m_Render->enableDepthMask(); // set transparency m_Render->enableBlend(); // Apply the blending (if appropiate) if(m_hasCustomBlending) { m_Render->blendFunc(this->m_renderBlendingPos); } // temp set view CCamera myCam; m_Render->setLineWidth(0.8); m_Render->setProjectionMatrix(); m_Render->pushMatrix(); m_Render->loadIdentity(); //myCam.SetLook(120,1,0); myCam.SetFar(1,10000); //myCam.SetFov(30); //myCam.Place(CPoint(100*sin(_time),0,100*cos(_time)), CPoint(0,0,0), CPoint(0,1,0)); float dist = 50 + 20*sin(_time); float height = dist*cos(_time); float period = _time * 4; myCam.Place(CPoint(dist*sin(period),height,dist*cos(period)), CPoint(0,0,0), CPoint(0,1,0)); //myCam.Place(CPoint(30,10,30), CPoint(0,0,0), CPoint(0,1,0)); myCam.toOGL(); //m_Render->setActiveCamera(&myCam); //m_Render->auxAxis(); // Apply the calculated alpha to our plane color (this alpha is set outside by an "Effect") CPoint currColor = this->m_Color; currColor.w*=this->m_alpha; //cout << currColor.w << endl; // set the current vertex color m_Render->setColor(currColor); // draw & update unsigned int i; CPoint vup, vright; //m_Render->setColor(0.6,0.6,1,0.035); float decay, s=0.1; for(i=0; i<m_numCubes; i++) { m_Render->setModelMatrix(); m_Render->pushMatrix(); s+=0.25; //m_Render->translate(20+10*sin(_time+i*5),0,20+10*cos(_time+i*5)); m_Render->scale(s,s,s); m_Render->rotate(i*(20+10*sin(_time)) + (_time-m_startTime)*80, i*i,i,-i); m_Render->drawCube(true); m_Render->setModelMatrix(); m_Render->popMatrix(); } //m_Render->popMatrix(); // temp set view m_Render->setProjectionMatrix(); m_Render->popMatrix(); m_Render->disableBlend(); glDisable(GL_DEPTH_TEST); }
void KeyBoard(unsigned char key, int x, int y) { switch (key) { case '1': //menentukan koordinat camera printf("%f %f %f \n\tat %f %f %f \n\tup %f %f %f", myView.position().x,myView.position().y,myView.position().z, myView.view().x,myView.view().y,myView.view().z, myView.upVector().x,myView.upVector().y,myView.upVector().z); break; case '2': bbolalampu += 0.4; glEnable(GL_LIGHT2); break; case '3': bbolalampu -= 0.4; glDisable(GL_LIGHT2); break; case 'w': //move forward myView.move(speed); break; case 's': //move back myView.move(-speed); break; case 'a': //strafe left myView.strafe(-speed); break; case 'd': //strafe right myView.strafe(speed); break; case 27: // “esc” on keyboard exit(0); break; } glutPostRedisplay(); }
/////////////////////////////////////////////////////////////////////////////////////////////////// // CalcShadowMatrices: calculate required matrices for shadow map generation - the light's // projection and transformation matrices void ShadowMapInternals::CalcShadowMatrices() { float minZ = ShadowBound[0].Z; ShadowBound.IntersectFrustumConservative(LightspaceCamera.GetFrustum()); // ShadowBound might have been empty to begin with, producing an empty result if (ShadowBound.IsEmpty()) { // no-op LightProjection.SetIdentity(); TextureMatrix = LightTransform; return; } // round off the shadow boundaries to sane increments to help reduce swim effect float boundInc = 16.0f; ShadowBound[0].X = floor(ShadowBound[0].X / boundInc) * boundInc; ShadowBound[0].Y = floor(ShadowBound[0].Y / boundInc) * boundInc; ShadowBound[1].X = ceil(ShadowBound[1].X / boundInc) * boundInc; ShadowBound[1].Y = ceil(ShadowBound[1].Y / boundInc) * boundInc; // minimum Z bound must not be clipped too much, because objects that lie outside // the shadow bounds cannot cast shadows either // the 2.0 is rather arbitrary: it should be big enough so that we won't accidentally miss // a shadow generator, and small enough not to affect Z precision ShadowBound[0].Z = minZ - 2.0; // Setup orthogonal projection (lightspace -> clip space) for shadowmap rendering CVector3D scale = ShadowBound[1] - ShadowBound[0]; CVector3D shift = (ShadowBound[1] + ShadowBound[0]) * -0.5; if (scale.X < 1.0) scale.X = 1.0; if (scale.Y < 1.0) scale.Y = 1.0; if (scale.Z < 1.0) scale.Z = 1.0; scale.X = 2.0 / scale.X; scale.Y = 2.0 / scale.Y; scale.Z = 2.0 / scale.Z; // make sure a given world position falls on a consistent shadowmap texel fractional offset float offsetX = fmod(ShadowBound[0].X - LightTransform._14, 2.0f/(scale.X*EffectiveWidth)); float offsetY = fmod(ShadowBound[0].Y - LightTransform._24, 2.0f/(scale.Y*EffectiveHeight)); LightProjection.SetZero(); LightProjection._11 = scale.X; LightProjection._14 = (shift.X + offsetX) * scale.X; LightProjection._22 = scale.Y; LightProjection._24 = (shift.Y + offsetY) * scale.Y; LightProjection._33 = scale.Z; LightProjection._34 = shift.Z * scale.Z; LightProjection._44 = 1.0; // Calculate texture matrix by creating the clip space to texture coordinate matrix // and then concatenating all matrices that have been calculated so far float texscalex = scale.X * 0.5f * (float)EffectiveWidth / (float)Width; float texscaley = scale.Y * 0.5f * (float)EffectiveHeight / (float)Height; float texscalez = scale.Z * 0.5f; CMatrix3D lightToTex; lightToTex.SetZero(); lightToTex._11 = texscalex; lightToTex._14 = (offsetX - ShadowBound[0].X) * texscalex; lightToTex._22 = texscaley; lightToTex._24 = (offsetY - ShadowBound[0].Y) * texscaley; lightToTex._33 = texscalez; lightToTex._34 = -ShadowBound[0].Z * texscalez; lightToTex._44 = 1.0; TextureMatrix = lightToTex * LightTransform; }
void CSphericalLight::Render( uint32 i_iPass ) { switch( i_iPass ) { case ePass_Leaf: return; case ePass_SphericalLight: break; } CGraphics *pGraphics = m_pParent->pGetParent()->pGetGraphics(); float32 fX = 1.2f * sinf( 1.5f * pGraphics->pGetParent()->fGetElapsedTime() ); CCamera *pCurCamera = pGraphics->pGetCurCamera(); matrix44 matWorld; matMatrix44Translation( matWorld, fX, 0.0f, 0.0f ); pCurCamera->SetWorldMatrix( matWorld ); m_pVertexShader->SetMatrix( m3dsc_wvpmatrix, pCurCamera->matGetWorldMatrix() * pCurCamera->matGetViewMatrix() * pCurCamera->matGetProjectionMatrix() ); m_pPixelShader->SetVector( 0, m_vColor ); m_pVertexShader->SetFloat( 0, 0.0f ); m_pPixelShader->SetFloat( 0, 0.0f ); pGraphics->SetVertexFormat( m_pVertexFormatSphere ); pGraphics->SetVertexStream( 0, m_pVertexBufferSphere, 0, sizeof( vertexformatsphere ) ); pGraphics->SetVertexShader( m_pVertexShader ); pGraphics->SetPixelShader( m_pPixelShader ); pGraphics->SetPrimitiveAssembler( m_pPrimitiveAssemblerSphere ); if( !m_iMaxVisiblePixels ) { // determine maximum number of pixels that can be rendered - colorwriteenable is false pGraphics->SetRenderState( m3drs_zenable, false ); pGraphics->SetRenderState( m3drs_colorwriteenable, false ); pGraphics->pGetM3DDevice()->DrawDynamicPrimitive( 0, m_iNumVertices ); m_iMaxVisiblePixels = pGraphics->pGetM3DDevice()->iGetRenderedPixels(); pGraphics->SetRenderState( m3drs_zenable, true ); pGraphics->SetRenderState( m3drs_colorwriteenable, true ); } pGraphics->pGetM3DDevice()->DrawDynamicPrimitive( 0, m_iNumVertices ); uint32 iRenderedPixels = pGraphics->pGetM3DDevice()->iGetRenderedPixels(); if( !iRenderedPixels ) return; // Now render the flare --------------------------------------------------- m_pVertexShader->SetFloat( 0, 1.0f ); m_pPixelShader->SetFloat( 0, 1.0f ); pGraphics->SetVertexFormat( m_pVertexFormatFlare ); pGraphics->SetVertexStream( 0, m_pVertexBufferFlare, 0, sizeof( vertexformatflare ) ); CResManager *pResManager = m_pParent->pGetParent()->pGetResManager(); CTexture *pFlare = (CTexture *)pResManager->pGetResource( m_hFlare ); pGraphics->SetTexture( 0, pFlare->pGetTexture() ); pGraphics->SetTextureSamplerState( 0, m3dtss_addressu, m3dta_clamp ); pGraphics->SetTextureSamplerState( 0, m3dtss_addressv, m3dta_clamp ); pGraphics->SetRenderState( m3drs_zenable, false ); m_pPixelShader->SetFloat( 1, (float32)iRenderedPixels / (float32)m_iMaxVisiblePixels ); pGraphics->pGetM3DDevice()->DrawPrimitive( m3dpt_trianglefan, 0, 2 ); }
void Init(HWND hWnd) { g_hWnd = hWnd; // Assign the window handle to a global window handle GetClientRect(g_hWnd, &g_rRect); // Assign the windows rectangle to a global RECT InitializeOpenGL(g_rRect.right, g_rRect.bottom); // Init OpenGL with the global rect // Here we open the config file and init some variables ifstream fin("Config.ini"); string strLevel = ""; string strTemp = ""; // Check if the file was not found or could not be opened if(fin.fail()) { // Display an error message and quit the program if file wasn't found MessageBox(g_hWnd, "Could not find Config.ini file!", "Error", MB_OK); PostQuitMessage(0); return; } // Read in the name of the level that will be loaded fin >> strLevel >> strLevel; // Now we need to read in the gamma level for our lightmaps fin >> strTemp >> g_Gamma; // Initialize the multitexturing function pointers glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) wglGetProcAddress("glActiveTextureARB"); glClientActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) wglGetProcAddress("glClientActiveTextureARB"); // Here we make sure that the functions were loaded properly if(!glActiveTextureARB || !glClientActiveTextureARB) { // Display an error message and quit MessageBox(g_hWnd, "Your video card doesn't support multitexturing", "Error", MB_OK); PostQuitMessage(0); } // Close the file fin.close(); // Here we load the level and get the result (true == success) bool bResult = g_Level.LoadBSP(strLevel.c_str()); // Make sure the file was found and we received a success if(bResult == false) { // Quit the application PostQuitMessage(0); return; } // Position the camera to the starting point since we have // not read in the entities yet, which gives the starting points. g_Camera.PositionCamera( 80, 320, 55, 80, 320, 155, 0, 1, 0); // Turn on depth testing and texture mapping glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); // Enable front face culling, since that's what Quake3 does glCullFace(GL_FRONT); glEnable(GL_CULL_FACE); }
void CAdvWater::UpdateWater(CGame* game) { if (!waterRendering->forceRendering && !readMap->HasVisibleWater()) return; glPushAttrib(GL_FOG_BIT | GL_COLOR_BUFFER_BIT); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); { bumpFBO.Bind(); glViewport(0, 0, 128, 128); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glSpringMatrix2dSetupPV(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); glColor3f(0.2f, 0.2f, 0.2f); CVertexArray* va = GetVertexArray(); va->Initialize(); va->EnlargeArrays(12, 0, VA_SIZE_T); glBindTexture(GL_TEXTURE_2D, rawBumpTexture[0]); va->AddVertexQT(ZeroVector, 0, 0 + gs->frameNum*0.0046f); va->AddVertexQT( UpVector, 0, 2 + gs->frameNum*0.0046f); va->AddVertexQT( XYVector, 2, 2 + gs->frameNum*0.0046f); va->AddVertexQT( RgtVector, 2, 0 + gs->frameNum*0.0046f); va->AddVertexQT(ZeroVector, 0, 0 + gs->frameNum*0.0026f); va->AddVertexQT( UpVector, 0, 4 + gs->frameNum*0.0026f); va->AddVertexQT( XYVector, 2, 4 + gs->frameNum*0.0026f); va->AddVertexQT( RgtVector, 2, 0 + gs->frameNum*0.0026f); va->AddVertexQT(ZeroVector, 0, 0 + gs->frameNum*0.0012f); va->AddVertexQT( UpVector, 0, 8 + gs->frameNum*0.0012f); va->AddVertexQT( XYVector, 2, 8 + gs->frameNum*0.0012f); va->AddVertexQT( RgtVector, 2, 0 + gs->frameNum*0.0012f); va->DrawArrayT(GL_QUADS); va = GetVertexArray(); va->Initialize(); glBindTexture(GL_TEXTURE_2D, rawBumpTexture[1]); va->AddVertexQT(ZeroVector, 0, 0 + gs->frameNum*0.0036f); va->AddVertexQT( UpVector, 0, 1 + gs->frameNum*0.0036f); va->AddVertexQT( XYVector, 1, 1 + gs->frameNum*0.0036f); va->AddVertexQT( RgtVector, 1, 0 + gs->frameNum*0.0036f); va->DrawArrayT(GL_QUADS); va = GetVertexArray(); va->Initialize(); glBindTexture(GL_TEXTURE_2D, rawBumpTexture[2]); va->AddVertexQT(ZeroVector, 0, 0 + gs->frameNum*0.0082f); va->AddVertexQT( UpVector, 0, 1 + gs->frameNum*0.0082f); va->AddVertexQT( XYVector, 1, 1 + gs->frameNum*0.0082f); va->AddVertexQT( RgtVector, 1, 0 + gs->frameNum*0.0082f); va->DrawArrayT(GL_QUADS); // this fixes a memory leak on ATI cards glBindTexture(GL_TEXTURE_2D, 0); glColor3f(1.0f, 1.0f, 1.0f); } reflectFBO.Bind(); glClearColor(sky->fogColor[0], sky->fogColor[1], sky->fogColor[2], 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); const double clipPlaneEqs[2 * 4] = { 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, }; CCamera* prvCam = CCamera::GetSetActiveCamera(CCamera::CAMTYPE_UWREFL); CCamera* curCam = CCamera::GetActiveCamera(); { curCam->CopyStateReflect(prvCam); curCam->UpdateLoadViewPort(0, 0, 512, 512); DrawReflections(&clipPlaneEqs[0], true, true); } CCamera::SetActiveCamera(prvCam->GetCamType()); prvCam->Update(); prvCam->LoadViewPort(); FBO::Unbind(); glPopAttrib(); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); }
void ActorViewer::Render() { m.Terrain.MakeDirty(RENDERDATA_UPDATE_COLOR); g_Renderer.SetClearColor(m.Background); // Disable shadows locally (avoid clobbering global state) bool oldShadows = g_Renderer.GetOptionBool(CRenderer::OPT_SHADOWS); g_Renderer.SetOptionBool(CRenderer::OPT_SHADOWS, m.ShadowsEnabled); bool oldSky = g_Renderer.GetSkyManager()->m_RenderSky; g_Renderer.GetSkyManager()->m_RenderSky = false; bool oldWater = g_Renderer.GetWaterManager()->m_RenderWater; g_Renderer.GetWaterManager()->m_RenderWater = false; g_Renderer.BeginFrame(); // Find the centre of the interesting region, in the middle of the patch // and half way up the model (assuming there is one) CVector3D centre; CmpPtr<ICmpVisual> cmpVisual(m.Simulation2, m.Entity); if (!cmpVisual.null()) cmpVisual->GetBounds().GetCentre(centre); else centre.Y = 0.f; centre.X = centre.Z = CELL_SIZE * m.Terrain.GetPatchesPerSide()*PATCH_SIZE/2; CCamera camera = View::GetView_Actor()->GetCamera(); camera.m_Orientation.Translate(centre.X, centre.Y, centre.Z); camera.UpdateFrustum(); g_Renderer.SetSceneCamera(camera, camera); g_Renderer.RenderScene(m); // .... glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.f, (float)g_xres, 0.f, (float)g_yres, -1.f, 1000.f); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glPushAttrib(GL_ENABLE_BIT); glEnable(GL_TEXTURE_2D); glDisable(GL_CULL_FACE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glDisable(GL_ALPHA_TEST); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_TEXTURE_2D); g_ProfileViewer.RenderProfile(); glPopAttrib(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); g_Renderer.EndFrame(); // Restore the old renderer state g_Renderer.SetOptionBool(CRenderer::OPT_SHADOWS, oldShadows); g_Renderer.GetSkyManager()->m_RenderSky = oldSky; g_Renderer.GetWaterManager()->m_RenderWater = oldWater; ogl_WarnIfError(); }
// À©µµ¿ì Ãâ·Â ÇÔ¼ö GLvoid drawScene(GLvoid) { GLfloat AmbientLight[] = { ambiant, ambiant, ambiant, 1.0f }; GLfloat DiffuseLight[] = { diffuse, diffuse, diffuse, 1.0f }; GLfloat SpecularLight[] = { specular, specular, specular, 1.0f }; GLfloat lightPos[] = { cos(lightangle*PI/180.0f)*floor_size*0.75, floor_size/2, sin(lightangle*PI / 180.0f)*floor_size*0.75, 1.0f }; GLfloat LightModel_Ambiant[] = {0.1,0.1,0.1,1.0}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, LightModel_Ambiant); glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 0.0); glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 0.0); GLfloat Ambient[] = { 0.5f, 0.5f, 1.0f, 1.0f }; GLfloat Specref[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, Ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Specref); glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 128); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // ¹ÙÅÁ»ö ÁöÁ¤ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // ¼³Á¤µÈ »öÀ¸·Î †Ã¼¸¦ Ä¥Çϱâ // »ö»ó ÁöÁ¤ÇÏ°í »ç°¢Çü ±×¸®±â glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL); glShadeModel(GL_SMOOTH); if (is_normal) glEnable(GL_NORMALIZE); else glDisable(GL_NORMALIZE); glLightfv(GL_LIGHT0, GL_AMBIENT, AmbientLight); glLightfv(GL_LIGHT0, GL_DIFFUSE, DiffuseLight); glLightfv(GL_LIGHT0, GL_SPECULAR, SpecularLight); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); if (light_0) glEnable(GL_LIGHT0); else glDisable(GL_LIGHT0); glColor4f(1.0, 1.0, 1.0, 1.0f); camera.Rander(); glPushMatrix(); { glColor3f(1.0,0.0,0.0); glPushMatrix(); { glTranslatef(cos(lightangle*PI/180.0f)*floor_size/2,floor_size/2, sin(lightangle*PI / 180.0f)*floor_size / 2); glutSolidCone(1,2,10,10); } glPopMatrix(); DrawAxis(); //////////////////<¹Ù´Ú>//////////////////// DrawFloor(); glColor4f(1.0, 1.0, 1.0, 1.0); glutWireCube(floor_size * 2); pyramid[0].Rander(); pyramid[1].Rander(); for (auto &p : snow) { p.Rander(); } } glPopMatrix(); glutSwapBuffers(); // ȸ鿡 Ãâ·ÂÇϱâ (glflushÈ¿°ú°¡ ÀÖ´Ù.)
void CModel::Render() { LPDIRECT3DDEVICE9 pDevice = rd::CRenderDevice::GetInstance()->GetRawDevice(); DWORD delta = bc::ut::CTimer::GetInstance()->GetFrameTime(); D3DXVECTOR3 vPosCamera = eg::CEngine::GetInstance()->GetActiveCamera()->GetPosition(); D3DXVECTOR3 vView = eg::CEngine::GetInstance()->GetActiveCamera()->GetView(); DWORD dwCurrentTime = bc::ut::CTimer::GetSystemTime(); CTerrainMesh::SGrid & grid = CXFile::GetInstance()->GetTerrainMesh()->GetGrid(FIX_GRID); m_vCenter = grid.vCenter; switch ( m_eCenterType ) { case ECT_CENTER: break; case ECT_CORNER: m_vCenter.x -= GRID_SPACE/2.0f; m_vCenter.z -= GRID_SPACE/2.0f; break; case ECT_XMIDWAY: m_vCenter.z -= GRID_SPACE/2.0f; break; case ECT_ZMIDWAY: m_vCenter.x -= GRID_SPACE/2.0f; break; } D3DXMatrixTranslation(&m_matWorldOff, m_vCenter.x + m_fShiftX, m_vCenter.y + m_fLift, m_vCenter.z + m_fShiftZ); m_mat = m_matSelfOff*m_matRotY*m_matWorldOff; //////////////////////////////////////////////////////////////////////// //// for wire box // //if ( this->IsSubUnit() ) //{ // D3DXVECTOR3 v = m_vOffset - m_vOffsetOverall; // D3DXVec3TransformCoord(&v,&v,&m_matRotY); // this->SetRelativePos(D3DXVECTOR3(m_matWorldOff._41 + v.x, m_matWorldOff._42 - m_vScale.y/2 + v.y, m_matWorldOff._43 + v.z)); //} //else //{ // this->SetRelativePos(D3DXVECTOR3(m_matWorldOff._41, m_matWorldOff._42, m_matWorldOff._43)); //} // //this->SetRelativeRotation(D3DXVECTOR3(0.0f,m_fRotation,0.0f)); //this->UpdateAbsolute(); //////////////////////////////////////////////////////////////////////// ICoreGraphic * pCoreGraphic = CXFile::GetInstance()->GetOperator()->GetCoreGraphic(); CXFile::GetInstance()->GetOperator()->GetGraphicModule()->ResetGraphicRenderStyle(CXFile::GetInstance()->GetOperator()->GetCoreGraphic()); ICamera * pCamera; pCoreGraphic->GetCamera(&pCamera); D3DXVECTOR3 vecPos = eg::CEngine::GetInstance()->GetActiveCamera()->GetPosition(); D3DXVECTOR3 vecView = eg::CEngine::GetInstance()->GetActiveCamera()->GetView(); pCamera->SetCamera(CVector3f(vecPos.x,vecPos.y,vecPos.z),CVector3f(vecView.x,vecView.y,vecView.z)); sc:CCamera * pMyCamera = eg::CEngine::GetInstance()->GetActiveCamera(); pCamera->SetProject(D3DXToRadian(pMyCamera->GetFOVY()), pMyCamera->GetNearPlane(),pMyCamera->GetFarPlane()); m_pModel->Render(*(CMatrix*)(&m_mat),dwCurrentTime,false); m_pModel->Render(*(CMatrix*)(&m_mat),dwCurrentTime,true); //int i = 0; //for ( std::vector<int>::iterator iter = m_vecBlockGrids.begin(); iter != m_vecBlockGrids.end(); ++iter, ++i ) //{ // m_vecpWireBox[i]->Render(); //} if ( sc::CXFile::GetInstance()->GetOperator()->GetSelectMode() ) { if ( this->GetLocked() || this->GetSelected() ) { // m_pWireBox->Render(); } //D3DXMATRIX mat; //D3DXMatrixIdentity(&mat); //pDevice->SetTransform(D3DTS_WORLD,&mat); //DWORD color[4] = {0xffffff}; //rd::CRenderDevice::GetInstance()->GetLayer3D()->DrawLineStrip(3, vCorners, color); //rd::CRenderDevice::GetInstance()->GetLayer3D()->DrawLineStrip(3, &vCorners[4], color); } ISceneNode::Render(); }
bool CScreen::SetDefaultGraphicsSettings3D() { HRESULT hr; D3DXMATRIX identityTransform, projTransform; D3DXMatrixIdentity(&identityTransform); D3DXMatrixPerspectiveFovLH(&projTransform, D3DX_PI / 4, 1.0f, 1.0f, 100.0f); D3DXVECTOR3 vEyePt(-10.0f, -10.0f, 10.0f); D3DXVECTOR3 vLookatPt(0.0f, 0.0f, 0.0f); D3DXVECTOR3 vUpVec(0.0f, 0.0f, 1.0f); D3DXMATRIXA16 matView; D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec); D3DCOLORVALUE lightColor = {1.0f, 1.0f, 1.0f, 1.0f}; D3DXVECTOR3 lightDir(-1.0f, 0.7f, -0.2f); D3DLIGHT9 light; setupDirectionalLight(light, lightColor, lightDir); D3DMATERIAL9 mtrl; ZeroMemory( &mtrl, sizeof( D3DMATERIAL9 ) ); mtrl.Diffuse = lightColor; mtrl.Ambient = lightColor; mtrl.Ambient.g = 0.0f; CGraphicsManager *pGraphicsManager = CGraphicsManager::GetInstance(); IDirect3DDevice9 *pDevice = pGraphicsManager->GetDevice(); CCamera * pCamera = CCamera::GetInstance(); hr = pDevice->SetTransform(D3DTS_WORLD, &identityTransform); if(FAILED(hr)) { LogErrorHr("Failed to set world transform", hr); return false; } D3DXMATRIX camViewMat = pCamera->GetViewMatrix(); hr = pDevice->SetTransform(D3DTS_VIEW, &camViewMat); if(FAILED(hr)) { LogErrorHr("Failed to set view transform", hr); return false; } D3DXMATRIX camProjMat = pCamera->GetProjectionMatrix(); hr = pDevice->SetTransform(D3DTS_PROJECTION, &camProjMat); if(FAILED(hr)) { LogErrorHr("Failed to set projection transform", hr); return false; } hr = pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); if(FAILED(hr)) { LogErrorHr("Failed to set cull mode render state", hr); return false; } hr = pDevice->SetLight(0, &light); if(FAILED(hr)) { LogErrorHr("Failed to set light 0", hr); return false; } hr = pDevice->SetMaterial(&mtrl); if(FAILED(hr)) { LogErrorHr("Failed to set material", hr); return false; } hr = pDevice->LightEnable(0, TRUE); if(FAILED(hr)) { LogErrorHr("Failed to enable light", hr); return false; } hr = pDevice->SetRenderState(D3DRS_AMBIENT, 0x00202020); if(FAILED(hr)) { LogErrorHr("Failed to set ambient color", hr); return false; } hr = pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); if(FAILED(hr)) { LogErrorHr("Failed to enable z", hr); return false; } hr = pDevice->SetRenderState(D3DRS_ZWRITEENABLE , TRUE); if(FAILED(hr)) { LogErrorHr("Failed to set z write enabled", hr); return false; } hr = pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); if(FAILED(hr)) { LogErrorHr("Failed to set sampler state - MINFILTER", hr); return false; } hr = pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); if(FAILED(hr)) { LogErrorHr("Failed to set sampler state - MAGFILTER", hr); return false; } hr = pDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); if(FAILED(hr)) { LogErrorHr("Failed to set sampler state - MIPFILTER", hr); return false; } return true; }
void CGizmo::DrawGizmoAxis(CRender3D *pRender, Vector& Origin, Vector& EndPoint, int red, int green, int blue, unsigned int uAxisHandle) { CCamera *pCamera = pRender->GetCamera(); Vector ViewUp; pCamera->GetViewUp(ViewUp); Vector ViewPoint; Vector ViewForward; pCamera->GetViewPoint(ViewPoint); VectorSubtract(Origin, ViewPoint, ViewForward); Vector Axis; VectorSubtract(EndPoint, Origin, Axis); CrossProduct(ViewForward, Axis, ViewUp); VectorNormalize(ViewUp); Vector Start; Vector End; // // Draw the first segment of the gizmo axis. // VectorMA(Origin, 0.1, Axis, Start); VectorMA(Origin, 0.25, Axis, End); pRender->BindTexture( g_pAxisTexture ); CMeshBuilder meshBuilder; CMatRenderContextPtr pRenderContext( MaterialSystemInterface() ); IMesh* pMesh = pRenderContext->GetDynamicMesh( ); meshBuilder.Begin( pMesh, MATERIAL_POLYGON, 4 ); meshBuilder.TexCoord2f(0, 0, 0); meshBuilder.Position3f(Start[0] - ViewUp[0] * GIZMO_AXIS_WIDTH, Start[1] - ViewUp[1] * GIZMO_AXIS_WIDTH, Start[2] - ViewUp[2] * GIZMO_AXIS_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.TexCoord2f(0, 2, 0); meshBuilder.Position3f(End[0] - ViewUp[0] * GIZMO_AXIS_WIDTH, End[1] - ViewUp[1] * GIZMO_AXIS_WIDTH, End[2] - ViewUp[2] * GIZMO_AXIS_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.TexCoord2f(0, 2, 1); meshBuilder.Position3f(End[0] + ViewUp[0] * GIZMO_AXIS_WIDTH, End[1] + ViewUp[1] * GIZMO_AXIS_WIDTH, End[2] + ViewUp[2] * GIZMO_AXIS_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.TexCoord2f(0, 0, 1); meshBuilder.Position3f(Start[0] + ViewUp[0] * GIZMO_AXIS_WIDTH, Start[1] + ViewUp[1] * GIZMO_AXIS_WIDTH, Start[2] + ViewUp[2] * GIZMO_AXIS_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); // // Draw the scale handle. // Start = End; VectorMA(Origin, 0.35, Axis, End); pRender->BeginRenderHitTarget(this, uAxisHandle + GIZMO_HANDLE_SCALE); pRender->BindTexture( g_pScaleHandleTexture ); pMesh = pRenderContext->GetDynamicMesh( ); meshBuilder.Begin( pMesh, MATERIAL_POLYGON, 4 ); meshBuilder.TexCoord2f( 0, 0, 0); meshBuilder.Position3f(Start[0] - ViewUp[0] * GIZMO_HANDLE_WIDTH, Start[1] - ViewUp[1] * GIZMO_HANDLE_WIDTH, Start[2] - ViewUp[2] * GIZMO_HANDLE_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.TexCoord2f( 0, 1, 0); meshBuilder.Position3f(End[0] - ViewUp[0] * GIZMO_HANDLE_WIDTH, End[1] - ViewUp[1] * GIZMO_HANDLE_WIDTH, End[2] - ViewUp[2] * GIZMO_HANDLE_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.TexCoord2f( 0, 1, 1); meshBuilder.Position3f(End[0] + ViewUp[0] * GIZMO_HANDLE_WIDTH, End[1] + ViewUp[1] * GIZMO_HANDLE_WIDTH, End[2] + ViewUp[2] * GIZMO_HANDLE_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.TexCoord2f( 0, 0, 1); meshBuilder.Position3f(Start[0] + ViewUp[0] * GIZMO_HANDLE_WIDTH, Start[1] + ViewUp[1] * GIZMO_HANDLE_WIDTH, Start[2] + ViewUp[2] * GIZMO_HANDLE_WIDTH); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); pRender->EndRenderHitTarget(); // // Draw the second segment of the gizmo axis. // Start = End; VectorMA(Origin, 0.5, Axis, End); pRender->BindTexture( g_pAxisTexture ); pMesh = pRenderContext->GetDynamicMesh( ); meshBuilder.Begin( pMesh, MATERIAL_POLYGON, 4 ); meshBuilder.TexCoord2f( 0, 0, 0); meshBuilder.Position3f(Start[0] - ViewUp[0] * GIZMO_AXIS_WIDTH, Start[1] - ViewUp[1] * GIZMO_AXIS_WIDTH, Start[2] - ViewUp[2] * GIZMO_AXIS_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.TexCoord2f( 0, 2, 0); meshBuilder.Position3f(End[0] - ViewUp[0] * GIZMO_AXIS_WIDTH, End[1] - ViewUp[1] * GIZMO_AXIS_WIDTH, End[2] - ViewUp[2] * GIZMO_AXIS_WIDTH); meshBuilder.AdvanceVertex(); meshBuilder.Color3ub(red, green, blue); meshBuilder.TexCoord2f( 0, 2, 1); meshBuilder.Position3f(End[0] + ViewUp[0] * GIZMO_AXIS_WIDTH, End[1] + ViewUp[1] * GIZMO_AXIS_WIDTH, End[2] + ViewUp[2] * GIZMO_AXIS_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.TexCoord2f( 0, 0, 1); meshBuilder.Position3f(Start[0] + ViewUp[0] * GIZMO_AXIS_WIDTH, Start[1] + ViewUp[1] * GIZMO_AXIS_WIDTH, Start[2] + ViewUp[2] * GIZMO_AXIS_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); // // Draw the rotate handle. // Start = End; VectorMA(Origin, 0.6, Axis, End); pRender->BeginRenderHitTarget(this, uAxisHandle + GIZMO_HANDLE_ROTATE); pRender->BindTexture( g_pRotateHandleTexture ); pMesh = pRenderContext->GetDynamicMesh( ); meshBuilder.Begin( pMesh, MATERIAL_POLYGON, 4 ); meshBuilder.TexCoord2f( 0, 0, 0); meshBuilder.Position3f(Start[0] - ViewUp[0] * GIZMO_HANDLE_WIDTH, Start[1] - ViewUp[1] * GIZMO_HANDLE_WIDTH, Start[2] - ViewUp[2] * GIZMO_HANDLE_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.TexCoord2f( 0, 1, 0); meshBuilder.Position3f(End[0] - ViewUp[0] * GIZMO_HANDLE_WIDTH, End[1] - ViewUp[1] * GIZMO_HANDLE_WIDTH, End[2] - ViewUp[2] * GIZMO_HANDLE_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.TexCoord2f( 0, 1, 1); meshBuilder.Position3f(End[0] + ViewUp[0] * GIZMO_HANDLE_WIDTH, End[1] + ViewUp[1] * GIZMO_HANDLE_WIDTH, End[2] + ViewUp[2] * GIZMO_HANDLE_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.TexCoord2f( 0, 0, 1); meshBuilder.Position3f(Start[0] + ViewUp[0] * GIZMO_HANDLE_WIDTH, Start[1] + ViewUp[1] * GIZMO_HANDLE_WIDTH, Start[2] + ViewUp[2] * GIZMO_HANDLE_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); pRender->EndRenderHitTarget(); // // Draw the third segment of the gizmo axis. // Start = End; VectorMA(Origin, 0.75, Axis, End); pRender->BindTexture( g_pAxisTexture ); pMesh = pRenderContext->GetDynamicMesh( ); meshBuilder.Begin( pMesh, MATERIAL_POLYGON, 4 ); meshBuilder.TexCoord2f( 0, 0, 0); meshBuilder.Position3f(Start[0] - ViewUp[0] * GIZMO_AXIS_WIDTH, Start[1] - ViewUp[1] * GIZMO_AXIS_WIDTH, Start[2] - ViewUp[2] * GIZMO_AXIS_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.TexCoord2f( 0, 2, 0); meshBuilder.Position3f(End[0] - ViewUp[0] * GIZMO_AXIS_WIDTH, End[1] - ViewUp[1] * GIZMO_AXIS_WIDTH, End[2] - ViewUp[2] * GIZMO_AXIS_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.TexCoord2f( 0, 2, 1); meshBuilder.Position3f(End[0] + ViewUp[0] * GIZMO_AXIS_WIDTH, End[1] + ViewUp[1] * GIZMO_AXIS_WIDTH, End[2] + ViewUp[2] * GIZMO_AXIS_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.TexCoord2f( 0, 0, 1); meshBuilder.Position3f(Start[0] + ViewUp[0] * GIZMO_AXIS_WIDTH, Start[1] + ViewUp[1] * GIZMO_AXIS_WIDTH, Start[2] + ViewUp[2] * GIZMO_AXIS_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); // // Draw the translate handle (arrowhead). // Start = End; pRender->BeginRenderHitTarget(this, uAxisHandle + GIZMO_HANDLE_TRANSLATE); pRender->BindTexture( g_pTranslateHandleTexture ); pMesh = pRenderContext->GetDynamicMesh( ); meshBuilder.Begin( pMesh, MATERIAL_TRIANGLES, 1 ); meshBuilder.TexCoord2f( 0, 0, 0); meshBuilder.Position3f(Start[0] - ViewUp[0] * GIZMO_HANDLE_WIDTH, Start[1] - ViewUp[1] * GIZMO_HANDLE_WIDTH, Start[2] - ViewUp[2] * GIZMO_HANDLE_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.TexCoord2f( 0, 1, 0.5); meshBuilder.Position3f(EndPoint[0], EndPoint[1], EndPoint[2]); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.TexCoord2f( 0, 0, 1); meshBuilder.Position3f(Start[0] + ViewUp[0] * GIZMO_HANDLE_WIDTH, Start[1] + ViewUp[1] * GIZMO_HANDLE_WIDTH, Start[2] + ViewUp[2] * GIZMO_HANDLE_WIDTH); meshBuilder.Color3ub(red, green, blue); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); pRender->EndRenderHitTarget(); }
void CBoss3::Update(int delta_time) { CResourcesManager* rs = CResourcesManager::GetInstance(); CCamera* c = rs->_camera; if (c->view_port.x + c->getWidth() + 5 >= rs->m_widthMap) _enable = true; if (_hp == 0) SetStatus(EDie); if (!_enable || _hp <= 0) return; //Target mục tiêu D3DXVECTOR3 pos_target = CResourcesManager::GetInstance()->m_posBill; SetTarget(pos_target.x, pos_target.y); //Cập nhật lại những viên đạn có thể bắn trong list của enemy _weapon->UpdateQueueIdBullet(_queue_id_bullet); if (!_is_hide) { if (_last_time_hide == 0) _last_time_hide = GetTickCount(); DWORD now = GetTickCount(); if (now - _last_time_hide >= BOSS3_ELAPSED_TIME_HIDE) { _enemy_status = EWait; _is_hide = true; _ready_shoot = false; _last_time_hide = 0; //Random tọa độ xuất hiện tiếp theo CCamera* c = CResourcesManager::GetInstance()->_camera; _x_random = (_target.x - BOSS3_RANDOM_DISTANCE_APPEAR_X) + rand() % (2 * BOSS3_RANDOM_DISTANCE_APPEAR_X); _y_random = c->getWidth() * 2 / 3 + rand() % BOSS3_RANDOM_DISTANCE_APPEAR_Y; D3DXVECTOR3 pos_check = c->Transform(_x_random, _y_random); if (pos_check.x - 60 < 0) _x_random = c->view_port.x + 60; if (pos_check.x + 60 > c->getWidth()) _x_random = c->view_port.x + c->getWidth() - 60; } } else { if (_last_time_appear == 0) _last_time_appear = GetTickCount(); DWORD now = GetTickCount(); if (now - _last_time_appear >= BOSS3_ELAPSED_TIME_APPEAR) { _enemy_status = EAttack; _is_hide = false; _last_time_appear = 0; _physical.x = _x_random; _physical.y = _y_random; } } switch (_enemy_status) { case EWait: case EDie: _can_impact = false; _physical.SetBounds(0, 0, 0, 0); break; case EAttack: _can_impact = true; _physical.SetBounds(_physical.x, _physical.y, 40, 40); break; } }
void CShadowHandler::CalcMinMaxView() { // derive the size of the shadow-map from the // intersection points of the camera frustum // with the xz-plane CCamera* cam = CCamera::GetCamera(CCamera::CAMTYPE_VISCUL); cam->GetFrustumSides(0.0f, 0.0f, 1.0f, true); cam->ClipFrustumLines(true, -20000.0f, mapDims.mapy * SQUARE_SIZE + 20000.0f); shadowProjMinMax.x = -100.0f; shadowProjMinMax.y = 100.0f; shadowProjMinMax.z = -100.0f; shadowProjMinMax.w = 100.0f; //if someone could figure out how the frustum and nonlinear shadow transform really works (and not use the SJan trial and error method) //so that we can skip this sort of fudge factors it would be good float borderSize = 270.0f; float maxSize = globalRendering->viewRange * 0.75f; if (shadowMapSize == 1024) { borderSize *= 1.5f; maxSize *= 1.2f; } const std::vector<CCamera::FrustumLine>& negSides = cam->GetNegFrustumSides(); const std::vector<CCamera::FrustumLine>& posSides = cam->GetPosFrustumSides(); std::vector<CCamera::FrustumLine>::const_iterator fli; if (!negSides.empty()) { for (fli = negSides.begin(); fli != negSides.end(); ++fli) { if (fli->minz < fli->maxz) { float3 p[5]; p[0] = float3(fli->base + fli->dir * fli->minz, 0.0f, fli->minz); p[1] = float3(fli->base + fli->dir * fli->maxz, 0.0f, fli->maxz); p[2] = float3(fli->base + fli->dir * fli->minz, readMap->initMaxHeight + 200, fli->minz); p[3] = float3(fli->base + fli->dir * fli->maxz, readMap->initMaxHeight + 200, fli->maxz); p[4] = projMidPos[2]; for (int a = 0; a < 5; ++a) { const float xd = (p[a] - projMidPos[2]).dot(sunDirX); const float yd = (p[a] - projMidPos[2]).dot(sunDirY); if (xd + borderSize > shadowProjMinMax.y) { shadowProjMinMax.y = xd + borderSize; } if (xd - borderSize < shadowProjMinMax.x) { shadowProjMinMax.x = xd - borderSize; } if (yd + borderSize > shadowProjMinMax.w) { shadowProjMinMax.w = yd + borderSize; } if (yd - borderSize < shadowProjMinMax.z) { shadowProjMinMax.z = yd - borderSize; } } } } if (shadowProjMinMax.x < -maxSize) { shadowProjMinMax.x = -maxSize; } if (shadowProjMinMax.y > maxSize) { shadowProjMinMax.y = maxSize; } if (shadowProjMinMax.z < -maxSize) { shadowProjMinMax.z = -maxSize; } if (shadowProjMinMax.w > maxSize) { shadowProjMinMax.w = maxSize; } } else { shadowProjMinMax.x = -maxSize; shadowProjMinMax.y = maxSize; shadowProjMinMax.z = -maxSize; shadowProjMinMax.w = maxSize; } // xScale = (shadowProjMinMax.y - shadowProjMinMax.x) * 1.5f; // yScale = (shadowProjMinMax.w - shadowProjMinMax.z) * 1.5f; }
//============================================================================= //初期化 //============================================================================= //[input] // pScene:設定するシーン //============================================================================= bool CScene::Init( CScene *pScene ) { if( m_IsFirstBoot ) { /*マウスの取得*/ pScene->m_pMouse = m_pApp->GetCore()->GetMouse(); //----------------------------------------------------------------- // シーン //----------------------------------------------------------------- m_pSceneMgr[S_MAIN]->SetRenderSize( m_pApp->GetScreenWidth(), m_pApp->GetScreenHeight() ); m_pSceneMgr[S_SUB]->SetRenderSize( m_pApp->GetScreenWidth(), m_pApp->GetScreenHeight() ); for( int i = 0;i < S_MAX;++i ) { m_pSceneMgr[i]->CreateDevice( m_pApp->GetRenderer() ); } m_pSceneMgr[S_MAIN]->SetInitParameter( false ); m_pSceneMgr[S_SUB]->SetInitParameter( true ); //----------------------------------------------------------------- //オブジェクトの追加 //----------------------------------------------------------------- //std::ifstream ifs("aa.csv"); //char Temp[256]; //char Temp2[256]; // //string strDataName; //string strObjectName; //ifs >> Temp >> Temp2; // //strDataName = Temp; //strObjectName = Temp2; //m_pGameObj->AppendObject( new CField(strDataName), strObjectName, true ); Selene::File::IResourceFile *pResFile = NULL; #if defined(DEBUG_CHAT) #else m_p3DObj->AppendObject( new CField("map.stm"), "Field", true ); //m_pGameObj->AppendObject( new CField("Kaidan.stm"), "Field", true ); //ifs >> Temp >> Temp2 ; // //strDataName = Temp; //strObjectName = Temp2; m_pApp->GetFileMgr()->SetCurrentPath( "CSV" ); pResFile = m_pApp->GetFileMgr()->FileOpen("Ameus.csv"); m_p3DObj->AppendObject( new CPlayer("Camerun.smf" , Math::Vector3D( 0, 7, -73) ) , "Player", true ); m_p3DObj->AppendObject( new CTrain("train1.smf", Math::Vector3D(0.0f, 0.0f, -73.0f) ), "Train", true ); m_p3DObj->AppendObject( new CEnemyAmeus("ameus.smf", Math::Vector3D(-141.0f , 1.0f, -238.0f), pResFile->GetNamePointer() ), "Ameus", true ); SAFE_RELEASE( pResFile ); for( int i = 0;i < BIRD_MAX;++i ) { char Temp[20] = ""; sprintf( Temp, "bird%d.csv", i+1 ); pResFile = m_pApp->GetFileMgr()->FileOpen(Temp); sprintf(Temp, "Bird%d", i+1 ); m_p3DObj->AppendObject( new CEnemyBird("bird.smf", Math::Vector3D(0.0f, 120.0, -45.0f), pResFile->GetNamePointer() ), Temp, true ); SAFE_RELEASE( pResFile ); } for( int i = 0;i < MOUSE_MAX;++i ) { char Temp[20] = ""; sprintf( Temp, "mouse%d.csv", i+1 ); pResFile = m_pApp->GetFileMgr()->FileOpen(Temp); sprintf(Temp, "Mouse%d", i+1 ); m_p3DObj->AppendObject( new CEnemyMouse("mouse.smf", Math::Vector3D(0.0f, 0.0f, -40.0f), pResFile->GetNamePointer() ), Temp, true ); SAFE_RELEASE( pResFile ); } pResFile = m_pApp->GetFileMgr()->FileOpen("manta.csv"); #if defined( TEST_RELEASE ) m_p3DObj->AppendObject( new CEnemyManta("manta.smf", Math::Vector3D(0.0f, 0.0f, -40.0f), pResFile->GetNamePointer() ), "Manta", true ); #else m_p3DObj->AppendObject( new CEnemyManta("manta.smf", Math::Vector3D(0.0f, 80.0f, -40.0f), pResFile->GetNamePointer() ), "Manta", true ); #endif SAFE_RELEASE( pResFile ); pResFile = m_pApp->GetFileMgr()->FileOpen("rabbit.csv"); m_p3DObj->AppendObject( new CEnemyRabbit("rabbit.smf", Math::Vector3D(0.0f, 0.0f, -40.0f), pResFile->GetNamePointer() ), "Rabbit", true ); SAFE_RELEASE( pResFile ); m_p3DObj->AppendObject( new CCamObject("camera.smf"), "CamObj", false ); m_p3DObj->AppendObject( new CCharacter("statue_dove.smf", Math::Vector3D( -188, 3.6f, -361) ), "FountObj", true ); m_p3DObj->AppendObject( new CCharacter("flag.smf", Math::Vector3D( -188, 3.6f, -361) ), "Flag", true ); //m_p3DObj->AppendObject( new CFlagObject("flag.smf"), "Flag", false ); //m_p3DObj->AppendObject( new CCharacter("statue_dove.smf", Math::Vector3D( -188, 4.4f, -361) ), "FountObj2", true ); //m_p3DObj->AppendObject( new CCharacter("statue_dove.smf", Math::Vector3D( -188, 4.4f, -361) ), "FountObj3", true ); m_p3DObj->AppendObject( new CCharacter("arrow.smf", Math::Vector3D( 0, 0, 0 ) ), "Arrow", true ); //m_p3DObj->AppendObject( new CSprite3D("title.png", Math::Vector3D( 0, 0, -100 ) ), "BillBoard", true ); m_p3DObj->AppendObject( new CCharacter("target.smf", Math::Vector3D( 0, 0, -100 ) ), "Target", true ); m_p3DObj->AppendObject( new CCharacter("star.smf", Math::Vector3D( 0, 0, -100 ) ), "Star", false ) ; m_p3DObj->AppendObject( new CCharacter("flying_island.smf", Math::Vector3D( 162, 180, -212 ) ), "IsLand", true ) ; m_p3DObj->AppendObject( new CSprite3D("flgemo.dds", Math::Vector3D( 0, 0, -10 ) ), "FlagBalloon", true ); m_p3DObj->AppendObject( new CParticle("smoke.dds", Math::Vector3D(0, 0, 10) ), "RunEffect0", false ); m_p3DObj->AppendObject( new CParticle("smoke.dds", Math::Vector3D(0, 0, 10) ), "RunEffect1", false ); m_p3DObj->AppendObject( new CParticle("smoke.dds", Math::Vector3D(0, 0, 10) ), "RunEffect2", false ); m_p3DObj->AppendObject( new CParticle("smoke.dds", Math::Vector3D(0, 0, 10) ), "RunEffect3", false ); m_p3DObj->AppendObject( new CFlash("flash2.png", Math::Vector3D( 0, 0, 0 ) ), "Emission0", false ); m_p3DObj->AppendObject( new CFlash("flash2.png", Math::Vector3D( 0, 0, 0 ) ), "Emission1", false ); m_p3DObj->AppendObject( new CFlash("flash2.png", Math::Vector3D( 0, 0, 0 ) ), "Emission2", false ); m_p3DObj->AppendObject( new CFlash("flash2.png", Math::Vector3D( 0, 0, 0 ) ), "Emission3", false ); m_p3DObj->AppendObject( new CFlash("flash2.png", Math::Vector3D( 0, 0, 0 ) ), "Emission4", false ); m_p3DObj->AppendObject( new CFlash("flash2.png", Math::Vector3D( 0, 0, 0 ) ), "Emission5", false ); m_p3DObj->AppendObject( new CSprite3D("emo.dds", Math::Vector3D( 0, 0, 0 ) ), "Emotion", false ); m_pSoundObj->AppendObject( new CSoundEffect("shutter.WAV"), "Shutter", true ); m_pSoundObj->AppendObject( new CSoundEffect("flag.WAV"), "Flag", true ); m_pSoundObj->AppendObject( new CSoundEffect("run.WAV"), "Run", true ); m_pSoundObj->AppendObject( new CSoundEffect("train.WAV"), "STrain", true ); m_pSoundObj->AppendObject( new CSoundEffect("change.WAV"), "Change", true ); m_pSoundObj->AppendObject( new CSoundEffect("enter.WAV"), "Enter", true ); m_pSoundObj->AppendObject( new CSoundEffect("collision.WAV"), "Collision", true ); m_pSoundObj->AppendObject( new CSoundEffect("mouse.WAV"), "Mouse", true ); m_pSoundObj->AppendObject( new CSoundEffect("flagrecall.WAV"), "RecallFlag", true ); m_pSoundObj->AppendObject( new CSoundEffect("flagsetfail.WAV"), "SetFlagFail", true ); m_pSoundObj->AppendObject( new CSoundEffect("missionclear.WAV"), "MissionClear", true ); m_pSoundObj->AppendObject( new CSoundEffect("missionfail.WAV"), "MissionFail", true ); m_pSoundObj->AppendObject( new CSoundEffect("bird.WAV"), "Bird", true ); m_pSoundObj->AppendObject( new CSoundEffect("select.WAV"), "Select", true ); m_pSoundObj->AppendObject( new CSoundEffect("DrumRoll.WAV"), "DrumRoll", true ); m_pSoundObj->AppendObject( new CSoundEffect("decide.WAV"), "Decide", true ); //while( !ifs.eof() ) //{ // ifs >> Temp >> Temp2; // // strDataName = Temp; // strObjectName = Temp2; // // m_pSoundObj->AppendObject( new CSoundEffect(strDataName), strObjectName, true ); // //} #endif m_pSoundObj->AppendObject( new CBGM("BGM.ogg"), "TitleBGM", true ); m_pSoundObj->AppendObject( new CBGM("Rolling Railing Hiking!.ogg"), "GameBGM", true ); m_pSoundObj->AppendObject( new CBGM("TitleBGM.ogg"), "ChatBGM", true ); m_pSoundObj->AppendObject( new CBGM("BGM.ogg"), "ResultBGM", true ); m_pGameObj->AppendObject( new CCamera(), "CamMain", true ); m_pGameObj->AppendObject( new CCamera(), "CamSub", true ); m_pGameObj->AppendObject( new CFontSprite("font.sff", Math::Vector2D( 200, 400 ) ), "TitleFont", true ); m_pGameObj->AppendObject( new CFontSprite("font2.sff", Math::Vector2D( 200, 400 ) ), "CommonFont", true ); m_pGameObj->AppendObject( new CFontSprite("MissionFont.sff", Math::Vector2D( 430, 13) ), "MissionFont", true ); m_pGameObj->AppendObject( new CFontSprite("MenuFont.sff", Math::Vector2D( 220, 100 ) ), "MenuFont", true ); m_pGameObj->AppendObject( new CFontSprite("ChatFont.sff", Math::Vector2D( 110, 465 ) ), "ChatFont", true ); m_pGameObj->AppendObject( new CFontSprite("NumFont.sff", Math::Vector2D( 110, 465 ) ), "NumFont", true ); m_pGameObj->AppendObject( new CFontSprite("MiContFont.sff", Math::Vector2D( 110, 465 ) ), "ContentFont", true ); m_pGameObj->AppendObject( new CFontSprite("MiContFont2.sff", Math::Vector2D( 110, 465 ) ), "ContentFont2", true ); m_pGameObj->AppendObject( new CFontSprite("ExplainFont.sff", Math::Vector2D( 110, 465 ) ), "ExplainFont", true ); //m_pGameObj->AppendObject( new Draw2DObject("Build_1.bmp", Math::Vector2D(100, 200) ), "Film", true ); #if defined( DEBUG_MAP_EDIT ) #elif defined( DEBUG_MAP_SEE ) #else m_p2DObj->AppendObject( new CSprite("title.png", Math::Vector2D( 0, 0 ) ), "Title", false ); m_p2DObj->AppendObject( new CSprite("background.png", Math::Vector2D( 0, 0 ) ), "MissionSelect", false ); m_p2DObj->AppendObject( new CSprite("chat.png", Math::Vector2D( 0, 0 ) ), "Chat", false ); m_p2DObj->AppendObject( new CSprite("Result.png", Math::Vector2D( 0, 0 ) ), "Result", false ); m_p2DObj->AppendObject( new CSprite("back.png", Math::Vector2D( 0, 0 ) ), "CalcScore", false ); m_p2DObj->AppendObject( new CSprite("clear.dds", Math::Vector2D( 0, 0 ) ), "GameClear", false ); m_p2DObj->AppendObject( new CSprite("failure.dds", Math::Vector2D( 0, 0 ) ), "GameFailure", false ); #endif const char *pMiniCharaName[] = { "Mini_Mouse1", "Mini_Mouse2", "Mini_Mouse3", "Mini_Bird1", "Mini_Bird2", "Mini_Bird3", "Mini_Bird4", "Mini_Bird5", "Mini_Bird6", }; m_p2DObj->AppendObject( new CMiniMap("minimap3.png", Math::Vector2D( 0, 0) ), "MiniMap", true ); m_p2DObj->AppendObject( new CSprite("came.dds", Math::Vector2D( 200, 200) ), "Mini_Player", true ); m_p2DObj->AppendObject( new CSprite("mini_flag.dds", Math::Vector2D( 0, 0 ) ), "Mini_Camera", false ); for( int i = 0;i < MINI_CHARA_MAX;++i ) { m_p2DObj->AppendObject( new CSprite("mini_camera.png", Math::Vector2D( 0, 0 ) ), pMiniCharaName[i], false ); } m_p2DObj->AppendObject( new CSprite("mini_target.dds", Math::Vector2D( 0, 0 ) ), "Mini_Target", false ); m_p2DObj->AppendObject( new CSprite("pauseback.png", Math::Vector2D( 0, 0 ) ), "Pause", false ); m_p2DObj->AppendObject( new CSprite("menu.dds", Math::Vector2D( 0, 0 ) ), "Menu", true ); m_p2DObj->AppendObject( new CSprite("char.dds", Math::Vector2D( 170, 7 ) ), "CharaIcon", true ); m_p2DObj->AppendObject( new CSprite("flag.dds", Math::Vector2D( 170, 7 ) ), "FlagIcon", true ); m_p2DObj->AppendObject( new CSprite("film.dds", Math::Vector2D( 220, 7 ) ), "Film", true ); m_p2DObj->AppendObject( new CSprite("bar.dds", Math::Vector2D( 310, 5 ) ), "Bar", true ); m_p2DObj->AppendObject( new CSprite("systemmenu.dds", Math::Vector2D( 100, 200 ) ), "PopMenu", true ); m_p2DObj->AppendObject( new CSprite("high.dds", Math::Vector2D( 590, 90 ) ), "HighScore", false ); m_p2DObj->AppendObject( new CSprite("pointa.dds", Math::Vector2D( 645, 470 ) ), "Pointa", true ); m_p2DObj->AppendObject( new CSprite("Cloud.tga", Math::Vector2D( 0, 0 ) ), "Cloud", true ); #if defined( DEBUG_MAP_EDIT ) #elif defined( DEBUG_MAP_SEE ) #else m_p2DObj->AppendObject( new CSprite("mission1.dds", Math::Vector2D( 270, 208 ) ), "MissionFont1", true ); m_p2DObj->AppendObject( new CSprite("mission2.dds", Math::Vector2D( 115, 298 ) ), "MissionFont2", true ); m_p2DObj->AppendObject( new CSprite("mission3.dds", Math::Vector2D( 452, 128 ) ), "MissionFont3", true ); m_p2DObj->AppendObject( new CSprite("mission4.dds", Math::Vector2D( 65, 138 ) ), "MissionFont4", true ); m_p2DObj->AppendObject( new CSprite("mission5.dds", Math::Vector2D( 426, 318 ) ), "MissionFont5", true ); m_p2DObj->AppendObject( new CSprite("pin.dds", Math::Vector2D( 383, 142 ) ), "Pin", true ); //m_p2DObj->AppendObject( new CSprite("pin2.dds", Math::Vector2D( 665, 490 ) ), "Pin2", true ); m_p2DObj->AppendObject( new CSprite("train.png", Math::Vector2D( 280, 150) ), "Picture1", true ); m_p2DObj->AppendObject( new CSprite("ameus.png", Math::Vector2D( 125, 240) ), "Picture2", true ); m_p2DObj->AppendObject( new CSprite("oashisu.png", Math::Vector2D( 480, 70) ), "Picture3", true ); m_p2DObj->AppendObject( new CSprite("funsui.png", Math::Vector2D( 75, 80 ) ), "Picture4", true ); m_p2DObj->AppendObject( new CSprite("manta.png", Math::Vector2D( 440, 260 ) ), "Picture5", true ); m_p2DObj->AppendObject( new CSprite("note.dds", Math::Vector2D( 322, 200 ) ), "Note", false ); #endif m_p2DObj->AppendObject( new CSprite("ready.dds", Math::Vector2D( 159, 245 ) ), "Ready", true ); m_p2DObj->AppendObject( new CSprite("go.dds", Math::Vector2D( 300, 238 ) ), "Go", true ); m_p2DObj->AppendObject( new CSprite("nofilm.dds", Math::Vector2D( 300, 238 ) ), "NoFilm", false ); m_p3DObj->AppendObject( new CDebugLine(), "DebugLine", true ); //ifs.close(); #if defined( DEBUG_MAP_EDIT ) #elif defined( DEBUG_MAP_SEE ) #elif defined( DEBUG_CHAT ) #else CSprite *pPin = dynamic_cast<CSprite *>( pScene->Get2DObject()->FindObjectFromName("Pin") ); pPin->SetDivnum( Math::Point2DI(2, 1) ); CSprite3D *pEmotion = dynamic_cast<CSprite3D *>( pScene->Get3DObject()->FindObjectFromName("Emotion") ); pEmotion->SetDivnum( Math::Point2DI( 4, 1 ) ); CSprite3D *pFlagBal = dynamic_cast<CSprite3D *>( pScene->Get3DObject()->FindObjectFromName("FlagBalloon") ); pFlagBal->SetDivnum( Math::Point2DI( 2, 1 ) ); #endif //CSprite *pPin = dynamic_cast<CSprite *>( pScene->Get2DObject()->FindObjectFromName("Pin") ); // //pPin->SetDivnum( Math::Point2DI(2, 1) ); // //CSprite3D *pEmotion = dynamic_cast<CSprite3D *>( pScene->Get3DObject()->FindObjectFromName("Emotion") ); // //pEmotion->SetDivnum( Math::Point2DI( 4, 1 ) ); // //CSprite3D *pFlagBal = dynamic_cast<CSprite3D *>( pScene->Get3DObject()->FindObjectFromName("FlagBalloon") ); // //pFlagBal->SetDivnum( Math::Point2DI( 2, 1 ) ); //--------------------------------------------------------------------------- //カメラ //--------------------------------------------------------------------------- CCamera *objCamMain = dynamic_cast<CCamera *>( m_pGameObj->FindObjectFromName("CamMain") ); CCamera *objCamSub = dynamic_cast<CCamera *>( m_pGameObj->FindObjectFromName("CamSub") ); /*カメラデバイスのセット*/ objCamMain->SetCamera( m_pSceneMgr[S_MAIN]->GetSceneMgr() ); objCamSub->SetCamera( m_pSceneMgr[S_SUB]->GetSceneMgr() ); /*プロジェクションのセット*/ objCamMain->SetProjection( 1.0f, 1000.0f, 45, m_pSceneMgr[S_MAIN]->GetRenderWidth(), m_pSceneMgr[S_MAIN]->GetRenderHeight() ); objCamSub->SetProjection( 1.0f, 1000.0f, 45, m_pSceneMgr[S_SUB]->GetRenderWidth(), m_pSceneMgr[S_SUB]->GetRenderHeight() ); //--------------------------------------------------------------------------- //物理エンジン初期化 //--------------------------------------------------------------------------- //pDynamicsWorld = Dynamics::CreateWorld( m_pSceneMgr[S_MAIN]->GetSceneMgr() ); // ///*ワールドにおける重力を設定*/ //pDynamicsWorld->SetGravity( Math::Vector3D( 0, -GRAVITY, 0 ) ); // ///*剛体モデルの生成*/ //m_p3DObj->CreateRigidModel( pDynamicsWorld ); //--------------------------------------------------------------------------- //モデル //--------------------------------------------------------------------------- #if defined( DEBUG_CHAT ) #else // ルートディレクトリに対して読み込むカレントディレクトリ設定 m_pApp->GetFileMgr()->SetCurrentPath( "Model" ); CField *objField = dynamic_cast<CField *>( m_p3DObj->FindObjectFromName("Field") ); CDebugLine *pDebugLine = dynamic_cast<CDebugLine *>( m_p3DObj->FindObjectFromName("DebugLine") ); /*読み込み*/ m_p3DObj->Load( m_pApp->GetRenderer() ); m_pApp->GetFileMgr()->SetCurrentPath("Shader"); CPlayer *objPlayer = dynamic_cast<CPlayer *>( pScene->Get3DObject()->FindObjectFromName("Player") ); pDebugLine->CreateLine( m_pApp->GetRenderer() ); //objPlayer->LoadShader( m_pGame->GetRenderer(), "UserShader.fx" ); pDebugLine->CreateActor( m_pSceneMgr[S_MAIN]->GetSceneMgr() ); #endif #if defined( DEBUG ) | (_DEBUG ) objField->SetCollisionLine( pDebugLine->GetLine() ); #elif defined( DEBUG_CHAT ) #endif //pDebugLine->CreateActor( m_pSceneMgr[S_SUB]->GetSceneMgr() ); #if defined( DEBUG_CHAT ) #else /*アクターの生成*/ for( int numScreen = 0;numScreen < S_MAX;++numScreen ) { m_p3DObj->CreateActor( numScreen, m_pSceneMgr[numScreen]->GetSceneMgr() ); objField->CreateActor( numScreen, m_pSceneMgr[numScreen]->GetSceneMgr() ); } #endif //--------------------------------------------------------------------------- //サウンド //--------------------------------------------------------------------------- m_pApp->GetFileMgr()->SetCurrentPath("Sound"); /*サウンドの読み込み*/ m_pSoundObj->LoadSound( m_pApp->GetCore() ); //--------------------------------------------------------------------------- //テクスチャ //--------------------------------------------------------------------------- m_pApp->GetFileMgr()->SetCurrentPath("Texture"); /*テクスチャの読み込み*/ m_p2DObj->Load( m_pApp->GetRenderer() ); CSprite *SkySpr = dynamic_cast<CSprite *>( pScene->Get2DObject()->FindObjectFromName("Cloud") ); for( int scenenum = 0;scenenum < S_MAX;++scenenum ) { m_pSceneMgr[scenenum]->CreateSkyDoom( SkySpr->GetTexture(), m_pApp->GetRenderer() ); } pScene->Get2DObject()->RemoveObject( SkySpr ); //--------------------------------------------------------------------------- //フォント //--------------------------------------------------------------------------- m_pApp->GetFileMgr()->SetCurrentPath("Font"); CFontSprite *pFontSpr = dynamic_cast<CFontSprite *>( m_pGameObj->FindObjectFromName("TitleFont") ); CFontSprite *pCommonFont = dynamic_cast<CFontSprite *>( m_pGameObj->FindObjectFromName("CommonFont") ); CFontSprite *pMissionFont = dynamic_cast<CFontSprite *>( m_pGameObj->FindObjectFromName("MissionFont") ); CFontSprite *pMenuFont = dynamic_cast<CFontSprite *>( m_pGameObj->FindObjectFromName("MenuFont") ); CFontSprite *pChatFont = dynamic_cast<CFontSprite *>( m_pGameObj->FindObjectFromName("ChatFont") ); CFontSprite *pNumFont = dynamic_cast<CFontSprite *>( m_pGameObj->FindObjectFromName("NumFont") ); CFontSprite *pMiContFont = dynamic_cast<CFontSprite *>( m_pGameObj->FindObjectFromName("ContentFont") ); CFontSprite *pMiContFont2 = dynamic_cast<CFontSprite *>( m_pGameObj->FindObjectFromName("ContentFont2") ); CFontSprite *pExpFont = dynamic_cast<CFontSprite *>( m_pGameObj->FindObjectFromName("ExplainFont") ); pFontSpr->Load( m_pApp->GetRenderer() ); pCommonFont->Load( m_pApp->GetRenderer() ); pMissionFont->Load( m_pApp->GetRenderer() ); pMenuFont->Load( m_pApp->GetRenderer() ); pChatFont->Load( m_pApp->GetRenderer() ); pNumFont->Load( m_pApp->GetRenderer() ); pMiContFont->Load( m_pApp->GetRenderer() ); pMiContFont2->Load( m_pApp->GetRenderer() ); pExpFont->Load( m_pApp->GetRenderer() ); //--------------------------------------------------------------------------- //テキスト読み込み //--------------------------------------------------------------------------- pResFile = m_pApp->GetFileMgr()->FileOpen("Text.txt"); Sint32 FileSize = pResFile->GetFileSize(); char *pTextBuff = new char[FileSize + 1]; pResFile->Read( pTextBuff, FileSize ); pTextBuff[FileSize] = '\0'; pResFile->Release(); pFontSpr->SetDrawString("PUSH START"); CSprite *objPopMenu = dynamic_cast<CSprite *>( m_p2DObj->FindObjectFromName("PopMenu") ); m_pGameObj->AppendObject( new CMenu( pMenuFont, objPopMenu ), "PopMenu", true ); //--------------------------------------------------------------------------- //ミッションの追加 //--------------------------------------------------------------------------- m_pApp->GetFileMgr()->SetCurrentPath("CSV"); pResFile = m_pApp->GetFileMgr()->FileOpen("mission.csv"); std::ifstream ifsMission( pResFile->GetNamePointer() ); SAFE_RELEASE( pResFile ); char MissionTemp[256]; ifsMission.getline( MissionTemp, 256 ); m_pApp->GetFileMgr()->SetCurrentPath("Font"); //ifs.open("mission.csv"); while( !ifsMission.eof() ) { char Temp[20]; static int count = 0; MissionData datMission; char TempMissionName[256]; char TempTargetName[256]; char TempChat[1024]; sprintf( Temp, "Mission%d.txt", count+1); pResFile = m_pApp->GetFileMgr()->FileOpen(Temp); ifstream ifs( pResFile->GetNamePointer() ); SAFE_RELEASE(pResFile); #if defined (DEBUG) | (_DEBUG) //ofstream out( Temp, ios::out ); // ////while( *pTextBuff != '\0') ////{ //// if( *pTextBuff != '\n' ) //// { //// out << pTextBuff; //// } //// //// pTextBuff += 1; //// //// ////} // // //out.close(); #endif while( !ifs.eof() ) { ifs >> TempChat; datMission.m_vecChat.push_back( TempChat ); } ifs.close(); sprintf( Temp, "MissionContent%d.txt", count+1 ); pResFile = m_pApp->GetFileMgr()->FileOpen(Temp); ifstream ifsContent( pResFile->GetNamePointer() ); char TempMiCont[256] = ""; //ifsContent.read( TempMiCont, pResFile->GetFileSize() ); SAFE_RELEASE( pResFile ); while( !ifsContent.eof() ) { ifsContent >> TempMiCont; datMission.m_vecMissionContent.push_back( TempMiCont ); } ifsContent.close(); ifsMission >> TempMissionName >> TempTargetName >> datMission.m_ClearPoint >> datMission.m_FilmNum >> datMission.m_LimitTime.Min >> datMission.m_LimitTime.Sec >> datMission.m_TimeBorder.Min >> datMission.m_TimeBorder.Sec >> datMission.m_TargetPosMin >> datMission.m_TargetPosMax >> datMission.m_DistanceMin >> datMission.m_DistanceMax ; datMission.m_MissionName = TempMissionName; datMission.m_TargetName = TempTargetName; CCharacter *objFlag = dynamic_cast<CCharacter *>( pScene->Get3DObject()->FindObjectFromName("Flag") ); float Scale = 4.0f; objFlag->SetScale( Math::Vector3D( Scale, Scale, Scale ) ); sprintf( Temp, "MissionFont%d", count+1 ); datMission.m_pFontSpr = dynamic_cast<CSprite *>( m_p2DObj->FindObjectFromName(Temp) ); sprintf( Temp, "Picture%d", count+1 ); datMission.m_pPhotoSpr = dynamic_cast<CSprite *>( m_p2DObj->FindObjectFromName(Temp) ); m_pMissionMgr->AppendMission( count, new CMission( dynamic_cast<CDraw3DObject *>( m_p3DObj->FindObjectFromName( datMission.m_TargetName ) ), datMission ) ); count++; } ifsMission.close(); #if defined( DEBUG_MAP_EDIT ) #elif defined( DEBUG_MAP_SEE) #else #endif //----------------------------------------------------------------- // 変更しないステート //----------------------------------------------------------------- m_pApp->SetTextureFilter(); m_IsFirstBoot = false; } return true; }
void Keyboard(unsigned char key, int x, int y) { { if (key == 'l' || key == 'L') { camera.HandlePosition(Camera_Speed, { 1,0,0 }); } if (key == 'j' || key == 'J') { camera.HandlePosition(-Camera_Speed, { 1,0,0 }); } if (key == 'i' || key == 'I') { camera.HandlePosition(Camera_Speed, { 0,1,0 }); } if (key == 'k' || key == 'K') { camera.HandlePosition(-Camera_Speed, { 0,1,0 }); } if (key == '1') { light_0 = 1 - light_0; } if (key == 'a') {; ambiant = max(0, ambiant - 0.1); } if (key == 'A') { ambiant = min(1, ambiant + 0.1); } if (key == 's') { specular = max(0, specular - 0.1); } if (key == 'S') { specular = min(1, specular + 0.1); } if (key == 'd') { diffuse = max(0, diffuse - 0.1); } if (key == 'D') { diffuse = min(1, diffuse + 0.1); } if (key == 'z' || key == 'Z') { is_normal = 1 - is_normal; pyramid[0].SwitchNormalizeMode(); pyramid[1].SwitchNormalizeMode(); } if (key == '+') { camera.HandleDistance(10); } if (key == '-') { camera.HandleDistance(-10); } if (key == 'r' || key == 'R') { camera.ResetPos(); } if (key == 'm' || key == 'M') { snow.push_front(Snow()); } } if (key == 'p' || key == 'P') { exit(0); } // Á¾·á
//============================================================================= //処理 //============================================================================= //[input] // pScene:設定するシーン //============================================================================= void CScene::Exec(CScene *pScene) { Renderer::IRender *pRender = pScene->GetAppDevice()->GetRenderer(); CSprite *pSpr = dynamic_cast<CSprite *>( m_p2DObj->FindObjectFromName("Loading") ); pSpr->SetDivnum( Math::Point2DI(6, 1) ); pScene->GetAppDevice()->GetRenderer()->Clear(); pScene->GetAppDevice()->GetRenderer()->Begin(); pSpr->Rendering(); //pScene->GetAppDevice()->GetRenderer()->DebugPrint( Math::Point2DI( 400, 300 ), CColor(255, 255, 255 ), "Npw Loading" ); pScene->GetAppDevice()->GetRenderer()->End(); pSpr->DrawAnimation( 6, 0 ); /*ロード終わってない*/ if( !pScene->GetLoadEndFlag() ) { static string Str = "Now Loading"; static int count = 0; count ++; if( count % 10 == 0 ) { Str += "."; } if( count >= 40 ) { count = 0; Str = "Now Loading"; } pRender->DrawText( Math::Point2DI( 590, 520 ), CColor(255, 255, 255 ), Str.c_str() ); } /*ロード終了*/ if( pScene->GetLoadEndFlag() ) { pSpr->SetVisibleFlag( false ); m_p3DObj->Init(); CCamera *objCamMain = dynamic_cast<CCamera *>( m_pGameObj->FindObjectFromName("CamMain") ); objCamMain->Init(); pSpr->Move(); /*キャラが画面外にいったら、次のシーンに*/ if( pSpr->GetPosition().x <= -100 ) { #if defined( DEBUG_MAP_EDIT ) m_eNextScene = SCENE_GAMEMAIN; #elif defined( DEBUG_MAP_SEE ) m_eNextScene = SCENE_DEMO; #elif defined( DEBUG_CHAT ) m_eNextScene = SCENE_CHAT; #endif pScene->SetSceneState( STATE_STANDBY ); pScene->ChangeScene( m_eNextScene ); } } }
void InitGL() // Inicializamos parametros { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Negro de fondo glEnable(GL_TEXTURE_2D); glShadeModel(GL_SMOOTH); //Para construir la figura comentar esto glLightfv(GL_LIGHT1, GL_POSITION, Position); glLightfv(GL_LIGHT1, GL_DIFFUSE, Diffuse); //glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, Position2); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); //glEnable(GL_LIGHT1); glEnable(GL_COLOR_MATERIAL); //Habilitar GlColor3f //glEnable(GL_CULL_FACE); //glCullFace(GL_BACK); //glPolygonMode(GL_BACK, GL_LINE); glClearDepth(1.0f); // Configuramos Depth Buffer glEnable(GL_DEPTH_TEST); // Habilitamos Depth Testing glDepthFunc(GL_LEQUAL); // Tipo de Depth Testing a realizar glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable(GL_AUTO_NORMAL); glEnable(GL_NORMALIZE); /* setup blending */ //glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Set The Blending Function For Translucency //glColor4f(1.0f, 1.0f, 1.0f, 0.5); rectoria._3dsLoad("rectoria/rectoria.3ds"); rectoria.LoadTextureImages(); rectoria.GLIniTextures(); rectoria.ReleaseTextureImages(); biblioteca._3dsLoad("biblioteca/biblioteca.3ds"); biblioteca.LoadTextureImages(); biblioteca.GLIniTextures(); biblioteca.ReleaseTextureImages(); //islas._3dsLoad("islas/islas.3ds"); //islas.LoadTextureImages(); //islas.GLIniTextures(); //islas.ReleaseTextureImages(); texturaPasto.LoadTGA("city/pasto01.tga"); texturaPasto.BuildGLTexture(); texturaPasto.ReleaseImage(); facultadD._3dsLoad("derecho3DS/derecho.3ds"); facultadD.LoadTextureImages(); facultadD.GLIniTextures(); facultadD.ReleaseTextureImages(); t_placasRectoria.LoadTGA("city/pasto01.tga"); t_placasRectoria.BuildGLTexture(); t_placasRectoria.ReleaseImage(); t_escalerasIslas.LoadTGA("cuadrosrectoria/texturaEsc.tga"); t_escalerasIslas.BuildGLTexture(); t_escalerasIslas.ReleaseImage(); quadratic = gluNewQuadric(); // Create A Pointer To The Quadric Object ( NEW ) gluQuadricNormals(quadratic, GLU_SMOOTH); // Create Smooth Normals ( NEW ) gluQuadricTexture(quadratic, GL_TRUE); // Create Texture Coords ( NEW ) objCamera.Position_Camera(0, 2.5f, 3, 0, 2.5f, 0, 0, 1, 0); }
void CNametags::DrawFromAim ( void ) { unsigned long ulCurrentTime = CClientTime::GetTime (); // Got any players that are not local? if ( m_pPlayerManager->Count () > 1 ) { // Grab the local player CClientPlayer* pLocalPlayer = m_pPlayerManager->GetLocalPlayer (); if ( pLocalPlayer ) { // Grab the current time and the camera unsigned long ulCurrentTime = CClientTime::GetTime (); CCamera* pCamera = g_pGame->GetCamera (); // Grab our controller state CControllerState State; g_pGame->GetPad ()->GetCurrentControllerState ( &State ); // Grab our current weapon slot. Use screen center if melee or none CVector vecStart; CVector vecTarget; eWeaponSlot eSlot = pLocalPlayer->GetCurrentWeaponSlot (); if ( eSlot == WEAPONSLOT_TYPE_UNARMED || eSlot == WEAPONSLOT_TYPE_MELEE || eSlot == WEAPONSLOT_TYPE_RIFLE || eSlot == WEAPONSLOT_TYPE_THROWN || eSlot == WEAPONSLOT_TYPE_SPECIAL || eSlot == WEAPONSLOT_TYPE_GIFT || eSlot == WEAPONSLOT_TYPE_PARACHUTE || eSlot == WEAPONSLOT_TYPE_DETONATOR ) { // Grab the active cam CCamera* pCamera = g_pGame->GetCamera (); CCam* pActive = pCamera->GetCam ( pCamera->GetActiveCam () ); // Grab the camera matrix CMatrix matCamera; pCamera->GetMatrix ( &matCamera ); vecStart = matCamera.vPos; // Range float fRange; if ( eSlot == WEAPONSLOT_TYPE_RIFLE && State.RightShoulder1 ) { fRange = SNIPER_AIM_VISIBLE_RANGE; } else { fRange = MELEE_VISIBLE_RANGE; } // Find the target position CVector vecFront = *pActive->GetFront (); vecFront.Normalize (); vecTarget = *pActive->GetSource () + vecFront * fRange; } else { // Grab the weapon and keysync state. If it exists and he holds Target down CWeapon* pPlayerWeapon = pLocalPlayer->GetWeapon (); if ( pPlayerWeapon && State.RightShoulder1 ) { // Grab the gun muzzle position CWeaponInfo* pCurrentWeaponInfo = pPlayerWeapon->GetInfo (); CVector vecGunMuzzle = *pCurrentWeaponInfo->GetFireOffset (); pLocalPlayer->GetTransformedBonePosition ( BONE_RIGHTWRIST, vecGunMuzzle ); // Grab the target point pCamera->Find3rdPersonCamTargetVector ( AIM_VISIBLE_RANGE, &vecGunMuzzle, &vecStart, &vecTarget ); } else { // Grab the active cam CCam* pActive = pCamera->GetCam ( pCamera->GetActiveCam () ); // Grab the camera matrix CMatrix matCamera; pCamera->GetMatrix ( &matCamera ); vecStart = matCamera.vPos; // Find the target position CVector vecFront = *pActive->GetFront (); vecFront.Normalize (); vecTarget = *pActive->GetSource () + vecFront * MELEE_VISIBLE_RANGE; } } // Ignore the local player for this pLocalPlayer->WorldIgnore ( true ); // Do the raycast CColPoint* pColPoint = NULL; CEntity* pEntity = NULL; g_pGame->GetWorld ()->ProcessLineOfSight ( &vecStart, &vecTarget, &pColPoint, &pEntity, true, true, true, true, true, true, false, true ); if ( pColPoint ) pColPoint->Destroy (); // Un-ignore the local player pLocalPlayer->WorldIgnore ( false ); // Did we find an entity? if ( pEntity ) { // Grab the CClientEntity belonging to this game_sa entity CClientEntity* pClientEntity = reinterpret_cast < CClientEntity* > ( pEntity->GetStoredPointer () ); if ( pClientEntity ) { // Is it a vehicle? Is it a ped? eClientEntityType EntityType = pClientEntity->GetType (); if ( EntityType == CCLIENTVEHICLE ) { CClientVehicle* pClientVehicle = static_cast < CClientVehicle* > ( pClientEntity ); // Set the current time as the last draw time for all players inside CClientPed* pPed; int i; for ( i = 0; i < 8; i++ ) { // Grab this seat's occupant and set its last nametag show time to now pPed = pClientVehicle->GetOccupant ( i ); if ( pPed && pPed->GetType () == CCLIENTPLAYER ) { static_cast < CClientPlayer* > ( pPed )->SetLastNametagShow ( ulCurrentTime ); } } } else if ( EntityType == CCLIENTPLAYER ) { // Grab the player this entity is CClientPlayer* pClientPlayer = static_cast < CClientPlayer* > ( pClientEntity ); if ( pClientPlayer ) { // Set now as the last time we had the cursor above him pClientPlayer->SetLastNametagShow ( ulCurrentTime ); } } } } // Grab the local player vehicle CClientVehicle* pLocalVehicle = pLocalPlayer->GetOccupiedVehicle (); // Draw the nametags we need to CClientPlayer* pPlayer; CClientStreamElement * pElement; list < CClientStreamElement* > ::const_iterator iter = m_pPlayerStreamer->ActiveElementsBegin (); for ( ; iter != m_pPlayerStreamer->ActiveElementsEnd (); iter++ ) { pElement = *iter; if ( !pElement->IsStreamedIn () ) continue; if ( pElement->GetType () != CCLIENTPLAYER ) continue; pPlayer = static_cast < CClientPlayer * > ( pElement ); if ( pPlayer->IsLocalPlayer () ) continue; // Is he in the same vehicle as the local player? if ( pLocalVehicle && pPlayer->GetOccupiedVehicle () == pLocalVehicle ) { pPlayer->SetLastNametagShow ( ulCurrentTime ); } // Can we show this player's nametag unsigned long ulLastNametagShow = pPlayer->GetLastNametagShow (); if ( ulLastNametagShow != 0 && ulCurrentTime <= ulLastNametagShow + NAMETAG_END_FADE_TIME ) { unsigned long ulLastNametagShow = pPlayer->GetLastNametagShow (); // Calculate the alpha modifier float fAlphaTimeModifier; if ( ulCurrentTime < ulLastNametagShow + NAMETAG_BEGIN_FADE_TIME ) { fAlphaTimeModifier = 1.0f; } else { fAlphaTimeModifier = 1.0f - ( ulCurrentTime - ulLastNametagShow - NAMETAG_BEGIN_FADE_TIME ) / 1000.0f; } // Calculate the alpha for the nametag unsigned char ucAlpha = static_cast < unsigned char > ( 180.0f * fAlphaTimeModifier ); // Draw it DrawTagForPlayer ( pPlayer, ucAlpha ); } } } } }
void display() { clock_t now_time = clock(); // std::cout << "now_time : " << now_time << std::endl; // std::cout << "update_time : " << update_time << std::endl; // std::cout << now_time - update_time << std::endl; //redraw time //std::cout << (double)(now_time - update_time) / (double)CLOCKS_PER_SEC << std::endl; //fps //std::cout << (float) CLOCKS_PER_SEC / (float) (now_time - update_time) << std::endl; //std::cout << "display" << std::endl; //Clear the color buffer glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); GLdouble ratio = 512.0/512.0; gluPerspective(60.0, ratio, 10.0, 100.0); Camera.Render(); //set the current drawing color to red glColor3f(1, 0, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(_CamPos.x, _CamPos.y, _CamPos.z, // eye x,y,z 0., 0., 0., // center x,y,z 0., 1., 0.); // Up direction //std::cout << Rotx << std::endl; glRotatef(Rotx, 1.0, 0.0, 0.0); glRotatef(Roty, 0.0, 1.0, 0.0); glRotatef(Rotz, 0.0, 0.0, 1.0); //start drawing triangles, each triangles takes 3 vertices //cout << "input delta : " << (double)(now_time - update_time) / (double)CLOCKS_PER_SEC << endl; //cout << "draw fps : " << (double)CLOCKS_PER_SEC / (double)(now_time - update_time)<< endl; //current_time_physics = glutGet(GLUT_ELAPSED_TIME); current_time_draw = glutGet(GLUT_ELAPSED_TIME); bool updated = false; while ((current_time_draw - prev_time_draw) < 15 || !updated) { current_time_physics = glutGet(GLUT_ELAPSED_TIME); current_time_draw = current_time_physics; if (current_time_physics - prev_time_physics > 7) { std::cout << "physics fps : " << 1000.0f/(float) (current_time_physics-prev_time_physics)<< std::endl; g_Flag->PositionUpdate((double)(current_time_physics-prev_time_physics) / 1000.0); prev_time_physics = current_time_physics; updated = true; } } std::cout << "draw fps : " << 1000.0f/(float) (current_time_draw-prev_time_draw)<< std::endl; g_Wind->Render(); g_Flag->Render((float) (current_time_draw-prev_time_draw) / 1000.0); prev_time_draw = current_time_draw; glFlush(); //swap the back and front buffers so we can see what we just drew glutSwapBuffers(); }
void Init(HWND hWnd) { g_hWnd = hWnd; // Assign the window handle to a global window handle GetClientRect(g_hWnd, &g_rRect); // Assign the windows rectangle to a global RECT InitializeOpenGL(g_rRect.right, g_rRect.bottom); // Init OpenGL with the global rect /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Initialize the camera position g_Camera.PositionCamera(0, 3.5f, 30, 0, 0, 0, 0, 1, 0); // Here we load the world from a .3ds file g_Load3DS.Import3DS(&g_World, FILE_NAME); // Go through all the materials for(int i = 0; i < g_World.numOfMaterials; i++) { // Check to see if there is a file name to load in this material if(strlen(g_World.pMaterials[i].strFile) > 0) { // Use the name of the texture file to load the bitmap, with a texture ID (i). // We pass in our global texture array, the name of the texture, and an ID to reference it. CreateTexture(g_Texture[i], g_World.pMaterials[i].strFile); } // Set the texture ID for this material g_World.pMaterials[i].texureId = i; } // The first thing that needs to happen before creating our octree is to find // the total width of the initial root node. Now we pass in our t3DModel object // to GetSceneDimensions(), instead of vertices and a vertex count, as done // in the last octree tutorials. This will store the initial root node cube width. g_Octree.GetSceneDimensions(&g_World); // Since our model structures stores multiple objects, we can't easily access the // total triangle count in the scene with out manually going through and counting the total. // This is what we do below. With the result, we pass this into our CreateNode() function. int TotalTriangleCount = g_Octree.GetSceneTriangleCount(&g_World); // To create the first node we need the world data, the total triangle count in the scene, // along with the initial root node center and width. This function will then recursively // subdivide the rest of the world, according to the global restrictions. g_Octree.CreateNode(&g_World, TotalTriangleCount, g_Octree.GetCenter(), g_Octree.GetWidth()); // The octree should be created by now. To better increase our efficiency we use display // lists for every end node. This way, we just have to call a display list ID to draw // a node, verses the slow loops we normal had. Vertex arrays are also used to optimize // our rendering of the octree. // Below we get the display list base ID and store it in the root node. This should return 1 // since we don't use display lists anywhere before this. Notice that we use our global // variable that stores our end node count to pass in the total amount of list ID's needed. // If you are unfamiliar with displays, basically what you do is section off a certain // amount of ID's, and then you are returns a base pointer to the start of those ID's. // You can use the ID's from the base pointer to the base pointer ID + the number of // ID's that were saved off for that base pointer. Each of the ID's correspond to a // bunch of OpenGL commands. That means that each end node has it's own ID that // corresponds to a bunch of OpenGL commands. So, for instance, if pass in a bunch // of vertices to OpenGL, we can assign this action to a display list. That way we // just call a display list ID to perform that action. Think of it as a function. // You just need to call a function to do a bunch of tasks, which eliminates extra // code, and also is saved on the video card for faster processing. g_Octree.SetDisplayListID( glGenLists(g_EndNodeCount) ); // Now we go through every single end node and create a display list for them all. // That way, when we draw the end node, we just use it's display list ID to render // the node, instead of looping through all the objects and manually give the verts to opengl. // The parameters for this function is the node (starting with the root node), // the world data and current display list base ID. The base ID is stored in the root // node's ID, so we just pass that in. The reason we do this is because, if you create // other display lists before you create the octree, you don't want to assume the octree // ID's go from 1 to the end node count. By passing in the base ID, we then will add // this ID to other nodes. Right now, when they are created they are assigned the // end node count at the time upon creating them. This will make more sense when looking // at the octree code. g_Octree.CreateDisplayList(&g_Octree, &g_World, g_Octree.GetDisplayListID()); // Hide our cursor since we are using first person camera mode ShowCursor(FALSE); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * glEnable(GL_LIGHT0); // Turn on a light with defaults set glEnable(GL_LIGHTING); // Turn on lighting glEnable(GL_COLOR_MATERIAL); // Allow color }
//------------------------------------------------------------------------ void CView::Update(float frameTime,bool isActive) { //FIXME:some cameras may need to be updated always if (!isActive) return; CGameObject * pLinkedTo = GetLinkedGameObject(); if (pLinkedTo && !pLinkedTo->CanUpdateView()) pLinkedTo = NULL; IEntity* pEntity = pLinkedTo ? 0 : GetLinkedEntity(); if (pLinkedTo || pEntity) { m_viewParams.SaveLast(); CCamera *pSysCam = &m_pSystem->GetViewCamera(); //process screen shaking ProcessShaking(frameTime); //FIXME:to let the updateView implementation use the correct shakeVector m_viewParams.currentShakeShift = m_viewParams.rotation * m_viewParams.currentShakeShift; m_viewParams.frameTime=frameTime; //update view position/rotation if (pLinkedTo) { pLinkedTo->UpdateView(m_viewParams); if (!m_viewParams.position.IsValid()) { m_viewParams.position = m_viewParams.GetPositionLast(); CRY_ASSERT_MESSAGE(0, "Camera position is invalid, reverting to old position"); } if (!m_viewParams.rotation.IsValid()) { m_viewParams.rotation = m_viewParams.GetRotationLast(); CRY_ASSERT_MESSAGE(0, "Camera rotation is invalid, reverting to old rotation"); } } else { Matrix34 mat = pEntity->GetWorldTM(); mat.OrthonormalizeFast(); m_viewParams.position = mat.GetTranslation(); m_viewParams.rotation = Quat(mat); } ApplyFrameAdditiveAngles(m_viewParams.rotation); if (pLinkedTo) { pLinkedTo->PostUpdateView(m_viewParams); } float fNearZ = gEnv->pGame->GetIGameFramework()->GetIViewSystem()->GetDefaultZNear(); //see if the view have to use a custom near clipping plane float nearPlane = (m_viewParams.nearplane > 0.01f)?(m_viewParams.nearplane):(fNearZ/*pSysCam->GetNearPlane()*/); float farPlane = gEnv->p3DEngine->GetMaxViewDistance(); float fov = m_viewParams.fov < 0.001 ? DEFAULT_FOV : m_viewParams.fov; m_camera.SetFrustum(pSysCam->GetViewSurfaceX(),pSysCam->GetViewSurfaceZ(),fov,nearPlane,farPlane, pSysCam->GetPixelAspectRatio()); //TODO: (14, 06, 2010, "the player view should always get updated, this due to the hud being visable, without shocking, in cutscenes - todo is to see if we can optimise this code"); IActor * pActor = gEnv->pGame->GetIGameFramework()->GetClientActor(); if (pActor) { CGameObject * linkToObj = (CGameObject*)pActor->GetEntity()->GetProxy( ENTITY_PROXY_USER ); if (linkToObj && linkToObj != pLinkedTo) { linkToObj->PostUpdateView(m_viewParams); } } //apply shake & set the view matrix m_viewParams.rotation *= m_viewParams.currentShakeQuat; m_viewParams.rotation.NormalizeSafe(); m_viewParams.position += m_viewParams.currentShakeShift; // Camera space Rendering calculations on Entity if(pLinkedTo) { IEntity* pLinkedToEntity = pLinkedTo->GetEntity(); if(pLinkedToEntity) { const int slotIndex = 0; uint32 entityFlags = pLinkedToEntity->GetSlotFlags(slotIndex); if(entityFlags & ENTITY_SLOT_RENDER_NEAREST) { // Get camera pos relative to entity const Vec3 cameraLocalPos = m_viewParams.position; // Set entity's camera space position const Vec3 cameraSpacePos(-cameraLocalPos * m_viewParams.rotation); pLinkedToEntity->SetSlotCameraSpacePos(slotIndex,cameraSpacePos); // Add world pos onto camera local pos m_viewParams.position = pLinkedToEntity->GetWorldPos() + cameraLocalPos; } } } // Blending between cameras needs to happen after Camera space rendering calculations have been applied // so that the m_viewParams.position is in World Space again m_viewParams.UpdateBlending(frameTime); Matrix34 viewMtx(m_viewParams.rotation); viewMtx.SetTranslation(m_viewParams.position); m_camera.SetMatrix(viewMtx); } else { m_linkedTo = 0; CCryAction *pCryAction = CCryAction::GetCryAction(); if (!pCryAction->IsGameSessionMigrating()) // If we're host migrating, leave the camera where it was { // Check if we're leaving a game mid way through - if we are then stop the camera from being reset for a frame or 2 before the unload happens if (!pCryAction->GetIGameSessionHandler()->IsMidGameLeaving()) { m_camera.SetPosition(Vec3(1,1,1)); } } } }
bool CEnemyManager::Init(const char* _pcFile) { CXMLTreeNode FileXML; FileXML.LoadFile(_pcFile); //CXMLTreeNode Enemies = fileXML(0); { CXMLTreeNode Templates = FileXML["templates"]; int iNumChildren = Templates.GetNumChildren(); for(int i = 0; i < iNumChildren; i++) { CXMLTreeNode EnemyTemplate = Templates(i); const char* pcId = EnemyTemplate.GetPszProperty("id"); const char* pcMesh = EnemyTemplate.GetPszProperty("mesh"); CEnemyResource* pResource = new CEnemyResource(); std::string szId = pcId; //TODO comprovar errors pResource->Init(pcId,pcMesh); m_Resources[szId] = pResource; } } { Vect3f Default(0,0,0); CXMLTreeNode Instances = FileXML["instances"]; int iNumChildren = Instances.GetNumChildren(); for(int i = 0; i < iNumChildren; i++) { CXMLTreeNode EnemyInstance = Instances(i); const char* pcType = EnemyInstance.GetPszProperty("type"); const Vect3f vPos = EnemyInstance.GetVect3fProperty("pos",Default); const Vect3f vRot = EnemyInstance.GetVect3fProperty("rot",Default); const float fMoveSpeed = EnemyInstance.GetFloatProperty("move_speed"); const float fRotateSpeed = EnemyInstance.GetFloatProperty("rotate_speed"); const float fHealth = EnemyInstance.GetFloatProperty("health"); if(strcmp(pcType,"PATROLLER") == 0) { const char* pcPaths = EnemyInstance.GetPszProperty("paths"); CPatroller* pPatroller = new CPatroller(); pPatroller->Init(vPos,vRot,fMoveSpeed,fRotateSpeed,fHealth,pcPaths); m_Instances.push_back(pPatroller); } else if(strcmp(pcType,"SNIPER") == 0) { float fAimDistance = EnemyInstance.GetFloatProperty("aim_distance"); CSniper* pSniper = new CSniper(); pSniper->Init(vPos,vRot,fMoveSpeed,fRotateSpeed,fHealth,fAimDistance); m_Instances.push_back(pSniper); } else if(strcmp(pcType,"TURRET") == 0) { Vect3f vMaxAngle = EnemyInstance.GetVect3fProperty("max_angle",Default); Vect3f vMinAngle = EnemyInstance.GetVect3fProperty("min_angle",Default); CTurret* pTurret = new CTurret(); pTurret->Init(vPos,vRot,fMoveSpeed,fRotateSpeed,fHealth,vMaxAngle,vMinAngle); m_Instances.push_back(pTurret); } else if(strcmp(pcType,"CAMERA") == 0) { Vect3f vMaxAngle = EnemyInstance.GetVect3fProperty("max_angle",Default); Vect3f vMinAngle = EnemyInstance.GetVect3fProperty("min_angle",Default); CCamera* pCamera = new CCamera(); pCamera->Init(vPos,vRot,fMoveSpeed,fRotateSpeed,fHealth,vMaxAngle,vMinAngle); m_Instances.push_back(pCamera); } else { //TODO errors } } } return true; }
virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { switch (event) { case eFE_Initialize: break; case eFE_Activate: IGameFramework* pGameFramework = gEnv->pGame->GetIGameFramework(); if(IsPortActive(pActInfo, EIP_Cast)) { // setup ray + optionally skip 1 entity ray_hit rayHit; static const float maxRayDist = 100.f; const unsigned int flags = rwi_stop_at_pierceable|rwi_colltype_any; IPhysicalEntity *skipList[1]; int skipCount = 0; IEntity* skipEntity = gEnv->pEntitySystem->GetEntity(GetPortEntityId(pActInfo, EIP_SkipEntity)); if(skipEntity) { skipList[0] = skipEntity->GetPhysics(); skipCount = 1; } Vec3 rayPos = GetPortVec3(pActInfo, EIP_RayPos); Vec3 rayDir = GetPortVec3(pActInfo, EIP_RayDir); // Check if the ray hits an entity if(gEnv->pSystem->GetIPhysicalWorld()->RayWorldIntersection(rayPos, rayDir * 100, ent_all, flags, &rayHit, 1, skipList, skipCount)) { int type = rayHit.pCollider->GetiForeignData(); if (type == PHYS_FOREIGN_ID_ENTITY) { IEntity* pEntity = (IEntity*)rayHit.pCollider->GetForeignData(PHYS_FOREIGN_ID_ENTITY); IEntityRenderProxy* pRenderProxy = pEntity ? (IEntityRenderProxy*)pEntity->GetProxy(ENTITY_PROXY_RENDER) : 0; // Get the renderproxy, and use it to check if the material is a DynTex, and get the UIElement if so if(pRenderProxy) { IRenderNode *pRenderNode = pRenderProxy->GetRenderNode(); IMaterial* pMaterial = pRenderProxy->GetRenderMaterial(); SEfResTexture* texture = 0; if(pMaterial && pMaterial->GetShaderItem().m_pShaderResources) texture= pMaterial->GetShaderItem().m_pShaderResources->GetTexture(EFTT_DIFFUSE); IUIElement* pElement = texture ? gEnv->pFlashUI->GetUIElementByInstanceStr(texture->m_Name) : 0; if(pElement && pRenderNode) { int m_dynTexGeomSlot = 0; IStatObj* pObj = pRenderNode->GetEntityStatObj(m_dynTexGeomSlot); // result bool hasHit = false; Vec2 uv0, uv1, uv2; Vec3 p0, p1, p2; Vec3 hitpos; // calculate ray dir CCamera cam = gEnv->pRenderer->GetCamera(); if (pEntity->GetSlotFlags(m_dynTexGeomSlot) & ENTITY_SLOT_RENDER_NEAREST) { ICVar *r_drawnearfov = gEnv->pConsole->GetCVar("r_DrawNearFoV"); assert(r_drawnearfov); cam.SetFrustum(cam.GetViewSurfaceX(),cam.GetViewSurfaceZ(),DEG2RAD(r_drawnearfov->GetFVal()),cam.GetNearPlane(),cam.GetFarPlane(), cam.GetPixelAspectRatio()); } Vec3 vPos0 = rayPos; Vec3 vPos1 = rayPos + rayDir; // translate into object space const Matrix34 m = pEntity->GetWorldTM().GetInverted(); vPos0 = m * vPos0; vPos1 = m * vPos1; // walk through all sub objects const int objCount = pObj->GetSubObjectCount(); for (int obj = 0; obj <= objCount && !hasHit; ++obj) { Vec3 vP0, vP1; IStatObj* pSubObj = NULL; if (obj == objCount) { vP0 = vPos0; vP1 = vPos1; pSubObj = pObj; } else { IStatObj::SSubObject* pSub = pObj->GetSubObject(obj); const Matrix34 mm = pSub->tm.GetInverted(); vP0 = mm * vPos0; vP1 = mm * vPos1; pSubObj = pSub->pStatObj; } IRenderMesh* pMesh = pSubObj ? pSubObj->GetRenderMesh() : NULL; if (pMesh) { const Ray ray(vP0, (vP1-vP0).GetNormalized() * maxRayDist); hasHit = RayIntersectMesh(pMesh, pMaterial, pElement, ray, hitpos, p0, p1, p2, uv0, uv1, uv2); } } // skip if not hit if (!hasHit) { ActivateOutput(pActInfo, EOP_Failed, 1); return; } // calculate vectors from hitpos to vertices p0, p1 and p2: const Vec3 v0 = p0-hitpos; const Vec3 v1 = p1-hitpos; const Vec3 v2 = p2-hitpos; // calculate factors const float h = (p0-p1).Cross(p0-p2).GetLength(); const float f0 = v1.Cross(v2).GetLength() / h; const float f1 = v2.Cross(v0).GetLength() / h; const float f2 = v0.Cross(v1).GetLength() / h; // find the uv corresponding to hitpos Vec3 uv = uv0 * f0 + uv1 * f1 + uv2 * f2; // translate to flash space int x, y, width, height; float aspect; pElement->GetFlashPlayer()->GetViewport(x, y, width, height, aspect); int iX = int_round(uv.x * (float)width); int iY = int_round(uv.y * (float)height); // call the function provided if it is present in the UIElement description string funcName = GetPortString(pActInfo, EIP_CallFunction); const SUIEventDesc* eventDesc = pElement->GetFunctionDesc(funcName); if(eventDesc) { SUIArguments arg; arg.AddArgument(iX); arg.AddArgument(iY); pElement->CallFunction(eventDesc->sName, arg); } ActivateOutput(pActInfo, EOP_Success, 1); } } } } ActivateOutput(pActInfo, EOP_Failed, 1); } break; } }
void CSkyBox::DrawSky( Vector3f vSunDir, bool bReflection) { #if 0 if( !m_bSkyLoaded ) return; m_pShader->Enable(); glDepthRange(1.0, 1.0); GetGLStateSaver()->Enable(GL_DEPTH_TEST); GetGLStateSaver()->DepthFunc(GL_EQUAL); glDepthMask( GL_FALSE ); GetGLStateSaver()->Enable( GL_TEXTURE_2D ); GetMVStack().PushMatrix(); Vector3f vCamPos = g_RenderInterf->GetRenderer()->GetActiveCam()->GetAbsPos(); if( bReflection ) vCamPos.y = -vCamPos.y + g_RenderInterf->GetRenderer()->GetWaterHeight() * 2.0f; GetMVStack().Translate( vCamPos ); GetShaderManager()->GetActiveShader()->UpdateMatrices(); float d = 1000.0f; //Skybox vertexes: float verts[] = { //Right Face 1.0f, 1.0f, d, d, -d, //Top Left 1.0f, 0.0f, d, -d, -d, //Bottom Left 0.0f, 0.0f, d, -d, d, //Bottom Right 0.0f, 1.0f, d, d, d, //Top Right //Left Face 1.0f, 1.0f, -d, d, d, //Top Left 1.0f, 0.0f, -d, -d, d, //Bottom Left 0.0f, 0.0f, -d, -d, -d, //Bottom Right 0.0f, 1.0f, -d, d, -d, //Top Right //Up Face 0.0f, 1.0f, -d, d, d, //Top Left 0.0f, 0.0f, -d, d, -d, //Bottom Left 1.0f, 0.0f, d, d, -d, //Bottom Right 1.0f, 1.0f, d, d, d, //Top Right //Down Face 1.0f, 1.0f, -d, -d, -d, //Top Left 1.0f, 0.0f, -d, -d, d, //Bottom Left 0.0f, 0.0f, d, -d, d, //Bottom Right 0.0f, 1.0f, d, -d, -d, //Top Right //Back Face 1.0f, 1.0f, d, d, d, //Top Left 1.0f, 0.0f, d, -d, d, //Bottom Left 0.0f, 0.0f, -d, -d, d, //Bottom Right 0.0f, 1.0f, -d, d, d, //Top Right //Front Face 1.0f, 1.0f,-d, d, -d, //Top Left 1.0f, 0.0f, -d, -d, -d, //Bottom Left 0.0f, 0.0f, d, -d, -d, //Bottom Right 0.0f, 1.0f, d, d, -d, //Top Right }; rglPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); init_vertexbuffer_vars_uvcoord_pos( verts ); for( int i = 0; i < 6; i++ ) { glBindTexture( GL_TEXTURE_2D, m_SkyTexs[i].index ); glDrawArrays( GL_QUADS, i*4, 4 ); } rglPopClientAttrib(); GetMVStack().PopMatrix(); glDepthMask( GL_TRUE ); //Re-Enable Z-Buffer GetGLStateSaver()->DepthFunc(GL_LESS); glDepthRange(0.0, 1.0); #else if( !m_bSkyLoaded ) return; m_pShaderSky->Enable(); m_pShaderSky->SetBrightness(render_sky_brightness.GetFloat()); glDepthRange(1.0, 1.0); GetGLStateSaver()->Enable(GL_DEPTH_TEST); GetGLStateSaver()->DepthFunc(GL_EQUAL); glDepthMask( GL_FALSE ); GetGLStateSaver()->Enable( GL_TEXTURE_2D ); CCamera *cam = g_RenderInterf->GetRenderer()->GetActiveCam(); GetMVStack().PushMatrix(); GetMVStack().Translate( cam->GetAbsPos() ); //GetMVStack().Rotate(cam->GetAbsAngles().GetConjugate()); m_pShaderSky->UpdateMatrices(); float d = 1000.0f; //Skybox vertexes: float verts[] = { //Right Face d, d, -d, //Top Left d, -d, -d, //Bottom Left d, -d, d, //Bottom Right d, d, d, //Top Right //Left Face -d, d, d, //Top Left -d, -d, d, //Bottom Left -d, -d, -d, //Bottom Right -d, d, -d, //Top Right //Up Face -d, d, d, //Top Left -d, d, -d, //Bottom Left d, d, -d, //Bottom Right d, d, d, //Top Right //Down Face -d, -d, -d, //Top Left -d, -d, d, //Bottom Left d, -d, d, //Bottom Right d, -d, -d, //Top Right //Back Face d, d, d, //Top Left d, -d, d, //Bottom Left -d, -d, d, //Bottom Right -d, d, d, //Top Right //Front Face -d, d, -d, //Top Left -d, -d, -d, //Bottom Left d, -d, -d, //Bottom Right d, d, -d, //Top Right }; rglPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); GetShaderManager()->InitVertexbufferVars(VBF_POS, verts); GetGLStateSaver()->ActiveTexture( GL_TEXTURE0 ); GetGLStateSaver()->Enable(GL_TEXTURE_CUBE_MAP); glBindTexture(GL_TEXTURE_CUBE_MAP, m_iCubeMapTex); glDrawArrays(GL_QUADS, 0, 6*4); rglPopClientAttrib(); GetMVStack().PopMatrix(); GetGLStateSaver()->Disable(GL_TEXTURE_CUBE_MAP); glDepthMask( GL_TRUE ); //Re-Enable Z-Buffer GetGLStateSaver()->DepthFunc(GL_LESS); glDepthRange(0.0, 1.0); #endif }
// À©µµ¿ì Ãâ·Â ÇÔ¼ö GLvoid drawScene(GLvoid) { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // ¹ÙÅÁ»ö ÁöÁ¤ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // ¼³Á¤µÈ »öÀ¸·Î †Ã¼¸¦ Ä¥Çϱâ // »ö»ó ÁöÁ¤ÇÏ°í »ç°¢Çü ±×¸®±â glEnable(GL_DEPTH_TEST); if(!orthomode) camera.Rander(); glColor4f(1.0, 1.0, 1.0, 1.0f); glPushMatrix(); { if (orthomode) { glLoadIdentity(); gluLookAt(0, 0, 0, 0, 0, -1, 0, 1, 0); } DrawAxis(); //////////////////<¹Ù´Ú>//////////////////// DrawFloor(); for (int x = 0; x <= (index) / 3.0; ++x) { glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[x * 3][0]); glEnable(GL_MAP1_VERTEX_3); glLineWidth(1.0); glBegin(GL_LINE_STRIP); for (int i = 0; i <= 30; i++) glEvalCoord1f((GLfloat)i / 30.0); glEnd(); glDisable(GL_MAP1_VERTEX_3); } glPointSize(5.0); glColor3f(0.0, 0.0, 1.0); glBegin(GL_POINTS); for (int i = 0; i < index; i++) glVertex3fv(&ctrlpoints[i][0]); glEnd(); for (int x = 0; x <= (index) / 3.0; ++x) { glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &road[x * 3][0]); glEnable(GL_MAP1_VERTEX_3); glLineWidth(12); glBegin(GL_LINE_STRIP); for (int i = 0; i <= 30; i++) glEvalCoord1f((GLfloat)i / 30.0); glEnd(); glDisable(GL_MAP1_VERTEX_3); } glLineWidth(1); glColor4f(1.0, 1.0, 1.0, 1.0); glutWireCube(floor_size * 2); gate.Rander(); squaretree.Rander(); roundtree.Rander(); elevator.Rander(); cone.Rander(); } glPopMatrix();
void display(void) { glClearColor(1.0, 1.0, 1.0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //clear the buffers glLoadIdentity(); myView.look();//camera ///* GLfloat lightColor1[] = {1.0f, 1.0f, 1.0f, 1.0f };//0.0f, 0.0f, -8.0f GLfloat lightPos1[] = {-80, 30, 0.0,1.0}; glLightfv(GL_LIGHT2, GL_DIFFUSE, lightColor1); glMaterialf(GL_LIGHT2,GL_SHININESS,4.0); glLightfv(GL_LIGHT2, GL_POSITION, lightPos1); glPushMatrix(); drawSceneTerra(_terrainRumput, 0.3f, 0.9f, 0.0f); glPopMatrix(); glPushMatrix(); drawSceneTerra(_terrainTanah, 0.7f, 0.2f, 0.1f); glPopMatrix(); glPushMatrix(); drawSceneTerra(_terrainAir, 0.0f, 0.2f, 0.5f); glPopMatrix();//*/ glPushMatrix(); glTranslatef(0.0,-10.0,-90.0); allmodel(); glPopMatrix(); glPushMatrix(); glTranslatef(-100.0,-10.0,0); glScalef(30,40,30); lampuvila(); glPopMatrix(); glPushMatrix(); pepohonan(); glPopMatrix(); glPushMatrix(); glTranslatef(-250,-20,-185); //glScalef(500,500,500); glPushMatrix(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,langit); //glColor3f(0,0,0); glBegin(GL_QUADS); glTexCoord2f(0,0);glVertex3f(0,0,0); glTexCoord2f(1,0);glVertex3f(500,0,0); glTexCoord2f(1,1);glVertex3f(500,250,0); glTexCoord2f(0,1);glVertex3f(0,250,0); glEnd(); glDisable(GL_TEXTURE_2D); glPopMatrix(); glPopMatrix(); glPushMatrix(); glRotatef(180,0.0,1.0,0.0); glTranslatef(-250,-20,-185); //glScalef(500,500,500); glPushMatrix(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,langit); glColor3f(0,0,0); glBegin(GL_QUADS); glTexCoord2f(0,0);glVertex3f(0,0,0); glTexCoord2f(1,0);glVertex3f(500,0,0); glTexCoord2f(1,1);glVertex3f(500,250,0); glTexCoord2f(0,1);glVertex3f(0,250,0); glEnd(); glDisable(GL_TEXTURE_2D); glPopMatrix(); glPopMatrix(); glPushMatrix(); glRotatef(90,0.0,1.0,0.0); glTranslatef(-250,-20,-185); //glScalef(500,500,500); glPushMatrix(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,langit); glColor3f(0,0,0); glBegin(GL_QUADS); glTexCoord2f(0,0);glVertex3f(0,0,0); glTexCoord2f(1,0);glVertex3f(500,0,0); glTexCoord2f(1,1);glVertex3f(500,250,0); glTexCoord2f(0,1);glVertex3f(0,250,0); glEnd(); glDisable(GL_TEXTURE_2D); glPopMatrix(); glPopMatrix(); glPushMatrix(); glRotatef(270,0.0,1.0,0.0); glTranslatef(-250,-20,-185); //glScalef(500,500,500); glPushMatrix(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,langit); glColor3f(0,0,0); glBegin(GL_QUADS); glTexCoord2f(0,0);glVertex3f(0,0,0); glTexCoord2f(1,0);glVertex3f(500,0,0); glTexCoord2f(1,1);glVertex3f(500,250,0); glTexCoord2f(0,1);glVertex3f(0,250,0); glEnd(); glDisable(GL_TEXTURE_2D); glPopMatrix(); glPopMatrix(); glPushMatrix(); glRotatef(90,1.0,0.0,0.0); glTranslatef(-180,-190,-190); //glScalef(500,500,500); glPushMatrix(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,langit); glColor3f(0,0,0); glBegin(GL_QUADS); glTexCoord2f(0,0);glVertex3f(0,0,0); glTexCoord2f(1,0);glVertex3f(500,0,0); glTexCoord2f(1,1);glVertex3f(500,500,0); glTexCoord2f(0,1);glVertex3f(0,500,0); glEnd(); glDisable(GL_TEXTURE_2D); glPopMatrix(); glPopMatrix(); glutSwapBuffers(); glFlush(); }
CCamera* CViacamController::SetUpCamera() { CCamera* cam; int numDevices; int camId= -1; // Load app local data ReadAppData(wxConfigBase::Get()); numDevices= CCameraEnum::GetNumDevices (); if (numDevices== 0) { wxMessageDialog errorMsg (NULL, _("Not detected any camera. Aborting"), _T("Enable Viacam"), wxOK | wxICON_ERROR); errorMsg.ShowModal(); return NULL; } // Try to find previously used camera if (m_cameraName.Length()> 0) { for (camId= 0; camId< numDevices; camId++) if (wxString(CCameraEnum::GetDeviceName (camId), wxConvLibc)== m_cameraName) break; if (camId== numDevices) camId= -1; // Not found } // Show selection dialog when needed if (camId== -1) { if(numDevices > 1) { wxArrayString strArray; for (camId= 0; camId< numDevices; camId++) strArray.Add (wxString(CCameraEnum::GetDeviceName (camId), wxConvLibc)); wxSingleChoiceDialog choiceDlg(NULL, _("Choose the camera to use"), _T("Enable Viacam"), strArray, NULL, wxDEFAULT_DIALOG_STYLE | wxOK | wxCANCEL | wxCENTRE); if (choiceDlg.ShowModal ()!= wxID_OK) return NULL; camId= choiceDlg.GetSelection(); m_cameraName= choiceDlg.GetStringSelection (); } else { camId= 0; m_cameraName= wxString(CCameraEnum::GetDeviceName (camId), wxConvLibc); } } cam= CCameraEnum::GetCamera(camId); if (!cam) return NULL; cam->SetHorizontalFlip (true); // Try to open the camera to ensure it works if (!cam->Open ()) { wxMessageDialog errorMsg (NULL, _("Can not initialize the camera.\nPerhaps is being used by other application."), _T("Enable Viacam"), wxOK | wxICON_ERROR); errorMsg.ShowModal(); delete cam; cam= NULL; ChangeCamera(); } else cam->Close(); WriteAppData(wxConfigBase::Get()); wxConfigBase::Get()->Flush(); return cam; }
void Display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); //Load a new modelview matrix -> we can apply new transformations //Update the scene: long unsigned int iNowTime = timeGetTime(); float timePassed = float(iNowTime-g_iLastRenderTime)/1000.0f; //divide by 1000 g_ParticleSystem1.UpdateSystem(timePassed); g_ParticleSystem2.UpdateSystem(timePassed); g_ParticleSystem3.UpdateSystem(timePassed); g_ParticleSystem4.UpdateSystem(timePassed); g_ParticleSystem5.UpdateSystem(timePassed); g_ParticleSystem6.UpdateSystem(timePassed); g_iLastRenderTime = iNowTime; //render everything: g_Camera.Render(); //render an opaque quadrangle: (if you want to see how to do this...) /* glEnable(GL_DEPTH_TEST); glDisable(GL_TEXTURE_2D); glColor3f(1.0f,0.0,1.0f); glBegin(GL_POLYGON); glVertex3f(0.0f,0.0f,0.0f); glVertex3f(1.0f,0.0f,0.0f); glVertex3f(1.0f,1.0f,0.0f); glVertex3f(0.0f,1.0f,0.0f); glEnd(); */ //render the nets, so switch off blending and texturing: glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); //enable depth testing (and z-buffer-writing) glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); GLfloat size = 2.0; GLint LinesX = 30; GLint LinesZ = 30; glColor3f(1.0,0.0,0.0); glPushMatrix(); glTranslatef(0.0,0.0 ,0.0); DrawNet(size,LinesX,LinesZ); glTranslatef(0.0,size,0.0); DrawNet(size,LinesX,LinesZ); glPopMatrix(); //Render system 2 first, it's not textured: glEnable(GL_BLEND); glDepthMask(GL_FALSE); glEnable(GL_DEPTH_TEST); //Calculate the point size depending from the camera's distance to the emitter: //(in order to be 100% exact we would have to pass the camera position to the //particles' render function. This method would then have to calculate the point size for each particle!) float zDist = g_Camera.GetPosition().z - g_ParticleSystem2.m_EmitterPosition.z; float xDist = g_Camera.GetPosition().x - g_ParticleSystem2.m_EmitterPosition.x; float CamDistToEmitter = sqrt(SQR(zDist)+SQR(xDist)); if (CamDistToEmitter < 0.2f) //avoid too big particles CamDistToEmitter = 0.2f; glPointSize(1.0f/CamDistToEmitter); g_ParticleSystem2.Render(); //Now enable texturing and render the other particle systems: glEnable(GL_TEXTURE_2D); g_ParticleSystem1.Render(); g_ParticleSystem3.Render(); g_ParticleSystem4.Render(); g_ParticleSystem5.Render(); g_ParticleSystem6.Render(); glDepthMask(GL_TRUE); glFlush(); //Finish rendering glutSwapBuffers(); //Swap the buffers ->make the result of rendering visible }
void ApplyShadowMaps (short nStartSeg, fix nEyeOffset, int nWindow) { static float mTexBiasf [] = { 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f}; static float mPlanef [] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; static GLenum nTexCoord [] = {GL_S, GL_T, GL_R, GL_Q}; CFloatMatrix mProjection; CFloatMatrix mModelView; int i; CCamera *cameraP; #if 1 OglActiveTexture (GL_TEXTURE0, 0); glEnable (GL_TEXTURE_2D); glEnable (GL_TEXTURE_GEN_S); glEnable (GL_TEXTURE_GEN_T); glEnable (GL_TEXTURE_GEN_R); glEnable (GL_TEXTURE_GEN_Q); for (i = 0; i < 4; i++) glTexGeni (nTexCoord [i], GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); for (i = 0; i < 4; i++) glTexGenfv (nTexCoord [i], GL_EYE_PLANE, mPlanef + 4 * i); glGetFloatv (GL_PROJECTION_MATRIX, mProjection.Vec ()); glMatrixMode (GL_TEXTURE); for (i = 0, cameraP = gameData.render.shadows.shadowMaps; i < 1/*gameData.render.shadows.nShadowMaps*/; i++) { glBindTexture (GL_TEXTURE_2D, cameraP->FrameBuffer ().RenderBuffer ()); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL); glLoadMatrixf (mTexBiasf); glMultMatrixf (mProjection.Vec ()); CFixMatrix::Transpose (mModelView, cameraP->GetObject ()->info.position.mOrient); glMultMatrixf (mModelView.Vec ()); } glMatrixMode (GL_MODELVIEW); #endif RenderMine (nStartSeg, nEyeOffset, nWindow); #if 1 glMatrixMode (GL_TEXTURE); glLoadIdentity (); glMatrixMode (GL_MODELVIEW); glDisable (GL_TEXTURE_GEN_S); glDisable (GL_TEXTURE_GEN_T); glDisable (GL_TEXTURE_GEN_R); glDisable (GL_TEXTURE_GEN_Q); OglActiveTexture (GL_TEXTURE0, 0); glDisable (GL_TEXTURE_2D); #endif DestroyShadowMaps (); }