void BSPMap::spawn(scene::Camera& cam, int i) const{ if(i<-1 || i>=(int)spawnPoints.size()) throw BadIndexException("Bad index while getting spawn point in BSPMap!"); if(i == -1) i = rand() % spawnPoints.size(); cam.setPosition(spawnPoints[i]); math::Vector3 v(1, 0, 0); Matrix4 m; math::Vector3 v2; v2[1] = spawnPoints[i].getA() * (3.14/180); m.rotate(v2); v = v*m; cam.setLookAt(spawnPoints[i]+v); }
virtual void update() override { auto kbd = mEngine->get<Input>()->getKeyboardList().front(); // should mainKeyboard be a thing? auto mouse = mEngine->get<Input>()->getMouseList().front(); // should mainMouse be a thing? // [WASD keyboard controls] { auto cameraAxes = mCamera.getDirections(); glm::vec3 deltaPosition(0.0f, 0.0f, 0.0f); if ((*kbd)['W']) deltaPosition -= cameraAxes.mForward; if ((*kbd)['S']) deltaPosition += cameraAxes.mForward; if ((*kbd)['A']) deltaPosition -= cameraAxes.mRight; if ((*kbd)['D']) deltaPosition += cameraAxes.mRight; if ((*kbd)['Q']) deltaPosition += cameraAxes.mUp; if ((*kbd)['Z']) deltaPosition -= cameraAxes.mUp; if ((*kbd)[GLFW_KEY_LEFT_SHIFT]) deltaPosition *= 5; float elapsedSeconds = mEngine->getClock().deltaFrame().count() * 0.001f; // deltaframe is in milliseconds float movementSpeed = 1.0f * elapsedSeconds; deltaPosition *= movementSpeed; mCamera.setPosition(mCamera.getPosition() + deltaPosition); } // [Mouselook] ~ yaw/pitch based { static std::pair<double, double> previousMousePosition = std::make_pair(0.0, 0.0); auto currentPos = mouse->getPosition(); if ((previousMousePosition.first == 0.0) && (previousMousePosition.second == 0.0)) previousMousePosition = currentPos; float dx = 0.01f * static_cast<float>(currentPos.first - previousMousePosition.first); float dy = 0.01f * static_cast<float>(currentPos.second - previousMousePosition.second); previousMousePosition = currentPos; mCameraYaw += dx; mCameraPitch += dy; auto yawQ = glm::rotate(mCameraYaw, glm::vec3(0.0f, 1.0f, 0.0f)); auto pitchQ = glm::rotate(mCameraPitch, glm::vec3(1.0f, 0.0f, 0.0f)); glm::quat q = glm::quat_cast(pitchQ * yawQ); mCamera.setOrientation(q); } mCamera.update(); mRenderState.clear(); // render that skybox mSkyBoxProgram.bind(); mSkyBoxProgram.setUniform("uView", mCamera.getView()); mSkyBoxProgram.setUniform("uProjection", mCamera.getProjection()); mSkyBoxProgram.setUniform("uModel", glm::translate(mCamera.getPosition())); mSkyBoxTexture.bind(0); mSkyBoxProgram.setUniform("uCubeMap", 0); mSkyBox->draw(); // render the cubes mProgram.bind(); mProgram.setUniform("uView", mCamera.getView()); mProgram.setUniform("uProjection", mCamera.getProjection()); mProgram.setUniform("uLightDirection", glm::vec4(0.2, -1, 0.5, 1)); mProgram.setUniform("uLightAmbient", glm::vec4(0.1, 0.1, 0.1, 1.0)); mProgram.setUniform("uLightDiffuse", glm::vec4(0.85, 0.85, 0.85, 1.0)); mTexture.bind(0); mProgram.setUniform("uTexture", 0); // draw the cube at 100 different locations for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) { mProgram.setUniform("uModel", glm::translate(glm::vec3(2 * (i - 5), 0, 2 * (j - 5)))); mSphere->draw(); //mCube->draw(); } }