satchigi
29-05-2011 14:13:30
I'm attempting to make demo's playercontroller code works in only 1h, 1cpp file.
But I got a problem that how to update my mPlayer (and mSceneMgr, mCamera and etc).
when I using only 1h,1cpp file.
It's seems like almost guys are doing that by separting files like Application.h/cpp , FrameListener.h/cpp
and connecting them by using customframelistener(mFrameListener from ExampleFramelistener).
That method also requires inherit class from exampleframelistner, but I should make it without adding that class.
Of coursly, I know method just mentioned and works very well
but I need fix that works in only 1h, 1cpp file to intergrate my framework.
My player is now not updated and not moving at all.
I can only do mouse pitch. (yawing is not working because it move with player)
[attachment=0]asd.jpg[/attachment]
As you can see, player controller's cilinder is attatched properly. The only problem is it's not updated.
gravity and another thing is also properly updated by OgeNewt::BasicframeListner <-- I can update this basic thing very simply but
why mPlayer,mCamera..etc require make another file?
Following is my source code. (It's included in just 1cpp file.)
This is my constructor
And this is player body's part.
And this is frmaelistener part
And this is input part.
Need to know how to update mPlayer without using customframelistener. help!
But I got a problem that how to update my mPlayer (and mSceneMgr, mCamera and etc).
when I using only 1h,1cpp file.
It's seems like almost guys are doing that by separting files like Application.h/cpp , FrameListener.h/cpp
and connecting them by using customframelistener(mFrameListener from ExampleFramelistener).
That method also requires inherit class from exampleframelistner, but I should make it without adding that class.
Of coursly, I know method just mentioned and works very well
but I need fix that works in only 1h, 1cpp file to intergrate my framework.
My player is now not updated and not moving at all.
I can only do mouse pitch. (yawing is not working because it move with player)
[attachment=0]asd.jpg[/attachment]
As you can see, player controller's cilinder is attatched properly. The only problem is it's not updated.
gravity and another thing is also properly updated by OgeNewt::BasicframeListner <-- I can update this basic thing very simply but
why mPlayer,mCamera..etc require make another file?
Following is my source code. (It's included in just 1cpp file.)
This is my constructor
OgreNewtonApplication::OgreNewtonApplication(void)
: mRoot(0),
mPluginsCfg(Ogre::StringUtil::BLANK)
{
mContinue = true;
// create OgreNewt world.
m_World = new OgreNewt::World();
//mPlayer = NULL;
m_World->setWorldSize(Ogre::Vector3(-30000,-30000,-30000), Ogre::Vector3(30000,30000,30000));
mEntityCount = 0;
}
OgreNewtonApplication::~OgreNewtonApplication(void)
{
Ogre::WindowEventUtilities::removeWindowEventListener(mWindow, this);
windowClosed(mWindow);
delete mRoot;
// destroy world.
if( mPlayer )
delete mPlayer;
delete m_World;
}
And this is player body's part.
void OgreNewtonApplication::makePlayer()
{
Entity* ellipsoid;
SceneNode* node;
ellipsoid = mSceneMgr->createEntity( "PlayerControllerEntity", "harry.mesh");
node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
node->attachObject( ellipsoid );
Ogre::Vector3 size (1.0f, 1.0f, 1.0f);
node->setScale(size);
OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Ellipsoid(m_World, Ogre::Vector3(30,90, 20), 0, Ogre::Quaternion::IDENTITY, Ogre::Vector3(0,100,0)));
OgreNewt::Body* bod = new OgreNewt::Body( m_World, col );
Ogre::Vector3 inertia, offset;
col->calculateInertialMatrix(inertia, offset);
#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR
delete col;
#endif
bod->attachNode(node);
bod->setMassMatrix( 50, 50*inertia );
bod->setCenterOfMass(offset);
bod->setStandardForceCallback();
// bod->setPositionOrientation(Ogre::Vector3(0,20,20), Ogre::Quaternion::IDENTITY);
// bod->setPositionOrientation(Ogre::Vector3(6.74f, -6.0f, -8.2f), Ogre::Quaternion::IDENTITY);
bod->setPositionOrientation(Ogre::Vector3(0.0f, 100.0f, 0.0f), Ogre::Quaternion::IDENTITY);
// set teh play to alway be actibe
bod->setAutoSleep(0);
bod->setCustomForceAndTorqueCallback<OgreNewtonApplication>(&OgreNewtonApplication::forceCallback,this);
bod->setContinuousCollisionMode(false);
mPlayer = new OgreNewt::PlayerController(bod, 0.4);
}
And this is frmaelistener part
void OgreNewtonApplication::createFrameListener()
{
OgreNewt::BasicFrameListener* mNewtonListener;
mNewtonListener = new OgreNewt::BasicFrameListener( mWindow, m_World, 100 );
mRoot->addFrameListener(mNewtonListener);
}
bool OgreNewtonApplication::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
return true;
}
bool OgreNewtonApplication::frameStarted(const FrameEvent& evt)
{
mMouse->capture();
mKeyboard->capture();
//cameraPitchAngle = 0.0f;
m_extenalViewDist = 180.0f;
mRoot->addFrameListener(this);
if(mWindow->isClosed())
return false;
Ogre::Real forwardSpeed, sideSpeed;
Ogre::Radian heading;
mPlayer->getVelocity(forwardSpeed, sideSpeed, heading);
forwardSpeed = 0;
sideSpeed = 0;
if( up == true )
forwardSpeed += 800;
if( down == true )
forwardSpeed -= 500;
if( left == true )
sideSpeed -= 500;
if( right == true )
sideSpeed += 500;
Real timestep = evt.timeSinceLastFrame;
Real rate = (60.0f * 3.1416f/ 180.0f) * timestep;
// calculate the camera Pitch Angle
int pitchDir = mMouse->getMouseState().Y.rel;
cameraPitchAngle += -pitchDir * rate;
if (cameraPitchAngle > 80.0f * 3.1416f/ 180.0f) cameraPitchAngle = 80.0f * 3.1416f/ 180.0f;
if (cameraPitchAngle < -80.0f * 3.1416f/ 180.0f) cameraPitchAngle = -80.0f * 3.1416f/ 180.0f;
Ogre::Quaternion pitch (Ogre::Radian(cameraPitchAngle), Ogre::Vector3 (1, 0, 0));
int yawDir = mMouse->getMouseState().X.rel;
heading += Ogre::Radian(-yawDir * rate);
mPlayer->setVelocity(forwardSpeed, sideSpeed, heading);
Ogre::Vector3 posit;
Ogre::Quaternion orient;
OgreNewt::Body* playerBody = mPlayer->getBody0();
// playerBody->getPositionOrientation (posit, orient);
playerBody->getVisualPositionOrientation (posit, orient);
orient = orient * pitch;
posit += orient * Ogre::Vector3 (60, 80, m_extenalViewDist);
// move eye point to be about the players head
posit.y += mPlayer->getPlayerHeight() * 0.75f;
mCamera->setPosition(posit);
mCamera->setOrientation(orient);
this->m_World->getDebugger().init(this->mSceneMgr);
this->m_World->getDebugger().hideDebugInformation();
if( debug == true )
this->m_World->getDebugger().showDebugInformation();
return mContinue;
}
And this is input part.
bool OgreNewtonApplication::keyPressed( const OIS::KeyEvent &e )
{
switch (e.key)
{
case OIS::KC_ESCAPE: mContinue = false;break;
case OIS::KC_W: up = true;break;
case OIS::KC_S: down = true;break;
case OIS::KC_A: left = true;break;
case OIS::KC_D: right = true;break;
case OIS::KC_R: debug = true;break;
case OIS::KC_E: debug = false;break;
}
return true;
}
bool OgreNewtonApplication::keyReleased( const OIS::KeyEvent &e )
{
switch (e.key)
{
case OIS::KC_W: up = false;break;
case OIS::KC_S: down = false;break;
case OIS::KC_A: left = false;break;
case OIS::KC_D: right = false;break;
}
return true;
}
Need to know how to update mPlayer without using customframelistener. help!