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”.
Discussion thread for this lab is here: Lab 2 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.
Make sure you have the following:
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.
Ogre::Vector3 getCartesian()
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!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! Upload your commented source files into Lab2 in MySchool (zip them up if more than one). The lab projects will not be graded, but their completion counts towards your participation grade.