NxOgre 0.9 Joints

ghiboz

15-05-2007 13:55:13

Hi all!
how works the joint in 0.9?
i tried to look in the sources, but I don't find nothing.
thanks very much! :wink:

betajaen

15-05-2007 16:58:30

According to the code I have, only the revolute joint is implemented, but joints should be gradually implemented over the next SVN commits.

ghiboz

15-05-2007 17:38:53

According to the code I have, only the revolute joint is implemented, but joints should be gradually implemented over the next SVN commits.
thanks, but in the svn server, the revolute joint is there or not?
and have you estimated when you commit the new things?

regards

ghiboz

betajaen

15-05-2007 17:43:50

Is English your primary language?

1. Yes

2. I have no idea when.

ghiboz

15-05-2007 17:46:00

Is English your primary language?
no, i'm italian.. sorry for the english errors that I write!
1. Yes
thanks, is somewhere a sample?
2. I have no idea when.
:cry: thanks for your great work!!

ghiboz

15-05-2007 18:01:30

2. I have no idea when.
to develop a new project, what do you suggest?
is better start with the 0.6 or with the 0.9??

regards :wink:

Pottej

25-05-2007 23:26:39

Hi Betajaen,

I thought I better post here because this is about joints too.

I am planning on using NxOgre for a big project which starts soon, but I will need as many joints as possible to be implemented. After getting used to 0.0 it would be great to use it, but if the joints aren't going to be in then I will probably settle for 0.6.

I know this is an annoying question :roll: , but what is your best guess for when you will implement the other joints? Are you just about to roll them out or are you concentrating on other things right now?

Thanks.

betajaen

25-05-2007 23:32:45

Since it's only me working on the code and interface (Although I don't mind working others working on the code, only I work on the interface). It's a question of when I have time to work it in.

The revolute joint is already in, and the joint class, and joint system has been created. So I suppose it's a lot of copying and pasting of the revolute class and changing the name for each PhysX one.

I started on cloth the other day, rewrote the render and simulate code based off code I don't understand - doesn't work though. So I'll attempt to fix that, once that's done. I need to finish of the shape system with handling groups and CCD.

Joints after that I suppose.

Pottej

25-05-2007 23:39:10

Right cool,

I might be able to piece some of them together, if I did could I send them to you for testing and maybe it would save you some time?

betajaen

25-05-2007 23:44:22

Alright, You can paste the code in here. Remember to use the right case for the class names, and use the RevoluteJoint as a base. Oh and remember the factory method in Scene, and three joints per "Joint Set".

Pottej

26-05-2007 00:01:35

OK I'll see what I can come up with. I probably won't have anything until next week but I'll keep you posted.

Cheers for all your work on this by the way :D

Pottej

26-05-2007 16:29:54

Ok here's my first joint set... you were right it was just a lot of copy and pasting. I've done spherical, prismatic and fixed joints.

Don't have time to properly test it so it could be totally broken, but the compiler isn't whining right now. Hope it is in the right format for you.

NxOgreJointSet2.h

//
// NxOgre a wrapper for the PhysX (formerly Novodex) physics library and the Ogre 3D rendering engine.
// Copyright (C) 2005 - 2007 Robin Southern and NxOgre.org http://www.nxogre.org
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//

#ifndef __NXOGRE_JOINTSET2_H__
#define __NXOGRE_JOINTSET2_H__

#include "NxOgrePrerequisites.h"
#include "NXOgreJoint.h"

namespace NxOgre {

class NxExport SphericalJoint : public Joint {

public:
SphericalJoint(Actor* a, Actor* b, const Ogre::Vector3 &anchor);
SphericalJoint(Actor* a, const Ogre::Vector3 &anchor);
~SphericalJoint();

protected:

void __createJoint(const Ogre::Vector3 &anchor);

NxSphericalJoint *mSphericalJoint;
NxSphericalJointDesc mDescription;


};

////////////////////////////////////////////////////////////////////////////////////

class NxExport FixedJoint : public Joint {

public:
FixedJoint(Actor* a, Actor* b);
~FixedJoint();

protected:

void __createJoint();

NxFixedJoint *mFixedJoint;
NxFixedJointDesc mDescription;

};

////////////////////////////////////////////////////////////////////////////////////

class NxExport PrismaticJoint : public Joint {

public:
PrismaticJoint(Actor* a, Actor* b, const Ogre::Vector3 &axis);
PrismaticJoint(Actor* a, const Ogre::Vector3 &axis);
~PrismaticJoint();

protected:

void __createJoint(const Ogre::Vector3 &axis);

NxPrismaticJoint *mPrismaticJoint;
NxPrismaticJointDesc mDescription;

};



};

#endif


NxOgreJointSet2.cpp

//
// NxOgre a wrapper for the PhysX (formerly Novodex) physics library and the Ogre 3D rendering engine.
// Copyright (C) 2005 - 2007 Robin Southern and NxOgre.org http://www.nxogre.org
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//

#include "NxOgreStable.h"
#include "NxOgreJointSet2.h"
#include "NxOgreJoint.h" // For: These joints inherit Joint
#include "NxOgreActor.h" // For: a::getNxActor, b::getNxActor
#include "NxOgreHelpers.h" // For: Vector3 to NxVec3 conversion
#include "NxOgreScene.h" // For: mScene::getNxScene()

namespace NxOgre {

////////////////////////////////////////////////////////////////////////////////////

SphericalJoint::SphericalJoint(Actor *a ,Actor *b, const Ogre::Vector3 &anchor) : Joint(a,b){
mDescription.setToDefault();
__createJoint(anchor);
}

////////////////////////////////////////////////////////////////////////////////////

SphericalJoint::SphericalJoint(Actor *a, const Ogre::Vector3 &anchor) : Joint (a) {
mDescription.setToDefault();
__createJoint(anchor);
}

////////////////////////////////////////////////////////////////////////////////////

void SphericalJoint::__createJoint(const Ogre::Vector3 &anchor) {

mDescription.actor[0] = mActorA->getNxActor();

if (mActorB)
mDescription.actor[1] = mActorB->getNxActor();
else
mDescription.actor[1] = NULL;

mDescription.setGlobalAnchor(toNxVec3(anchor));
mDescription.userData = this;

mNxJoint = mScene->getNxScene()->createJoint(mDescription);
mSphericalJoint = static_cast<NxSphericalJoint*>(mNxJoint);
}

////////////////////////////////////////////////////////////////////////////////////

SphericalJoint::~SphericalJoint() {
mScene->getNxScene()->releaseJoint(*mNxJoint);
}

////////////////////////////////////////////////////////////////////////////////////

FixedJoint::FixedJoint(NxOgre::Actor *a, NxOgre::Actor *b) : Joint (a,b){
mDescription.setToDefault();
__createJoint();
}

////////////////////////////////////////////////////////////////////////////////////

FixedJoint::~FixedJoint() {
mScene->getNxScene()->releaseJoint(*mNxJoint);
}

////////////////////////////////////////////////////////////////////////////////////

void FixedJoint::__createJoint(){
mDescription.actor[0] = mActorA->getNxActor();
mDescription.actor[1] = mActorB->getNxActor();
mDescription.userData = this;

mNxJoint = mScene->getNxScene()->createJoint(mDescription);
mFixedJoint = static_cast<NxFixedJoint*>(mNxJoint);
}

////////////////////////////////////////////////////////////////////////////////////

PrismaticJoint::PrismaticJoint(NxOgre::Actor *a, NxOgre::Actor *b, const Ogre::Vector3 &axis) : Joint(a,b){
mDescription.setToDefault();
__createJoint(axis);
}

////////////////////////////////////////////////////////////////////////////////////

PrismaticJoint::PrismaticJoint(NxOgre::Actor *a, const Ogre::Vector3 &axis) : Joint(a){
mDescription.setToDefault();
__createJoint(axis);
}

////////////////////////////////////////////////////////////////////////////////////

PrismaticJoint::~PrismaticJoint(){
mScene->getNxScene()->releaseJoint(*mNxJoint);
}

////////////////////////////////////////////////////////////////////////////////////

void PrismaticJoint::__createJoint(const Ogre::Vector3 &axis){
mDescription.actor[0] = mActorA->getNxActor();

if(mActorB){
mDescription.actor[1] = mActorB->getNxActor();
}
else{
mDescription.actor[1] = NULL;
}

mDescription.setGlobalAxis(toNxVec3(axis));
mDescription.userData = this;

mNxJoint = mScene->getNxScene()->createJoint(mDescription);
mPrismaticJoint = static_cast<NxPrismaticJoint*>(mPrismaticJoint);

}


}; //End of NxOgre namespace.

betajaen

26-05-2007 18:21:42

I told you it was copying and pasting, and thank you for the code.

ghiboz

31-05-2007 14:52:45

compile, but after to use? I need to implement in the scene the createFixedJoint, etc??

bye :lol:

Pottej

01-06-2007 14:01:43

Just use the constructor:



NxOgre::FixedJoint* joint = new NxOgre::SphericalJoint(a,b);



Does it not work? I have got spherical joints working in my application.

ghiboz

01-06-2007 15:33:35

Just use the constructor:



NxOgre::FixedJoint* joint = new NxOgre::SphericalJoint(a,b);



Does it not work? I have got spherical joints working in my application.


and you have simply added the 2 files in the nxogre dll??

hmmm :o

Caphalor

12-08-2007 15:33:30

Fixed Joints are working, but I have a question about spherical joints. I created two dynamic bodies with a sphere shape and created a spherical shape. I added this to NxOgreScene.cpp (only copy and paste):

SphericalJoint* Scene::createSphericalJoint(NxOgre::Actor *a, NxOgre::Actor *b, const Ogre::Vector3 &anchor)
{
SphericalJoint* j = new SphericalJoint(a, b, anchor);
NxString jid = NxCreateID(mJoints.count(), "Joint");
mJoints.insert(jid, j);
mJoints.lock(jid, true);
return j;
};


The connection between the two dynamic bodies is very weak, if I add force to one the other moves and rotates, but much less than the first one; unacceptable for a chain for example. I tried many values for the anchor, but no difference. :(

betajaen

12-08-2007 15:40:08

Worth a shot, try increasing the solver count for both Actors.

Caphalor

12-08-2007 16:01:00

I tried
mBody->setSolverIterationCount(100);
but no differences. I made a video, maybe it helps: http://dragoonmind.dk/data/Blackstar/Caphalor/SphericalJoint.wmv
I'm sorry that the editor is in german, but only the last few seconds of the video are important, when I shoot at the two connected spheres.

betajaen

12-08-2007 16:15:30

100 is way to high. The default is 4, I was thinking 5 or 6.

But where is the joint placed, is it inside on of those spheres or where they meet?

Caphalor

12-08-2007 16:52:49

I misunderstood the sense of the anchor parameter completely, I now set the anchor to the body1 position and it worked. Thanks for the help. :D

Edit: http://dragoonmind.dk/data/Blackstar/Caphalor/SphericalJoints_working.wmv

betajaen

12-08-2007 17:25:32

Good to hear, and a good video. And excellent game/editor you have there.

Caphalor

12-08-2007 18:27:51

Another question: Are breakable joints implemented in 0.9? Because setBreakable is protected.

Caphalor

15-08-2007 13:03:39

I can't create a Joint between a dynamic and a static body. Nothing happens, but when I close my application, I get a standard windows error.

betajaen

15-08-2007 13:08:48

Just create a free standing joint then. The static actor will never move anyway.

Caphalor

15-08-2007 13:18:12

Wah, I just wanted to delete my Post. You are too fast. :D
I passed NULL as second actor and it works.
My chain still acts a little bit odd, but I think that's because of the swing and twist parameters.
Edit: http://dragoonmind.dk/data/Blackstar/Caphalor/Kette_PreFinal.wmv
:)

betajaen

15-08-2007 14:13:54

Glad to hear. The chain which is pretty well modelled infact, does seem a little odd there, perhaps you could increase the distance between each chain link?

Caphalor

18-12-2007 22:02:43

I'm programming a new editor (now using wxWidgets) and I'm currently re-implementing Joints.
Just create a free standing joint then. The static actor will never move anyway.
In my editor, the user is able to move a static body, and so the free standing joint should be moved together with the static body. Sadly, joint->setGlobalAnchor doesn't seem to work after the joint is created. Do you have a suggestion for me beside recreating the whole joint?

PS: Here is an "exclusive" screenshot of the new editor. :D

betajaen

18-12-2007 22:09:58

I read somewhere that if your going to connect a static to dynamic actor together using a joint, you shouldn't. You should connect it to to the Scene only (Null to Actor). It probably won't help you, but you can keep a reference to joints that are sort of connected to the static actor, and move them with the static actor afterwards.

p.s. Nice Screen shot. Dance will be better though. ;)