[SOLVED] ball from camera - cam direction and roation issue

klarax

23-11-2009 15:17:44

Hi guys,

i have an issue i cant seem to think through correctly and was hoping you could shed some light on things...

I got this demo going where if you can imagine a coconut throw game, where you throw a ball at coconuts to knock them off. Well got the scene all set up, and all is good

Whats getting me is getting the ball to move from the cam to the direction that the camera is facing given the rotation and direction of the camera

I have created the ball at the cam pos but looking at the addforce func, they require vec3's and i think i need some quaternion, or maybe a real for axix of mouse.

I've pasted the small section of code that im trying to implement below:


if(m_pGameState->getState() == BALLS)
{
if(m_iBallCount < NUMBEROFALLOWEDBALLS)
{
//Target Meshes - as Convex
convexMesh = NxOgre::MeshManager::getSingleton()->load("media:ball.nxs");
convex = new NxOgre::Convex(convexMesh);

//Fill Target Array with meshes and position each
m_pRenderSystem = m_pGameState->getRenderSystem();
m_pBallBody[m_iBallCount] = m_pRenderSystem->createBody(convex, m_pCameraNode->getPosition()/*NxOgre::Vec3(900, -2.0, 115)*/, "ball.mesh");

//here i have tried addforce and setvelocity functions but they dont appear to do anything :s

m_iBallCount++;
}
return;
}


Hope you can shed some light on this matter for me.

Thanks,

Karax

deshan

24-11-2009 08:29:47

try something like this

Ogre::Vector3 dire = m_pCameraNode->_getDerivedOrientation() * Ogre::Vector3(0, 0, -1);

dgoldaraz

24-11-2009 11:32:52

I think that yo can use the BlodyMess Tutorial 5 (in NxOgre wiki) something like this:

if(mKeyboard->isKeyDown(OIS::KC_SPACE) && mTimeUntilNextToggle <= 0)
{
mCube = mRenderSystem->createBody(new NxOgre::Box(1, 1, 1), NxOgre::Vec3(mCamera->getPosition().x,
mCamera->getPosition().y, mCamera->getPosition().z), "cube.1m.mesh");
mCube->addForce(NxOgre::Vec3(mCamera->getDirection().x * 10000, mCamera->getDirection().y * 10000,
mCamera->getDirection().z * 10000), NxOgre::Enums::ForceMode_Force, true);
mTimeUntilNextToggle = 0.2;
}


Here when you press Space yo create a box an shoot it in the direccion of the camera!

klarax

26-11-2009 11:48:46

I solved this by used deshan's way of doing it. Had to use the scene node as the using the camera resulted in the creation of the balls being created at the camera creation position i.e. 0,0,0

i the had to multiply the dire result by 8000 to produce a force that gave a rsult that i needed.

Thanks all :)

Klarax