I am creating a spaceship game in which you will be able to fire a laser from their ship. Basically I want to create a ray from the players ship to the cursor position. The player can move around but the camera is static. So far I've tried using:
Ray laser = mCamera->getCameraToViewportRay(mMouse->getMouseState().X.abs, mMouse->getMouseState().Y.abs);
and setting:
laser.setOrigin->(mPlayer->getPosition);
However every time I execute the ray scene query, it fires towards the top left corner of my screen. I am using the code here as a reference to how to derive the screen co-ordinates: http://www.ogre3d.org/forums/viewtopic.php?f=5&t=49132
A quick side question for extra credit:
Is there a way of only drawing ManualObject
for a small amount of time to simulate a shot from a laser gun? I've already tried to draw a small portion of the ray using the following snippet:
Ogre::ManualObject* lazor = mSceneMgr->createManualObject("lazor");
lazor->begin("HiliteYellow", Ogre::RenderOperation::OT_LINE_LIST);
// define start and end point
for (int i = 0; i< 20000;i++)
{
lazor->position(laser.getPoint(30+i));
lazor->position(laser.getPoint(300+i));
}
lazor->end();
mSceneMgr->getRootSceneNode()->attachObject(lazor);
Thanks!