set Position of a body or a actor ?

ClementM

03-02-2009 13:08:14

--------------See my last post----------------

hi,

I'am a beginner with NxOgre, and i try to put addForce to a body, but my body don't move...
This is my code:

#include "..\include\Tutoriel1App.h"

class MonCallback: public GroupCallback::InheritedCallback {

public:

void onStartTouch(Actor* Actor1, Actor* Actor2, ContactStream* cs) {

//MessageBox( NULL, "-= Entered onStartTouch Callback! =-","", MB_OK | MB_ICONERROR | MB_TASKMODAL);
}

void onEndTouch(Actor* Actor1, Actor* Actor2, ContactStream* cs) {
MessageBox( NULL, "-= Entered onEndTouch Callback! =-","", MB_OK | MB_ICONERROR | MB_TASKMODAL);
if (Actor2->getName() == "Cube2_body") {
//Actor2->addForce(Vector3(0,NxMath::rand(500,1000),0));
Actor2->addTorque(0,1,0);
}
}

void onTouch(Actor* Actor1, Actor* Actor2, ContactStream* cs) {
//MessageBox( NULL, "-= Entered onTouch Callback! =-","", MB_OK | MB_ICONERROR | MB_TASKMODAL);

}

};

Tutoriel1App::Tutoriel1App(void)
{
}

Tutoriel1App::~Tutoriel1App(void)
{
}

bool Tutoriel1App::frameStarted(const FrameEvent &evt)
{
}
bool Tutoriel1App::frameEnded(const FrameEvent &evt)
{

}
void Tutoriel1App::createScene(void)
{
//Light
mSceneMgr->setAmbientLight(ColourValue(1.0f,1.0f,1.0f));
light = mSceneMgr->createLight( "Light1" );
light->setType( Light::LT_SPOTLIGHT);
light->setPosition( Ogre::Vector3(0,620,0));
light->setDiffuseColour( 1.0, 1.0, 1.0 );
light->setSpecularColour( 1.0, 1.0, 1.0 );
mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE) ;
mSceneMgr->setShadowColour(ColourValue(0, 0, 0));

//Camera
mCamera->setPosition(0,0,500);
mCamera->pitch(Degree(15));

//NxOgre
World* mWorld = new NxOgre::World("FrameListener: Yes, time-controller:ogre, log: none");
Scene* mScene=mWorld->createScene("My Scene",mSceneMgr,"gravity: yes, floor: yes, controller: accumulator, renderer: ogre");
mScene->setGravity(Vector3(0,-100,0));

NxOgre::ActorGroup * mJaune;
NxOgre::ActorGroup * mVert;
NxOgre::ActorGroup * mPlan;

//Creation des ActorGroupes
mJaune=mScene->createActorGroup("jaune");
mVert=mScene->createActorGroup("vert");
mPlan=mScene->createActorGroup("plan");

//Parametres
ActorParams mParams;

//Cube jaune Ogre
c = new Cube(100,100,100);
ent1 = mSceneMgr->createEntity("Cube1_entity","cube.mesh");
node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Cube1_Node");
ent1->setMaterialName("Template/yellow");
node1->attachObject(ent1);
node1->rotate(Ogre::Vector3(1,1,1),Ogre::Radian(45));

NodeRenderableParams nrp1;
nrp1.setToDefault();
nrp1.mIdentifierUsage = NxOgre::NodeRenderableParams::IU_Use;
nrp1.mIdentifier = node1->getName();

mParams.mMass = 100;
mParams.mGroupAsName = "jaune";

NxOgre::Body * body_jaune = mScene->createBody("Cube1_body",c,NxOgre::Pose(NxOgre::float3(50,250,0)),nrp1,mParams);


//Cube vert Ogre
c = new Cube(100,100,100);
ent2 = mSceneMgr->createEntity("Cube2_entity","cube.mesh");
node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Cube2_Node");
ent2->setMaterialName("Template/green");
node2->attachObject(ent2);

nrp1.setToDefault();
nrp1.mIdentifierUsage = NxOgre::NodeRenderableParams::IU_Use;
nrp1.mIdentifier = node2->getName();

mParams.mMass = 0;
mParams.mGroupAsName = "vert";

NxOgre::Body * body_vert = mScene->createBody("Cube2_body",c,NxOgre::Pose(NxOgre::float3(-20,0,0)),nrp1,mParams);

//Callback
MonCallback * mCallback = new MonCallback();
mPlan->setCallback(mCallback);
mJaune->setCallback(mCallback);
mJaune->setCollisionCallback(mVert, NX_NOTIFY_ALL, true);
mPlan->setCollisionCallback(mJaune, NX_NOTIFY_ALL, true);

}

I don't know why there is not effect...
Please help me

Thanks a lot

betajaen

03-02-2009 18:30:35

Apart from the obvious remark that your addForce is commented out. Your gravity is way to high ( it should be -9.8 ), your box is rather heavy, and it's sitting on a floor (or other box) that has friction. You need a larger force to move it.

ClementM

04-02-2009 09:20:04

Apart from the obvious remark that your addForce is commented out. Your gravity is way to high ( it should be -9.8 ), your box is rather heavy, and it's sitting on a floor (or other box) that has friction. You need a larger force to move it.
Thanks a lot, it's OK :D
In addition, i have a other problem: I create 16 body, with the same Actor Group, and i want to put collision between there 16 body. I have a solution: make 16 ActorGroup and the number necessary of Callback.

Do you know a other solution to do that ?
Thanks

ClementM

04-02-2009 14:47:18

Hi, i have a question: i want to know if it's possible to get the size of a entity and use it in my body.
For example:
size_ent=10;
size_body=10;


Entity * dice_ent = mSceneMgr->createEntity("dice","0Cube_Material.001.mesh");
Ogre::SceneNode * dice_node;
dice_node = mSceneMgr->getRootSceneNode()->createChildSceneNode("dice_node");
dice_node->attachObject(dice_ent);
dice_node->setScale(Ogre::Vector3(size_ent,size_ent,size_ent));


thus, a dice has the body of a cube...
NodeRenderableParams nrp;
ActorParams mParams;
NxOgre::Cube * c = new Cube(size_body,size_body,size_body);
nrp.setToDefault();
nrp.mIdentifierUsage = NxOgre::NodeRenderableParams::IU_Use;
nrp.mIdentifier = dice_node->getName();
mParams.mMass = 10;
mParams.mGroupAsName = "dice";
dice_body = mScene->createBody("dice_body",c,NxOgre::Pose(pos1,100,pos1-50),nrp,mParams);


Thanks a lot

betajaen

04-02-2009 15:03:18

If it's a cube, then you can use the bounding box of the dice which is near to the dimensions of the cube; but you'd have to create the dice before the body. A better way is just to store the dimensions of the cube somewhere in a file and read it from there.

ClementM

10-02-2009 08:07:20

Hi,

I wonna make a special things. Imagine, your screen is not on a vertical plan, but put on a table, in the horizontal plan. In my Ogre scene, i want to have differents points of view. So, i used lookat, set position, etc.. BUT, i realised the probleme, i always see the scene with the same "orientation" (vertical plan). And i want having the possibility for the player to play with the game anywhere around the screen. (You know what i mean ?)

Exemple:
In this picture, all is OK

But, in this picture, there is a probleme of orientation of view.



I wonna know if it's possible to do that ?

Thanks a lot.

ClementM

10-02-2009 09:59:41

Re,

I success to do the second screenshot. Now i want to have the view on the right and on the left. I think it's not possible.

Can you tell me if it's true ?

ClementM

12-02-2009 09:50:20

Hi !

I have create a body, at a position( for example: Ogre::Vector3(0,0,0) ) and i want to move it, to the position Ogre::Vector3( 100, 0, 20).

I try some instructions: moveTowards, setGlobalpos, setGlobalPosition....
But no one work perfectly.

I want to know if it's possible to move a body at a position ?

Thanks

betajaen

12-02-2009 10:33:48

Describe moving it; teleporting it, or adding some force so it eventually reaches it?

ClementM

12-02-2009 10:46:54

I want just to move, translate my actor on a terrain. Without force, or torque. New Position is return by picking action.

betajaen

12-02-2009 11:30:18

setLinearVelocity

ClementM

12-02-2009 11:33:52

Ok, thanks

I try with this function, but, when i picking my actor, it's translate on the X positive axis, and it not follow my cursor.