void FSlateOpenGLViewport::Resize( int32 Width, int32 Height, bool bInFullscreen ) { ViewportRect.Right = Width; ViewportRect.Bottom = Height; bFullscreen = bInFullscreen; // Need to create a new projection matrix each time the window is resized ProjectionMatrix = CreateProjectionMatrix( Width, Height ); }
Camera::Camera(D3DXVECTOR3 position, D3DXVECTOR3 direction, D3DXVECTOR3 worldUp, const Frustrum& viewFrustrum) : mPosition(position), mDirection(direction), mWorldUp(worldUp), mPrevMouseX(0), mPrevMouseY(0) { //mPosition = mPosition - (D3DXVec3Dot(&mPosition, &mWorldUp) * mWorldUp); D3DXVec3Normalize(&mDirection, &mDirection); CreateProjectionMatrix(viewFrustrum); }
Camera::Camera(D3DXVECTOR3 position, D3DXVECTOR3 direction, D3DXVECTOR3 worldUp, const Frustum& viewFrustum) : mPosition(position), mDirection(direction), mWorldUp(worldUp), mZoom(-200.0f) { mPosition = mPosition - (D3DXVec3Dot(&mPosition, &mWorldUp) * mWorldUp); mDestination = mPosition; D3DXVec3Normalize(&mDirection, &mDirection); CreateProjectionMatrix(viewFrustum); }
void ResizeFunction (int Width, int Height) { CurrentWidth = Width; CurrentHeight = Height; glViewport (0, 0, CurrentWidth, CurrentHeight); ProjectionMatrix = CreateProjectionMatrix ( 60, (float)CurrentWidth / CurrentHeight, 1.0f, 100.0f ); glUseProgram (ShaderIds [0]); glUniformMatrix4fv (ProjectionMatrixUniformLocation, 1, GL_FALSE, ProjectionMatrix.m); glUseProgram (0); }
void FSlateOpenGLViewport::Initialize( TSharedRef<SWindow> InWindow, const FSlateOpenGLContext& SharedContext ) { TSharedRef<FGenericWindow> NativeWindow = InWindow->GetNativeWindow().ToSharedRef(); RenderingContext.Initialize(NativeWindow->GetOSWindowHandle(), &SharedContext); // Create an OpenGL viewport const int32 Width = FMath::TruncToInt(InWindow->GetSizeInScreen().X); const int32 Height = FMath::TruncToInt(InWindow->GetSizeInScreen().Y); ProjectionMatrix = CreateProjectionMatrix( Width, Height ); ViewportRect.Right = Width; ViewportRect.Bottom = Height; ViewportRect.Top = 0; ViewportRect.Left = 0; }
void inicializarEstado( void ) { /* DOUBLE-BUFFERING */ glutInitDisplayMode (GLUT_DOUBLE); /* Definir a cor do fundo */ glClearColor( 0.0, 0.0, 0.0, 1.0 ); /* Back-Face Culling */ glCullFace( GL_BACK ); glEnable( GL_CULL_FACE ); /* Matriz de projeccao é inicialmente a IDENTIDADE => Proj. Paralela Ortogonal */ // matrizProj = IDENTITY_MATRIX; //Start with perspective projection matrizProj = CreateProjectionMatrix( 60, 1, 1, 50 ); Translate( &matrizProj, 0, 0, -5 ); /* Parametros das transformacoes */ anguloRotXX = 0; anguloRotYY = 0; anguloRotZZ = 0; factorEscX = 0.5; factorEscY = 0.5; factorEscZ = 0.5; }
void Scene::RenderScene() { // Poll input PollEvents(); // Clear screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Update Matrices CreateProjectionMatrix(); CreateViewMatrix(); // Set uniforms glUniformMatrix4fv(glGetUniformLocation(shader->Program(), "viewMatrix"), 1, false, glm::value_ptr(viewMatrix)); glUniformMatrix4fv(glGetUniformLocation(shader->Program(), "projMatrix"), 1, false, glm::value_ptr(projMatrix)); // Draw dino modelMatrix = glm::translate(glm::mat4(), glm::vec3(50.0f, 00.0f, 0.0f)); modelMatrix = glm::rotate(modelMatrix, glm::radians(90.0f), glm::vec3(0, -1, 0)); modelMatrix = glm::scale(modelMatrix, glm::vec3(20.0f, 20.0f, 20.0f)); glUniformMatrix4fv(glGetUniformLocation(shader->Program(), "modelMatrix"), 1, false, glm::value_ptr(modelMatrix)); (*meshes)["dino"]->Draw(); // Draw box modelMatrix = glm::translate(glm::mat4(), glm::vec3(0.0f, 0.0f, 0.0f)); modelMatrix = glm::scale(modelMatrix, glm::vec3(10.0f, 10.0f, 10.0f)); glUniformMatrix4fv(glGetUniformLocation(shader->Program(), "modelMatrix"), 1, false, glm::value_ptr(modelMatrix)); (*meshes)["box"]->Draw(); // Draw death star modelMatrix = glm::translate(glm::mat4(), glm::vec3(0.0f, 750.0f, 0.0f)); modelMatrix = glm::scale(modelMatrix, glm::vec3(0.5f, 0.5f, 0.5f)); glUniformMatrix4fv(glGetUniformLocation(shader->Program(), "modelMatrix"), 1, false, glm::value_ptr(modelMatrix)); (*meshes)["deathstar"]->Draw(); // Swap buffers SwapBuffers(); }
static void myMenuDir( int i ) { char fileName[20]; switch( menu2[i].val ) { case 'O' : matrizProj = IDENTITY_MATRIX; break; case 'P' : matrizProj = CreateProjectionMatrix( 60, 1, 1, 50 ); /* Posicionar no interior do View Volome */ Translate( &matrizProj, 0, 0, -5 ); glutPostRedisplay(); break; case 'L': printf("Name for the file you want to load: "); scanf("%s",fileName); lerDeFicheiro( fileName, &numVertices, &arrayVertices, &arrayCores ); glutPostRedisplay(); break; case 'S': printf("Name for the file you want to save: "); scanf("%s",fileName); escreverEmFicheiro( fileName, numVertices, &arrayVertices, &arrayCores ); break; case 'A': anguloRotXX = 0; anguloRotYY = 0; anguloRotZZ = 0; factorEscX = 0.5; factorEscY = 0.5; factorEscZ = 0.5; glutPostRedisplay(); break; case '1' : exit( EXIT_SUCCESS ); break; } }
//Initialisation bool ASCDX9Renderer::Initialise( SRendererInit& rParameters ) { WNDCLASSEX wc = { sizeof(WNDCLASSEXA), CS_CLASSDC, ASCDX9Renderer::MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, #ifdef _DEBUG "AscensionWindow", #else L"AscensionWindow", #endif NULL }; RegisterClassEx( &wc ); LPCWSTR lstrWindowTitle = CharStrToLPCWSTR(rParameters.m_strWindowName.c_str()); RECT rc = { 0, 0, rParameters.m_uScreenWidth, rParameters.m_uScreenHeight }; AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, false ); m_hWnd = CreateWindowW( L"AscensionWindow", lstrWindowTitle, WS_OVERLAPPEDWINDOW - (WS_MAXIMIZEBOX|WS_THICKFRAME), CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, GetDesktopWindow(), NULL, wc.hInstance, NULL ); assert_msg(m_hWnd != NULL, "Guts, Failed to create window"); UINT32 uScreenX = GetSystemMetrics(SM_CXFULLSCREEN); UINT32 uScreenY = GetSystemMetrics(SM_CYFULLSCREEN); UINT32 uX = (uScreenX / 2) - (rParameters.m_uScreenWidth / 2); UINT32 uY = (uScreenY / 2) - (rParameters.m_uScreenHeight / 2); SetWindowPos(m_hWnd, NULL, uX, uY, 0, 0, SWP_NOSIZE); if ( NULL == ( m_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) { assert_now("Guts, Failed to create D3D9"); return false; } //Window parameters ZeroMemory( &m_d3dPP, sizeof( m_d3dPP ) ); m_d3dPP.Windowed = rParameters.m_bWindowMode; m_d3dPP.SwapEffect = D3DSWAPEFFECT_DISCARD; m_d3dPP.BackBufferFormat = D3DFMT_X8R8G8B8; m_d3dPP.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; m_d3dPP.EnableAutoDepthStencil = TRUE; m_d3dPP.AutoDepthStencilFormat = D3DFMT_D24X8; m_d3dPP.BackBufferWidth = rParameters.m_uScreenWidth; m_d3dPP.BackBufferHeight = rParameters.m_uScreenHeight; UINT32 AdapterToUse = D3DADAPTER_DEFAULT; D3DDEVTYPE DeviceType=D3DDEVTYPE_HAL; for (UINT32 Adapter = 0; Adapter < m_pD3D->GetAdapterCount(); Adapter++) { D3DADAPTER_IDENTIFIER9 Identifier; HRESULT Res; Res = m_pD3D->GetAdapterIdentifier(Adapter,0,&Identifier); if (strstr(Identifier.Description,"PerfHUD") != 0) { AdapterToUse=Adapter; DeviceType=D3DDEVTYPE_REF; break; } } if ( D3D_OK != m_pD3D->CreateDevice( AdapterToUse, DeviceType, m_hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &m_d3dPP, &m_pDevice ) ) { assert_now("Guts, Failed to create D3D9 device"); return false; } // Show the window ShowWindow( m_hWnd, SW_SHOWDEFAULT ); UpdateWindow( m_hWnd ); m_hInst = wc.hInstance; VertElement sDeclElem[] = { VertElement::Init(0, ES_POSITION, 0, ET_FLOAT32, 4), VertElement::Init(16, ES_COLOUR, 0, ET_UINT8, 4), VertElement::Init(20, ES_TANGENT, 0, ET_UINT8, 4), VertElement::Init(24, ES_TEXTURE, 0, ET_FLOAT32, 2), VertElement::Init(32, ES_NORMAL, 0, ET_FLOAT32, 3), VertElement::Init(44, ES_BINORMAL, 0, ET_FLOAT32, 3),}; m_pDefaultVertDecl = new ASCDX9VertexDeclaration(sDeclElem, 6, m_pDevice); m_pDefaultVertDecl->Apply(); D3DCAPS9 pCaps; m_pD3D->GetDeviceCaps(AdapterToUse, DeviceType, &pCaps); if (pCaps.AlphaCmpCaps & D3DPCMPCAPS_GREATEREQUAL) { m_pDevice->SetRenderState(D3DRS_ALPHAREF, (DWORD)0x00000001); m_pDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); m_pDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); } SetRenderState( RS_bAlphaBlendEnable, true ); SetRenderState( RS_bAlphaBlendEnable, true ); SetRenderState( RS_eAlphaSrcBlend, AB_SrcAlpha ); SetRenderState( RS_eDestBlend, AB_InvSrcAlpha ); m_pTextureManager = new ASCDX9TextureManager( m_pDevice ); m_pShaderManager = new ASCDX9ShaderManager( m_pDevice ); m_ProjectionMatrix = CreateProjectionMatrix( SC_FLOAT(rParameters.m_uScreenWidth), SC_FLOAT(rParameters.m_uScreenHeight), rParameters.m_fNear, rParameters.m_fFar); SetProjectionMatrix(m_ProjectionMatrix); m_ViewMatrix = CreateViewMatrix(); SetViewMatrix(m_ViewMatrix); return true; }