void cameraMouseMove(sf::RenderWindow & window,gameMap_t * self){ //Up Left if (sf::IntRect(0, 0, 200, 200).contains(sf::Mouse::getPosition(window))){ cameraUp(self); cameraLeft(self); } //Up if (sf::IntRect(200, 0, 1290, 200).contains(sf::Mouse::getPosition(window))){ cameraUp(self); } // Left if (sf::IntRect(0, 200, 200, 680).contains(sf::Mouse::getPosition(window))){ cameraLeft(self); } //Down if (sf::IntRect(200, 880, 1520, 200).contains(sf::Mouse::getPosition(window))){ cameraDown(self); } //Right // if (sf::IntRect(1720, 200, 200, 680).contains(sf::Mouse::getPosition(window))){ // cameraRight(self); // } //dDown Left if (sf::IntRect(0, 880, 200, 200).contains(sf::Mouse::getPosition(window))){ cameraDown(self); cameraLeft(self); } }
void MainWindow::keyPressEvent(QKeyEvent *e) { switch (e->key()) { case Qt::Key_W: carForward(); break; case Qt::Key_A: carLeft(); break; case Qt::Key_S: carBack(); break; case Qt::Key_D: carRight(); break; case Qt::Key_I: cameraUp(); break; case Qt::Key_K: cameraDown(); break; case Qt::Key_J: cameraLeft(); break; case Qt::Key_L: cameraRight(); break; } }
void render( void ) { glClear( GL_COLOR_BUFFER_BIT ); static float scale = 0.0f; scale += 0.1f; Matrix matrix; matrix.rotate( 0.0f , scale , 0.0f ); matrix.worldPosition( 0.0f , 0.0f , 5.0f ); math::Vec3f cameraPosition( 0.0f , 0.0f , -3.0f ); math::Vec3f cameraTarget( 0.0f , 0.0f , 2.0f ); math::Vec3f cameraUp( 0.0f , 1.0f , 0.0f ); matrix.setCamera( cameraPosition , cameraTarget , cameraUp ); matrix.perspeciveProjection( 60.0f , WINDOW_WIDTH , WINDOW_HEIGHT , 1.0f , 100.0f ); glUniformMatrix4fv( worldLocation , 1 , GL_TRUE , ( const GLfloat* ) matrix.getTranslation() ); glEnableVertexAttribArray( 0 ); glBindBuffer( GL_ARRAY_BUFFER , vertexBufferID ); glVertexAttribPointer( 0 , 3 , GL_FLOAT , GL_FALSE , 0 , 0 ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER , indexBufferID ); glDrawElements( GL_TRIANGLES , 12 , GL_UNSIGNED_INT , 0 ); glDisableVertexAttribArray( 0 ); glutSwapBuffers(); }
int main() { tw::vec3f position(1.0f, 0.0f, -2.0f); tw::vec3f axis(0.0f, 1.0f, 0.0f); float32_t angle = tw::radians(45.0f); tw::vec3f scale(1.0f, 1.0f, 1.0f); tw::mat4f translationMat = tw::translation(position); tw::quatf rotationQuat = tw::rotation(axis, angle); tw::mat4f scalingMat = tw::scaling(scale); tw::mat4f model = translationMat * tw::mat4_cast(rotationQuat) * scalingMat; tw::vec3f cameraPosition(0.0f, 0.0f, 1.0f); tw::vec3f cameraCenter(0.0f, 0.0f, 0.0f); tw::vec3f cameraUp(0.0f, 1.0f, 0.0f); tw::mat4f view = tw::lookAt(cameraPosition, cameraCenter, cameraUp); tw::mat4f mv = view * model; tw::vec4f p(1.0f, 0.0f, 0.0f, 1.0f); p = mv * p; std::cout << p.x << " " << p.y << " " << p.z << " " << p.w << std::endl; std::cin.get(); return 0; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { //init flags cameraDownFlag = false; cameraUpFlag = false; cameraLeftFlag = false; cameraRightFlag = false; carForwardFlag = false; carBackFlag = false; carLeftFlag = false; carRightFlag = false; ui->setupUi(this); _instance = new VlcInstance(VlcCommon::args(), this); _player = new VlcMediaPlayer(_instance); _player->setVideoWidget(ui->video); ui->video->setMediaPlayer(_player); connect(ui->actionOpen_Local_File, SIGNAL(triggered()), this, SLOT(openLocal())); connect(ui->actionOpen_URL, SIGNAL(triggered()), this, SLOT(openUrl())); connect(ui->actionCar_Address, SIGNAL(triggered()), this, SLOT(setCarAddr())); connect(ui->cameraDown, SIGNAL(pressed()), this, SLOT(cameraDown())); connect(ui->cameraUp, SIGNAL(pressed()), this, SLOT(cameraUp())); connect(ui->cameraLeft, SIGNAL(pressed()), this, SLOT(cameraLeft())); connect(ui->cameraRight, SIGNAL(pressed()), this, SLOT(cameraRight())); connect(ui->carForward, SIGNAL(pressed()), this, SLOT(carForward())); connect(ui->carBack, SIGNAL(pressed()), this, SLOT(carBack())); connect(ui->carLeft, SIGNAL(pressed()), this, SLOT(carLeft())); connect(ui->carRight, SIGNAL(pressed()), this, SLOT(carRight())); connect(ui->cameraDown, SIGNAL(released()), this, SLOT(cameraDownRelease())); connect(ui->cameraUp, SIGNAL(released()), this, SLOT(cameraUpRelease())); connect(ui->cameraLeft, SIGNAL(released()), this, SLOT(cameraLeftRelease())); connect(ui->cameraRight, SIGNAL(released()), this, SLOT(cameraRightRelease())); connect(ui->carForward, SIGNAL(released()), this, SLOT(carForwardRelease())); connect(ui->carBack, SIGNAL(released()), this, SLOT(carBackRelease())); connect(ui->carLeft, SIGNAL(released()), this, SLOT(carLeftRelease())); connect(ui->carRight, SIGNAL(released()), this, SLOT(carRightRelease())); sender = new MsgSender(); }
void Model::beginRender() { mt::mat4f projection; mt::make_projection_fov_m4( projection, m_cameraFOV, m_cameraWidth / m_cameraHeight, 1.f, 1000.f ); DXCALL m_pDevice->SetTransform( D3DTS_PROJECTION, (D3DMATRIX *)projection.buff() ); const Model3DFrame & frame = this->getCurrentFrame(); mt::mat4f lookAt; mt::vec3f cameraPos( frame.cameraPos.x, frame.cameraPos.y, frame.cameraPos.z ); mt::vec3f cameraDir( -frame.cameraDir.x, -frame.cameraDir.z, -frame.cameraDir.y ); mt::vec3f cameraUp( -frame.cameraRight.x, -frame.cameraRight.z, -frame.cameraRight.y ); mt::make_lookat_m4( lookAt, cameraPos, cameraDir, cameraUp, -1.f ); DXCALL m_pDevice->SetTransform( D3DTS_VIEW, (D3DMATRIX *)lookAt.buff() ); DXCALL m_pDevice->SetTexture( 0, m_pTexture ); DXCALL m_pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); }
void mouseEvents(sf::RenderWindow & window,gameMap_t * self){ if(sf::Keyboard::isKeyPressed(sf::Keyboard::W)){ cameraUp(self); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)){ cameraLeft(self); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)){ cameraDown(self); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)){ cameraRight(self); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)){ pauseMenu(window); } }
void doMovement(CViewPoint* camera){ GLfloat currentFrame = (GLfloat)glfwGetTime(); deltaTime = currentFrame - lastFrame; lastFrame = currentFrame; GLfloat cameraSpeed = defaultCameraSpeed*deltaTime; if(!moved) { camera->rotate(glm::vec3(xoffset,yoffset,0)); moved = true; } glm::vec3 eulers = camera->getEulers(); glm::vec3 cameraTarget(-glm::sin(eulers.x)*glm::cos(eulers.y), 0, glm::cos(eulers.x)*glm::cos(eulers.y)); glm::vec3 cameraUp(0,1,0); if (keys[GLFW_MOUSE_BUTTON_2]) { camera->move (cameraTarget*cameraSpeed); } }
int main(int argc, char** argv) { try { int cudaDevice; std::string lsystemFile; int screenWidth; int screenHeight; CmdOptions cmdOptions(argc, argv); cmdOptions.read("device", cudaDevice, 0); cmdOptions.read<std::string>("lsystemFile", lsystemFile, ""); cmdOptions.read("screenWidth", screenWidth, DEFAULT_SCREEN_WIDTH); cmdOptions.read("screenHeight", screenHeight, DEFAULT_SCREEN_HEIGHT); if (lsystemFile == "") { printUsage(); exit(EXIT_FAILURE); } Framework::GLWindow window("LSystem", screenWidth, screenHeight, true, false); if (gl3wInit()) { throw std::runtime_error("gl3wInit() failed"); } cudaDeviceProp deviceProperties; cudaGetDeviceProperties(&deviceProperties, cudaDevice); cudaSetDevice(cudaDevice); LSystem lsystem(lsystemFile); /********************************/ /* CENTER L-SYSTEM ON SCREEN */ /********************************/ float width = lsystem.getBounds().extents().x; float height = lsystem.getBounds().extents().y; float screenDiagonal = sqrt(pow(width, 2) + pow(height, 2) + 1); float distance = min((screenDiagonal / 2.0f) / tan(HALF_FOV_RAD), ZFAR); float aspectRatio = screenWidth / (float)screenHeight; math::float3 cameraCenter(lsystem.getBounds().center().x, lsystem.getBounds().center().y, -distance); math::float3 cameraForward = cameraCenter + math::float3(0, 0, -1); math::float3 cameraUp(0, 1, 0); ////////////////////////////////////////////////////////////////////////// SimpleCamera camera(FOV_RAD, aspectRatio, ZNEAR, ZFAR, cameraCenter, cameraForward, cameraUp); LSystemRenderer renderer(window, lsystem, camera); window.attach(&renderer); FirstPersonCameraNavigator navigator(&camera); LSystemInputHandler inputHandler(renderer, navigator); window.attach(static_cast<Framework::MouseInputHandler*>(&inputHandler)); window.attach(static_cast<Framework::KeyboardInputHandler*>(&inputHandler)); Framework::run(renderer, &inputHandler); return 0; } catch (std::exception& e) { std::cout << "Error: " << e.what() << std::endl; } catch (...) { std::cout << "Unknown error" << std::endl; } // DEBUG: system("pause"); return -1; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowSmd) { FileSystem fileSystem("../../Resources"); Console console(fileSystem, false); ResourceManager resourceManager(fileSystem, console); InputDevice input(console); Window window("Void", console, input, resourceManager, fileSystem, 1280, 720, true, false); //Window window("Void", console, input, resourceManager, fileSystem); if(window.Initialise()) return 0; ConsoleEvent shouldQuitConsole(console, input, "Game.Quit"); input.addDefaultBinding(Key::Q, shouldQuitConsole); input.addDefaultBinding(Key::Escape, shouldQuitConsole); ConsoleEvent cameraForward(console, input, "Camera.Move.Forward"); input.addDefaultBinding(Key::W, cameraForward); ConsoleEvent cameraBackward(console, input, "Camera.Move.Backward"); input.addDefaultBinding(Key::S, cameraBackward); ConsoleEvent cameraLeft(console, input, "Camera.Move.Left"); input.addDefaultBinding(Key::A, cameraLeft); ConsoleEvent cameraRight(console, input, "Camera.Move.Right"); input.addDefaultBinding(Key::D, cameraRight); ConsoleEvent cameraUp(console, input, "Camera.Move.Up"); input.addDefaultBinding(Key::Space, cameraUp); ConsoleEvent cameraDown(console, input, "Camera.Move.Down"); input.addDefaultBinding(Key::LCtrl, cameraDown); ConsoleEvent cameraSprint(console, input, "Camera.Move.Sprint"); input.addDefaultBinding(Key::LShift, cameraSprint); window.GetGraphicsDevice().getRenderer3D().setSkybox(resourceManager.getResourceReference<TextureResource>("[Texture] Clouds.dds")); Camera &camera = window.GetGraphicsDevice().getRenderer3D().getCamera(); camera.rotateY(Math::DegreesToRadians(90)); camera.setPosition(-1100.0f, -170.0f, 0.0f); std::vector<PointLight> lights; ResourceReference<ModelResource> visibleLion = resourceManager.getResourceReference<ModelResource>("[Model] Lion.smdf"); std::vector<ResourceReference<MaterialResource>> materials; #define add_model(x) materials.push_back(resourceManager.getResourceReference<MaterialResource>("[Material] " x ".smtf")) add_model("Lion");add_model("Lionbackground"); add_model("VaseRound"); add_model("Ceiling"); add_model("ColumnA"); add_model("ColumnB"); add_model("ColumnC"); add_model("Floor"); add_model("FabricGreen"); add_model("FabricBlue"); add_model("FabricRed"); add_model("CurtainBlue"); add_model("CurtainRed"); add_model("CurtainGreen"); add_model("VaseHanging"); add_model("Vase"); add_model("Bricks"); add_model("Arch"); add_model("Details"); add_model("Roof"); add_model("VasePlant"); add_model("Chain"); add_model("Thorn");add_model("Vase"); Timer gameTime; bool isMousePressed = false; int oldMouseX = 0; int oldMouseY = 0; for(;;) { uint64 frameTime = gameTime.getElapsedReset(); float frameSeconds = frameTime / 1000.0f; resourceManager.Update(); console.update(); if(window.Update()) break; input.Update(); if(shouldQuitConsole.isPress()) break; if(isMousePressed != input.IsKeyDown(Key::LButton)) { isMousePressed = !isMousePressed; if(isMousePressed) { window.setMouseClipping(true); oldMouseX = input.GetMouseXPositionAbsolute(); oldMouseY = input.GetMouseYPositionAbsolute(); window.setMouseVisibility(true); } else { window.setMouseClipping(false); window.SetMousePosition(oldMouseX, oldMouseY); window.setMouseVisibility(false); } } if(isMousePressed) { camera.rotateY(Math::DegreesToRadians(input.GetMouseXPositionRelative())); camera.rotateX(Math::DegreesToRadians(input.GetMouseYPositionRelative())); } float distance = 100.0f * frameSeconds; if(cameraSprint.isHeld()) distance *= 6; if(cameraForward.isHeld()) camera.moveX(distance); if(cameraBackward.isHeld()) camera.moveX(-distance); if(cameraRight.isHeld()) camera.moveZ(distance); if(cameraLeft.isHeld()) camera.moveZ(-distance); if(cameraUp.isHeld()) camera.moveY(distance); if(cameraDown.isHeld()) camera.moveY(-distance); visibleLion->Render(); if(resourceManager.isLoading()) { if(lights.empty()) fillLightsGrid(lights, window); } else if(!lights.empty()) lights.clear(); if(input.IsKeyPress(Key::Num1)) fillLightsGrid(lights, window); Vector3 lightChange; if(input.IsKeyDown(Key::Up)) lightChange.y += distance; if(input.IsKeyDown(Key::Down)) lightChange.y -= distance; if(input.IsKeyDown(Key::Left)) lightChange.x += distance; if(input.IsKeyDown(Key::Right)) lightChange.x -= distance; if(lightChange != Vector3::Zero) { for(PointLight &light : lights) light.setPosition(light.getPosition() + lightChange); } if(window.Render()) break; } return 0; }
btVector3 GL_DialogDynamicsWorld::getRayTo(int x,int y) { float cameraDistance = m_screenHeight/2.f;//m_screenWidth/2;//1.f; btVector3 cameraTargetPosition(0,0,0); btVector3 cameraUp(0,-1,0); if (1)//_ortho) { btScalar aspect; btVector3 extents; if (m_screenWidth> m_screenHeight) { aspect = m_screenWidth / (btScalar)m_screenHeight; extents.setValue(aspect * 1.0f, 1.0f,0); } else { cameraDistance = m_screenWidth/2.f; aspect = m_screenHeight / (btScalar)m_screenWidth; extents.setValue(1.0f, aspect*1.f,0); } extents *= cameraDistance; btVector3 lower = cameraTargetPosition - extents; btVector3 upper = cameraTargetPosition + extents; btScalar u = x / btScalar(m_screenWidth); btScalar v = (m_screenHeight - y) / btScalar(m_screenHeight); btVector3 p(0,0,0); p.setValue( (1.0f - u) * lower.getX() + u * upper.getX(), -((1.0f - v) * lower.getY() + v * upper.getY()), cameraTargetPosition.getZ()); return p; } float top = 1.f; float bottom = -1.f; float nearPlane = 1.f; float tanFov = (top-bottom)*0.5f / nearPlane; float fov = 2 * atanf (tanFov); btVector3 cameraPosition(0,0,-100); btVector3 rayFrom = cameraPosition; btVector3 rayForward = (cameraTargetPosition-cameraPosition); rayForward.normalize(); float farPlane = 10000.f; rayForward*= farPlane; btVector3 rightOffset; btVector3 vertical = cameraUp; btVector3 hor; hor = rayForward.cross(vertical); hor.normalize(); vertical = hor.cross(rayForward); vertical.normalize(); float tanfov = tanf(0.5f*fov); hor *= 2.f * farPlane * tanfov; vertical *= 2.f * farPlane * tanfov; btScalar aspect; if (m_screenWidth > m_screenHeight) { aspect = m_screenWidth / (btScalar)m_screenHeight; hor*=aspect; } else { aspect = m_screenHeight / (btScalar)m_screenWidth; vertical*=aspect; } btVector3 rayToCenter = rayFrom + rayForward; btVector3 dHor = hor * 1.f/float(m_screenWidth); btVector3 dVert = vertical * 1.f/float(m_screenHeight); btVector3 rayTo = rayToCenter - 0.5f * hor + 0.5f * vertical; rayTo += btScalar(x) * dHor; rayTo -= btScalar(y) * dVert; //rayTo += y * dVert; return rayTo; }
/** * Function that listens for event input from keyboard. */ void Keyboard(unsigned char key, int x, int y) { switch (key){ /*projection commands*/ case '1': printf("changing projection to orthographic.\n"); orthographic(); break; case '2': printf("changing projection to oblique.\n"); oblique(); break; case '3': printf("changing projection to perspective.\n"); perspective(); break; /*camera movement*/ case 'm': printf("Camera movement. You can no use w,a,s,d,z,x to move "); printf("around.\n"); currentMode = 'm'; glutPostRedisplay(); break; case 'w': if(useSmooth == true){ useSmooth = false; bezSpeed += 0.25; calculateNewBezierCurve(direction,P0,Pref,V0,bezierP,PrefChange,uM, uMPrim,bezSpeed); bezierPCounter = 0; useSmooth = true; }else{ cameraForward(0); } break; case 'a': if(useSmooth == true){ direction = 'l'; calculateNewBezierCurve(direction,P0,Pref,V0,bezierP,PrefChange,uM, uMPrim,bezSpeed); bezierPCounter = 0; }else{ cameraLeft(); } break; case 's': if(useSmooth == true){ if(bezSpeed > 0.5){ useSmooth = false; bezSpeed -= 0.25; calculateNewBezierCurve(direction,P0,Pref,V0,bezierP,PrefChange, uM,uMPrim,bezSpeed); bezierPCounter = 0; useSmooth = true; } }else{ cameraBackward(); } break; case 'd': if(useSmooth == true){ direction = 'r'; calculateNewBezierCurve(direction,P0,Pref,V0,bezierP,PrefChange,uM, uMPrim,bezSpeed); bezierPCounter = 0; }else{ cameraRight(); } break; /*object movement*/ case 'q': printf("Closing program.....\n"); exit(0); break; case 'v': glutFullScreenToggle(); break; case 'o': printf("\ncurrent mode: open OFF file.\n"); currentMode = 'o'; glutPostRedisplay(); loadVertices(NULL); glutPostRedisplay(); break; case 't': printf("current mode: translation.\n"); currentMode = 't'; chosenMovement = 'n'; chosenMovement = 'n'; glutPostRedisplay(); printf("In which direction (x,y or z) do you want to move the object?"); printf("\npress x,y or z button to choose.\n"); break; case 'e': printf("current mode: Scaling.\n"); currentMode = 's'; glutPostRedisplay(); chosenMovement = 'n'; chosenMovement = 'n'; printf("press + or - button to scale the object.\n"); break; case 'r': printf("current mode: Rotating.\n"); currentMode = 'r'; glutPostRedisplay(); chosenMovement = 'n'; chosenMovement = 'n'; printf("Press x,y,or z to choose which axis the object should "); printf("rotate around.\n"); break; case 'x': if(currentMode == 't'){ printf("X direction chosen. press + or - button "); printf("to move the object.\n"); chosenDirection = 'x'; }else if(currentMode == 'r'){ printf("X direction chosen. press + or - button "); printf("to rotate the object around the X-axis.\n"); chosenDirection = 'x'; }else{ cameraUp(); } break; case 'y': if(currentMode == 't'){ printf("Y direction chosen. press + or - button "); printf("to move the object.\n"); chosenDirection = 'y'; }else if(currentMode == 'r'){ printf("Y direction chosen. press + or - button "); printf("to rotate the object around the Y-axis.\n"); chosenDirection = 'y'; } break; case 'z': if(currentMode == 't'){ printf("Z direction chosen. press + or - button "); printf("to move the object.\n"); chosenDirection = 'z'; } else if(currentMode == 'r'){ printf("Z direction chosen. press + or - button "); printf("to rotate the object around the Z-axis.\n"); chosenDirection = 'z'; }else{ cameraDown(); } break; case '+': if(currentMode == 't'){ if(chosenDirection == 'x' || chosenDirection == 'y' || chosenDirection == 'z'){ chosenMovement = '+'; translateStage(); } }else if(currentMode == 's'){ chosenMovement = '+'; scaleStage(); }else if(currentMode == 'r'){ chosenMovement = '+'; rotateStage(); } break; case '-': if(currentMode == 't'){ if(chosenDirection == 'x' || chosenDirection == 'y' || chosenDirection == 'z'){ chosenMovement = '-'; translateStage(); } }else if(currentMode == 's'){ chosenMovement = '-'; scaleStage(); }else if(currentMode == 'r'){ chosenMovement = '-'; rotateStage(); } break; case 'f': /*changes between line mode and filled mode for the object.*/ if(objectFilled == false){ glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); sendTMatrixToGPU(); glutPostRedisplay(); objectFilled = true; }else if(objectFilled == true){ glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); sendTMatrixToGPU(); glutPostRedisplay(); objectFilled = false; } break; case 'h': printf("Help:\n----------------------------------------------------\n"); printf("The allowed keyboard commands are: \n"); printf("o: open file, q: quit program, t: transform object\n"); printf("e: scale object, r: rotate object, m: camera movement.\n"); printf("f: object fill: on/off "); printf("x: choose x-axis. If camera mode: go up.\ny: choose y-axis "); printf("z: choose z-axis. If camera mode: go down.\n\n"); printf("w: move camera forward. a: move camera left.\n"); printf("s: move camera backwards. d: move camera right.\n"); printf("v: toggle between fullscreenmode..\n"); printf("1: orthographic projection. 2: oblique projection.\n"); printf("3: perspective projection.\n"); printf("You may also use the mouse to move the camera. To enable, "); printf("press and hold left\nmouse button and move the mouse.\n"); printf("Use the mouseScroll to zoom in or out.\n"); printf("-----------------------------------------------------------\n"); break; default: printf("Unknown keyboard command. Press \"h\" for help. \n"); break; } }
View *CascadedShadowMap::createLightView(float nSlice1, float nSlice2, Camera *camera, Camera *lightCamera, View *view, Frustum *frustum) { glm::vec3 ntl,ntr,nbl,nbr,ftl,ftr,fbl,fbr,nc,fc,X,Y,Z; float nearDepth = (float)(view->getNear()+(view->getFar()-view->getNear())*nSlice1); float farDepth = (float)(view->getNear()+(view->getFar()-view->getNear())*nSlice2); float nh = (frustum->getHeightNear()+(frustum->getHeightFar()-frustum->getHeightNear())*nSlice1)/2.0f; float nw = (frustum->getWidthNear()+(frustum->getWidthFar()-frustum->getWidthNear())*nSlice1)/2.0f; float fh = (frustum->getHeightNear()+(frustum->getHeightFar()-frustum->getHeightNear())*nSlice2)/2.0f; float fw = (frustum->getWidthNear()+(frustum->getWidthFar()-frustum->getWidthNear())*nSlice2)/2.0f; glm::vec3 cameraRight(camera->getRight()[0], camera->getRight()[1], camera->getRight()[2]); glm::vec3 cameraUp(camera->getUp()[0], camera->getUp()[1], camera->getUp()[2]); glm::vec3 cameraLookAt(camera->getLookAt()[0],camera->getLookAt()[1],camera->getLookAt()[2]); glm::vec3 cameraEye(camera->getEyeV()[0],camera->getEyeV()[1],camera->getEyeV()[2]); X = cameraRight; X = glm::normalize(X); Y = cameraUp; Y = glm::normalize(Y); Z = cameraLookAt - cameraEye; Z = glm::normalize(Z); nc = cameraEye+Z*nearDepth; fc = cameraEye+Z*farDepth; ntl = nc + Y * nh - X * nw; ntr = nc + Y * nh + X * nw; nbl = nc - Y * nh - X * nw; nbr = nc - Y * nh + X * nw; ftl = fc + Y * fh - X * fw; ftr = fc + Y * fh + X * fw; fbl = fc - Y * fh - X * fw; fbr = fc - Y * fh + X * fw; // calculate the actual bounds for the ortho projection glm::mat4 lightMVP; lightMVP = glm::ortho(-1,1,-1,1,0,1); lightMVP = lightCamera->transformToMatrix(lightMVP); float left, right, up, down, back; glm::vec4 corners[] = {glm::vec4(ntl,1.0f), glm::vec4(ntr,1.0f), glm::vec4(nbl,1.0f), glm::vec4(nbr,1.0f), glm::vec4(ftl,1.0f), glm::vec4(ftr,1.0f), glm::vec4(fbl,1.0f), glm::vec4(fbr,1.0f)}; // get the projected positions of the corners for (int i=0; i<8; i++) { corners[i]=lightMVP*corners[i]; } left = corners[0][0]; right = corners[0][0]; up = corners[0][1]; down = corners[0][1]; back = corners[0][2]; // determine the bounds for (int i=1; i<8; i++) { if (corners[i][0]<left) { left=corners[i][0]; } if (corners[i][0]>right) { right=corners[i][0]; } if (corners[i][1]<down) { down=corners[i][1]; } if (corners[i][1]>up) { up=corners[i][1]; } if (corners[i][2]>back) { back=corners[i][2]; } } View *lightView = new View(); lightView->set2D(left,right,down,up,0.1,50); return lightView; }