deshan
25-09-2009 14:33:38
Hi all
I am new to NXOGRE
I am trying to make a first person camera with NXOGRE. But I am facing the problem of creating the physics body which I am going to attach the camera node
The thing I have done with OGRENEWT as follows
SceneNode* cam_node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
Collision* cam_collision = new OgreNewt::CollisionPrimitives::Ellipsoid( mWorld, cam_size,Ogre::Quaternion::IDENTITY,Vector3(0, 100/2 ,0) );
Body* cam_body= new OgreNewt::Body( mWorld, cam_collision ); // create the body
cam_body->attachToNode( cam_node); // attach the node to the body. Now, when the body moves the node moves too
SceneNode* cam_view_node = cam_node->createChildSceneNode(Vector3(0,5,0));
cam_view_node->attachObject(mCamera);
Now here what would be the body which I have to attach the camera node?
Thank You
betajaen
25-09-2009 15:21:39
Hi there,
It isn't too difficult to do. As your using Ogre, you'll need the OGRE3DRenderSystem, and you use a OGRE3DBody instead of an Actor (OGRE3DBody is a class that inherits from Actor and has a SceneNode/Entity as member variables).
So using your code, roughly translated it should go:
SceneNode* cam_node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
cam_node->attachObject(mCamera);
OGRE3DRigidBodyPrototype* rigidbody_prototype = new OGRE3DRigidBodyPrototype();
rigidbody_prototype->mNode = cam_node; // Usually OGRE3DBody creates one if this is NULL. We don't want that.
OGRE3DBody* cam_body = mOgreRenderSystem->createBody(new Capsule(0.5, 2), NxOgre::Vec3(0,5,0), Ogre::StringUtil::BLANK, rigidbody_prototype);
Done.
if your not sure about the RenderSystem, or your totally new to NxOgre. Checkout Spacegaier's NxOgre tutorials on the Wiki.
deshan
25-09-2009 16:21:37
Thank You very much for answering.
I have tried it, but 4th parameter of createBody only accept NxOgre::RigidBodyDescription. Here it is OGRE3DRigidBodyPrototype *. Is there any method to convert
OGRE3DRigidBodyPrototype to RigidBodyDescription? Because I have found that RigidBodyDescriptionToRigidBodyPrototype() method copies RigidBodyDescription members to the OGRE3DRigidBodyPrototype.
Colud you please help me again?
I am totally new to ogre and I have tried all the wiki tutorials. They are really understandable and well explained.
betajaen
25-09-2009 16:51:20
Oh poop. I thought it did Prototypes.
I tell you what, I'll add a second createBody method for you, so you can attach a scenenode directly.
betajaen
25-09-2009 17:58:21
There we go. I added an alternate createBody function to accept scenenodes as arguments. I haven't tested it, but it should work.
SceneNode* cam_node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
cam_node->attachObject(mCamera);
OGRE3DBody* cam_body = mOgreRenderSystem->createBody(new Capsule(0.5, 2), NxOgre::Vec3(0,5,0), cam_node);
deshan
25-09-2009 19:20:30
THANK YOU BETAJAEN, YOU ARE AWESOME!!!
Found one thing, That release not works with Real3 but Vec3.
Thank You again!!!
This is my code
#ifndef FPCAMERA_H
#define FPCAMERA_H
#include "Ogre.h"
#include <NxOgre.h>
#include <NxOgreOGRE3D.h>
using namespace Ogre;
using namespace NxOgre;
class FPCamera
{
private:
Ogre::SceneManager* mSceneMgr;
Ogre::Camera* mCamera;
NxOgre::Scene* mScene;
OGRE3DRenderSystem* mRenderSystem;
SceneNode* cam_node;
SceneNode* cam_view_node;
SceneNode* bodyNode;
OGRE3DBody* mCube;
OGRE3DRigidBodyPrototype* rigidbody_prototype;
OGRE3DBody* cam_body;
public:
FPCamera(Ogre::SceneManager* mSceneMgr,Ogre::Camera* mCamera, NxOgre::Scene* mScene, OGRE3DRenderSystem* mRenderSystem);
~FPCamera();
};
#endif
#include "FPCamera.h"
FPCamera::FPCamera(Ogre::SceneManager* mSceneMgr,Ogre::Camera* mCamera, NxOgre::Scene* mScene, OGRE3DRenderSystem* mRenderSystem)
{
this->mSceneMgr = mSceneMgr;
this->mCamera = mCamera;
this->mScene = mScene;
this->mRenderSystem = mRenderSystem;
this->cam_node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
cam_node->attachObject(mCamera);
cam_body = mRenderSystem->createBody(new Capsule(0.5, 2), NxOgre::Vec3(0,5,0), cam_node);
cam_body->addForce(NxOgre::Vec3(0, 0, -100), NxOgre::Enums::ForceMode_Force);
}
FPCamera::~FPCamera()
{
}
betajaen
25-09-2009 19:21:39
No problem, although you don't need that RigidBodyPrototype anymore.
Yep - I removed the Real3 typedef. Much to Spacegaier's annoyance - he had to update his tutorials again.
Just replace any instances of Real3 in your code with Vec3 and you should be fine.
deshan
25-09-2009 19:37:22
Thank You again.
I have removed that RigidBodyPrototype and updated the above code again.
Really appreciate ur help.