This lab is to some extent based on Chapter 4 in the textbook, in particular sections 4.2.1 “Points and Cartesian Coordinates” and 4.2.4 “Vector Operations”.
The main focus here is to learn how we can use other coordinate systems to help us generate effects or behaviour that would be unintuitive to do with Cartesian coordinates.
Discussion thread for this lab is here: Lab 3 Discussion Thread
There are two main parts to this lab. In the first part, which has you thinking about coordinate systems, you create an animation effect that spins an object along a cylindrical path. In the second part, which focuses on vector operations, you use a simple dot product to find which direction you are facing relative to another object.
OgreMath.h
included in your source file to access the Ogre::Math::Cos()
and Ogre::Math::Sin()
functionsFollow these steps to complete the lab project:
SceneNode
as a child of the Ogre's scene node, and attach the Cube to that node. This means that all transformations applied to the Ogre's scene node will be passed down into the Cube's scene node as well. So, do the following:createScene
createScene
method, add the following (after you create the Ogre entity): _myCube = _sceneManager->createEntity("Cube.mesh"); Ogre::SceneNode* cubenode =_myOgre->getParentSceneNode()->createChildSceneNode(); cubenode->attachObject(_myCube);
cubenode->scale(0.01, 0.01, 0.01); //Try different values cubenode->setPosition(2.0, 0.0, 0.0); //Notice that this is relative to the Ogre's model origin
Ogre::Light* plight = _sceneManager->createLight("Light2"); plight->setType(Ogre::Light::LT_POINT); cubenode->attachObject(plight);
CylindricalEffect
that moves an entity along a cylindric path at a given velocity. The class has the following constructor:CylindricalEffect(Ogre::Entity* entity, Ogre::Vector3 position, Ogre::Vector3 velocity)
entity
is any movable entity in the scene that you want to apply the animation effect to. The second argument position
is that entity's position (relative to it's parent) in Cylindrical Coordinates, that is, the vector consists of three numbers: velocity
is the velocity of the object along the three axes of the cylindrical coordinates, i.e. along the height axis, along the radius and the angular velocity along the circle. GetCartesian()
Method If the class operates on cylindrical coordinates, you will always want to retrieve the corresponding cartesian coordinates for updating positions in the Ogre3D default cartesian coordinate system. Therefore you should add the following method which should return the class's position member variable converted to Cartesian coordinates Ogre::Vector3 getCartesian()
(height,radius,angle) = (h, r, α) X coordinate = cosine of the angle times the radius Y coordinate = height Z Coordinate = sin(angle) times the radius
void update(float dt) { _position = _position + dt*_velocity; _entity->getParentSceneNode()->setPosition(getCartesian()); }
frameStarted
method (note that you'll have to pass a pointer to this effect into the FrameListener constructor so that it knows about it). Don't forget to delete your effect instance in the destructor of your application!Bonus Pts!
Ogre::Vector3 F = _Cam→getDirection();
). If this dot product is greater than 0, you know the object is in front of the camera. Finally, why don't you also check to see if the object is relatively close to the camera (you can use the Ogre::Vector3::length() method). Now you can add this to your project such that the special effect only gets updated when these two checks are passed! Lets remove the height, and replace it with the angle theta Θ So the coordinate would be like (angle,radius,angle) = (Θ,r,α) X coordinate = sin(α) times cos(Θ) times r Y coordinate = cos(α) times r // This was Cos of Θ, which was wrong :( Z coordinate = sin(α) sin(Θ) times r
And find some interesting way to make the spherical movement random
The finished results should look somewhat like this picture here unless you implemented the bonus steps!
Upload your commented source files into Lab3 in MySchool (zip them up if more than one).