public:t-gede-16-1:lab9
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| public:t-gede-16-1:lab9 [2016/03/30 21:18] – [Discussion] marino | public:t-gede-16-1:lab9 [2024/04/29 13:33] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 8: | Line 8: | ||
| ===== Bullet ===== | ===== Bullet ===== | ||
| - Setup Bullet Project. | - Setup Bullet Project. | ||
| - | - Downlaod [[https:// | + | - Downlaod [[https:// |
| - Build Bullet | - Build Bullet | ||
| - Run <bullet root> | - Run <bullet root> | ||
| - Open the <bullet root> | - Open the <bullet root> | ||
| - Visual studio should prompt you to update the project to visual studio, accept that. | - Visual studio should prompt you to update the project to visual studio, accept that. | ||
| - | - Make sure you compile | + | - We have confirmed that compiling |
| - Change the C/ | - Change the C/ | ||
| - Build the solution for debug and release. **You can skip all projects starting with test_ or app_ if you like.** | - Build the solution for debug and release. **You can skip all projects starting with test_ or app_ if you like.** | ||
| + | - **Note:** If your Ogre was compiled for 64 bit, your Bullet build will **also** need to be compiled for 64 bit! | ||
| ===== Lab ===== | ===== Lab ===== | ||
| Line 24: | Line 25: | ||
| - **Add** ''< | - **Add** ''< | ||
| - **Add** ''< | - **Add** ''< | ||
| - | - **Add** '' | + | - **Add (note: file names may vary slightly, e.g. _64bit is appended for 64 bit builds, verify what files you have!)** '' |
| - | - **Add** '' | + | - **Add (note: file names may vary slightly, e.g. _64bit is appended for 64 bit builds, verify what files you have!)** '' |
| - **Create class Physics.** <code cpp> | - **Create class Physics.** <code cpp> | ||
| // Header! | // Header! | ||
| Line 224: | Line 225: | ||
| } | } | ||
| </ | </ | ||
| - | - **And finally we must update the dynamicWorld** and of course make the camera shoot some boxes! | + | - **And finally we must update the dynamicWorld** and of course make the camera shoot some boxes! |
| - | - **You can either do that via the constructor**, or use the lazy way, and make them public, and set them like so '' | + | <code cpp> |
| - | | + | // HEADER! |
| - | mouseMask |= 1 << | + | #pragma once |
| - | return true; | + | #include < |
| + | #include < | ||
| + | // A simple indepdendent camera that can be flown around | ||
| + | // using the mouse and WASD keys, while pressing and holding | ||
| + | // right mouse button. | ||
| + | class RoamingCamera | ||
| + | { | ||
| + | public: | ||
| + | // Constructor | ||
| + | // sceneManager: | ||
| + | // win: is a valid render window into which the camera view will get rendered | ||
| + | RoamingCamera(Ogre:: | ||
| + | // Destructor | ||
| + | ~RoamingCamera(); | ||
| + | // Update | ||
| + | // dt: Elapsed time in seconds from the last time this method got called | ||
| + | // state: Valid SDL keyboard state, as retrieved with SDL_GetKeyboardState(..) | ||
| + | void update(Ogre:: | ||
| + | private: | ||
| + | Ogre:: | ||
| + | Ogre:: | ||
| + | Physics* _physicsEngine; | ||
| + | }; | ||
| + | |||
| + | // Implementation! | ||
| + | #include " | ||
| + | RoamingCamera:: | ||
| + | { | ||
| + | _physicsEngine = physicsEngine; | ||
| + | // Attaching | ||
| + | _node = sceneManager->getRootSceneNode()-> | ||
| + | _cam = sceneManager-> | ||
| + | _node-> | ||
| + | _node-> | ||
| + | _node-> | ||
| + | Ogre::Node:: | ||
| + | | ||
| + | _cam-> | ||
| + | Ogre::Viewport* vp = win->addViewport(_cam); | ||
| + | vp-> | ||
| + | _cam-> | ||
| + | | ||
| } | } | ||
| - | virtual bool mouseMoved(const OIS::MouseEvent &arg) { | + | RoamingCamera::~RoamingCamera() |
| - | return true; | + | { |
| } | } | ||
| - | virtual bool mouseReleased(const OIS::MouseEvent | + | void RoamingCamera:: |
| - | return true; | + | { |
| - | }</ | + | int x = 0, y = 0; |
| - | </ | + | // Leave if right mouse button is not being pressed |
| - | try { | + | // ...but also retrieve and store mouse movement |
| - | _Mouse | + | if (!(SDL_GetRelativeMouseState(&x, &y) & SDL_BUTTON_RMASK)) return; |
| - | _Mouse->setEventCallback(this); | + | // Construct displacement vector |
| - | std::cout << " | + | Ogre::Vector3 vec = Ogre:: |
| + | if (state[SDL_SCANCODE_W]) { | ||
| + | vec = Ogre:: | ||
| + | } | ||
| + | if (state[SDL_SCANCODE_S]) { | ||
| + | vec = Ogre::Vector3(0, 0, 1); | ||
| + | } | ||
| + | if (state[SDL_SCANCODE_A]) { | ||
| + | vec = Ogre::Vector3(-1, 0, 0); | ||
| + | } | ||
| + | if (state[SDL_SCANCODE_D]) { | ||
| + | vec = Ogre::Vector3(1, 0, 0); | ||
| + | } | ||
| + | if (state[SDL_SCANCODE_Q]) { | ||
| + | vec = Ogre:: | ||
| + | } | ||
| + | if (state[SDL_SCANCODE_E]) | ||
| + | | ||
| + | } | ||
| + | // Construct view rotation | ||
| + | float rotX = x * dt * -1 * 2.0f; | ||
| + | float rotY = y * dt * -1 * 2.0f; | ||
| + | // Update camera with new displacement and rotation | ||
| + | _cam->yaw(Ogre::Radian(rotX)); | ||
| + | _cam->pitch(Ogre:: | ||
| + | | ||
| } | } | ||
| - | catch (...) { | + | </ |
| - | std::cout << " | + | make it shoot boxes when some button is pressed, you can shoot boxes like this: |
| - | _Mouse = 0; | + | < |
| - | }</ | + | // Create a cube entity. |
| - | - **Now we spawn a cube from the origin of the camera** and give it some linear velocity in the direction of the camera. | + | Ogre:: |
| - | either through the constructor, | + | Ogre:: |
| - | a set function | + | |
| - | or if you're lazy, a public member.</ | + | |
| - | // Create a cube entity. | + | |
| - | Ogre:: | + | |
| - | Ogre:: | + | |
| - | cubeNode-> | + | cubeNode-> |
| - | // Set the position of the cube to the front of the origin of the camera | + | // Set the position of the cube to the front of the origin of the camera |
| - | cubeNode-> | + | cubeNode-> |
| - | cubeNode-> | + | cubeNode-> |
| - | // Now make the cube a rigid body, give it some linearVelocity and add it to the physics world | + | // Now make the cube a rigid body, give it some linearVelocity and add it to the physics world |
| - | btRigidBody* boxBody = _physicsEngine-> | + | btRigidBody* boxBody = _physicsEngine-> |
| - | boxBody-> | + | boxBody-> |
| - | }</ | + | </ |
| - **Finally** we update the physics world <code cpp>// Now update the physics world with the delta time. "Note: normally we would want to have the physics world update a little more independant of the framerate, but this will do for now :)" | - **Finally** we update the physics world <code cpp>// Now update the physics world with the delta time. "Note: normally we would want to have the physics world update a little more independant of the framerate, but this will do for now :)" | ||
| _physicsEngine-> | _physicsEngine-> | ||
/var/www/cadia.ru.is/wiki/data/attic/public/t-gede-16-1/lab9.1459372701.txt.gz · Last modified: 2024/04/29 13:32 (external edit)