Fiddling with friction and f-ing it all up...

Langhole

21-03-2007 00:49:39

Okeedoke, Hi there I'm langford.. been reading the forums a while now, and experimenting with the wicked awesome ogre rendering engine.. recently I've been playing a bit with OgreNewt. I've got a 'milestone' due in a couple days, need to show off a bit of what I've learned thus far, and I'd really like to have a vehicle in there..

I extended the OgreNewt::Vehicle class (by re-writing and tweaking the SimpleVehicle example class) and I made 'MyVehicle' which is located in it's own header. Everything worked fine until I added the vehicle class, and tried to initialize it, then when I compiled, I got this error:

------ Build started: Project: Langframe, Configuration: Release Win32 ------
Compiling...
Langframe.cpp
Linking...
Langframe.obj : error LNK2001: unresolved external symbol "public: __thiscall MyVehicle::MyVehicle(class Ogre::SceneManager *,class OgreNewt::World *,class Ogre::Vector3 &,class Ogre::Quaternion &)" (??0MyVehicle@@QAE@PAVSceneManager@Ogre@@PAVWorld@OgreNewt@@AAVVector3@2@AAVQuaternion@2@@Z)
bin\Release\Langframe.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://e:\Angry Man\C++ Projects\Langframe\Langframe\obj\Release\BuildLog.htm"
Langframe - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


I'm not sure 'which' code to put up here to help solve my problem, and I think I've included all the needed directories for libraries/includes, and set up the dependencies correctly... as I said I've not had many problems up to this point that I haven't been able to fix.. I'm just at a loss as to what to do about this linker error... I'd appreciate any help.

Thanks :)

Langhole

21-03-2007 23:59:08

Ok, scratch all the previous...

I've got a vehicle working fine now (using the SimpleVehicle setup)

Now I want to implement a gearbox and increase the friction between the ground and the tires.


Here I set up a material for the ground, and the material pair for the friction.

OgreNewtonApplication.h


class OgreNewtonApplication :
public ExampleApplication
{
public:
OgreNewtonApplication(void);
~OgreNewtonApplication(void);

OgreNewt::MaterialID* defMat;
OgreNewt::MaterialPair* mPair;

...




Here I set up the material for m_chassis

SimpleVehicle.h


class SimpleVehicle :
public OgreNewt::Vehicle
{
public:

OgreNewt::MaterialID* vehMat;

...



In the SimpleVehicle constructor I give the material it's value, and apply it in the Setup() function to m_chassis.

SimpleVehicle.cpp


SimpleVehicle::SimpleVehicle(Ogre::SceneManager* mgr, OgreNewt::World* world, Ogre::Vector3& position, Ogre::Quaternion& orient) : OgreNewt::Vehicle()
{
// save the scene manager
mSceneMgr = mgr;
mWorld = world;

vehMat = new OgreNewt::MaterialID(mWorld);



..

void SimpleVehicle::setup()
{
// okay, we have the main chassis all setup. let's do a few things to it:
m_chassis->setStandardForceCallback();
// we don't want the vehicle to freeze, because we'll be unable to control it.
m_chassis->setAutoFreeze(0);

// apply a mat
m_chassis->setMaterialGroupID(vehMat);

...



In the application's constructor I create the material, and in the createScene() function I apply it to the floor body, and set the friction in the material pair.

OgreNewtonApplication.cpp


OgreNewtonApplication::OgreNewtonApplication(void)
{
// create OgreNewt world.
m_World = new OgreNewt::World();
defMat = new OgreNewt::MaterialID(m_World);
//mPair->setDefaultFriction(0.0f, 0.0f);
}



...

bod->setMaterialGroupID(defMat);
mPair = new OgreNewt::MaterialPair(m_World, defMat, mCar->vehMat);
mPair->setDefaultFriction(0.0f, 0.0f);

...



I compile and cross my fingers, and it works, except the friction part.

I have a sneaking suspicion that "mPair = new OgreNewt::MaterialPair(m_World, defMat, mCar->vehMat);" should be somewhere else, like the OgreNewtonApplication constructor, and/or "mPair->setDefaultFriction(0.0f, 0.0f);"

However, when I put one or both of those in the constructor I get the debugger popping up (which doesn't want to work for me anyway or else I'd actually debug it) and the App don't work.

All I want is a little friction :( anyone have any ideas?

PS. For anyone wondering why when I want friction it's set to 0.0f, that's for testing purposes only. If there's no friction at all, obviously it's working.

walaber

22-03-2007 05:29:10

i assume you're creating the vehicle before you create the MaterialPair?

Langhole

22-03-2007 09:24:38

Hmm, I'm not entirely sure exactly 'what' was causing the problem, but I've solved it finally :) thanks to reading the many posts on this forum about friction using OgreNewt. I also did a solid review of demo 5, and did a run-through of certain files in the Stunt Playground source... I knew the theory behind it, but I'm still making the transfer from Actionscript back to C++ :s

I figured it out though, here's what I've come up with for anyone who has the same problem, disorganization :P


void OgreNewtonApplication::createMats(OgreNewt::Body* body1, OgreNewt::Body* body2)
{
OgreNewt::MaterialID* mat1 = new OgreNewt::MaterialID(m_World);
OgreNewt::MaterialID* mat2 = new OgreNewt::MaterialID(m_World);
OgreNewt::MaterialPair* matPair = new OgreNewt::MaterialPair(m_World, mat1, mat2);

body1->setMaterialGroupID(mat1);
body2->setMaterialGroupID(mat2);
matPair->setDefaultFriction(1.4f, 1.4f);
}


Basically, I made a meeting place for the 2 bodies, and applied the mats to them there, and set the friction there as well (though I'm not sure if I need to set the friction here or not, I'm just playing it safe i guess).

This worked great! I set my friction to 2.0 and my car was flipping instead of sliding like usual, I'm very happy now that I've fixed my problem, and learned a little about materials in the process ;)

Thx walaber for OgreNewt, it's freakin' sweet!

New question: Since I'm using the SimpleVehicle example for the time being, I grabbed the GT.mesh from the stunt playground, and the wheel, to play with instead of that wicked looking box that yeh start out with. I've run into a problem... The car is created facing the wrong way, and I've tried everything I can think of to rotate it, nothing is working :( Possibly a solution out there that anyone can nudge me toward?

Langhole

22-03-2007 09:58:37

Ok then... I did a little math, drew up a little graph, figured out how exactly the wheels are configured, kinda tricky at first ya gotta admit ;)


tirepos = (offset * Ogre::Vector3((x * -1),0.5f,z) - Ogre::Vector3(0.9,-0.5,0));


May look a bit wierd to some of you, but I had to tweak the positioning a bit, and this is the only way I could find, I'm sure it doesn't really create any problems, after all it's just the initial position of the tires... this coupled with my previous "rear-wheel-drive" accident, I've now got a front-wheel drive, GT, facing the right way, set up via SimpleVehicle (tweaked edition) lolz.

I'm sure I'll have other questions fairly soon, but for now, it's time to start playing with my own meshes, maybe actually create a nice looking scene to fit my car and terrain into... maybe even start planning a game :o who knows...

Anyway I'd like to thank anyone on this forum who ever discussed problems like mine above, you've helped solve me a lot of little problems :)

walaber

23-03-2007 02:17:03

glad you got it working. don't be shy to dig into the Stunt Playground source whenever you need to, I released it for a reason :)

Langhole

23-03-2007 08:44:11

I understand ;)

I'm going through the source bit by bit as I get more inside the workings of OgreNewt, and even Ogre in general. I will be implementing some custom meshes and rendering effects next, then I'll get back to more of the physics side of things... that is, after I finish this gearbox hehe. I just can't seem to get away from the vehicle for some reason...

Anyway, thx for releasing that source dude, helps a ton. I'm even learning some things about the GUI, and materials 8)

Time to get down to business...