Page 2 of 3

Posted: Mon Jan 16, 2006 2:39 pm
by zenoid
I have my porting from 1.35 to 1.5 working flawlessly. I run vehicle joint and other body without any problem. I'am actualy porting the new tractor from the customjoint to irr. My only pb is irr 0.14 that do not pass my heighmap to newton as it did.
hope it helps

Posted: Tue Jan 17, 2006 7:56 am
by Nick_Japan
Could I ask you to post your code? I'll trade for a Newton Helicopter ;)

Posted: Tue Jan 17, 2006 8:58 am
by zenoid
I wont post here as my vehicle code falls in two files ; .h and .c++ class and is not very clear I think and long.
In the class I'am loading the vehicle profile from a xml file, the name of the file is passed as parameter and come from a listbox selected item.
In the constructor, the xml file(the selected item) give the chassis mesh, wheel mesh , sound file path and names. All parameters for the vehicle geometry ; number of wheels, there positions, the performances are all in this file also.
Plus there is lot to do to clear the code and add the other features I want.
But I want to help you, tell were are you now on this issue.

Posted: Thu Jan 19, 2006 11:08 am
by Nick_Japan
At the moment, It seems that the basic problem is that the tyre callback never gets called. When creating the car body, I set the ForceAndTorque callback to just apply gravity to the car body. This works fine - the car falls and lands on my test surface.

This is the tyre setup code, where it is added to the vehicle joint:

Code: Select all

	f32 tireMass; 
	f32 tireSuspensionShock;
	f32 tireSuspensionSpring; 
	f32 tireSuspensionLength;


	// set tire values
	tireMass = 2.0f; 
	tireSuspensionShock = 160.0f;
	tireSuspensionSpring = 7500.0f; 
	tireSuspensionLength = 0.02f;

	// create the tyre's position (these coords were passed to us from assembleCarPhysics)
    matrix4 tyrepos;
    tyrepos.setTranslation(vector3df(xpos, ypos, zpos));

    // the tire will spin around the lateral axis of the same tire space
	vector3df tirePin (0.0, 0.0, 1.0f);
    
	// add the tire and set this as the user data
    // nb NULL should be the parent vehicle joint

	NewtonVehicleAddTire (vehicle, &tyrepos.M[0], vecToArray(tirePin), tireMass, width, radius, tireSuspensionShock, tireSuspensionSpring, tireSuspensionLength, wheelpointer, tyreid);
This is the callback function passed to NewtonVehicleSetTyreCallback():

Code: Select all

    printf("in wheel callback\n");
    void *wheelid = 0;
    for(wheelid = NewtonVehicleGetFirstTireID(vehicle); wheelid; wheelid = NewtonVehicleGetNextTireID(vehicle, wheelid))
    {
        CPhysicsCarWheel *wheel = (CPhysicsCarWheel *)NewtonVehicleGetTireUserData(vehicle, wheelid);
        wheel->setTirePhysics(vehicle, wheelid);
    }
and this is wheel->setTirePhysics():

Code: Select all

	f32 omega;
	f32 speed;
	f32 brakeAcceleration;


	dFloat currSteerAngle;

	currSteerAngle = NewtonVehicleGetTireSteerAngle (vehicle, id);
	NewtonVehicleSetTireSteerAngle (vehicle, id, currSteerAngle +  (steerangle - currSteerAngle) * 0.25f);


    // this is pretty much all from the newton vehicle demo - not quite sure what it's all doing i'm afraid

	// get the tire angular velocity
    // NULL should be the parent's vehicle joint
	omega = NewtonVehicleGetTireOmega (vehicle, id);

    
	// add some viscuos damp to the tire torque (this prevent out of control spin
    printf("torque = %f\n", torque);
	NewtonVehicleSetTireTorque (vehicle, id, torque - 0.1f * omega);

	// calculate the tire speed at the contact
	// set the max side slip speed as a fraction of the tire spm
	speed = radius * omega;
	NewtonVehicleSetTireMaxSideSleepSpeed (vehicle, id, speed * 0.1f);

	// The side slip is usually propostinal to the tire longitudilnal speed, and tire load
	NewtonVehicleSetTireSideSleepCoeficient (vehicle, id, speed * 0.05f);

    
	// if brake are applyed ....
	if (brakes > 0.0f) {
		// ask Newton for the precise acceleration needed to stop the tire
		brakeAcceleration = NewtonVehicleTireCalculateMaxBrakeAcceleration (vehicle, id);

		// tell Newton you want this tire stoped but only if the trque need it is less than 
		// the brakes pad can withstand (assume max brake pad torque is 500 newton * meter)
		NewtonVehicleTireSetBrakeAcceleration (vehicle, id, brakeAcceleration, 500.0f * brakes);

		// set some side slipe as funtion of the linear speed 
		speed = NewtonVehicleGetTireLongitudinalSpeed (vehicle, id);
		NewtonVehicleSetTireMaxSideSleepSpeed (vehicle, id, speed * 0.1f);
	}
	// Reset the brakes
	brakes = 0.0f;
As you can see, this is largely unchanged from my original vehicle tutorial code, but I've not read any major changes that you need to make to port to 1.5. The printf() function in my tyre callback never gets run, so that means that for some reason the wheels are not being updated. I've looked into the Newton world size changes and the vehicle is definitely still inside the world. I also call NewtonBodySetAutoFreeze(carbody, 0) when the vehicle is created, so I don't think it's an autofreeze problem. Answers on a postcard! Cheers

Posted: Tue May 16, 2006 5:18 pm
by bicunisa
Anyone got this sorted out yet?

I would like to know if anyone has implemented Newton 1.52 with Irrlicht 1.0. Thanks!

Posted: Wed May 17, 2006 9:02 am
by zenoid
I'am in the course of making a tractor/forest harvester vehicle sim using newton/irr (plus SDL/openAL). I'am still blocked on the terrain issue. All has been working fine since then ; i was using newt 1.50/irr 0.12 and now facing pb passing the terrainSceneNode trough the newton world build. I know it's a pb of world size : I got a frozen newton world and it certainly is a problem in my coding.

Exept that port pb, I've used the newton vehicle container a lot (it's a 4*4 land rover in my sim) without any pb.

So I hope I will soon have time to clear that pb.

Posted: Wed May 17, 2006 1:49 pm
by andrei25ni
The problem here is that some tutorial are not beeing updated. For example the Mercior tut, and now this great tut with vehicle. It is true that they explain the basics for us noobs, but what good are they if we can't use them?

So my request is, if someone succeded in making this tutorial work with the latest libs and dll's from Irrlicht and Newton, please post the code here, or at least tell us what bits of code must be changed.

The purpose of tutorials is to help us learn faster, step-by-step what we need to know.

Cheers

Posted: Thu Jul 13, 2006 11:26 am
by BlindSide
This code compiles in 1.0 flawlessly, as for the car, well this is more of an engineering thing than coding but I made it Four Wheel Drive so its more durable.

Like so:

Code: Select all

void driveCar(CComponentBus *bus)
void driveCar(CComponentBus *bus)
{
    if(bus->physics->PLAYER_MOVE_FORWARDS)
    {
        bus->physics->car->wheel_RL->torque = 25.0f;
        bus->physics->car->wheel_RR->torque = 25.0f;
        bus->physics->car->wheel_FL->torque = 25.0f;
        bus->physics->car->wheel_FR->torque = 25.0f;
    }
    else if(bus->physics->PLAYER_MOVE_BACKWARDS)
    {
        bus->physics->car->wheel_RL->torque = -25.0f;
        bus->physics->car->wheel_RR->torque = -25.0f;
        bus->physics->car->wheel_FL->torque = -25.0f;
        bus->physics->car->wheel_FR->torque = -25.0f;
    }
    else if(!bus->physics->PLAYER_MOVE_BACKWARDS && !bus->physics->PLAYER_MOVE_FORWARDS)
    {
        bus->physics->car->wheel_RL->torque = 0.0f;
        bus->physics->car->wheel_RR->torque = 0.0f;
        bus->physics->car->wheel_FL->torque = 0.0f;
        bus->physics->car->wheel_FR->torque = 0.0f;
    }

    if(bus->physics->PLAYER_STRAFE_LEFT)
    {
        bus->physics->car->wheel_FL->setSteer(-0.5f);
        bus->physics->car->wheel_FR->setSteer(-0.5f);
    }
    else if(bus->physics->PLAYER_STRAFE_RIGHT)
    {
        bus->physics->car->wheel_FL->setSteer(0.5f);
        bus->physics->car->wheel_FR->setSteer(0.5f);
    }
    else if(!bus->physics->PLAYER_STRAFE_LEFT && !bus->physics->PLAYER_STRAFE_RIGHT)
    {
        bus->physics->car->wheel_FL->setSteer(0.0f);
        bus->physics->car->wheel_FR->setSteer(0.0f);
    }
}
Note it became too fast once I did this so I reduced some of the torque values to compensate. Have a play around this is good stuff!

Posted: Wed Jul 26, 2006 5:47 pm
by Zeuss
I dont know if people have been suffering with this, or whether it has been fixed.

It has me completely stumped. My current project is a bit of a mish-mash of the tutes and Nick_Japan's demo.

I have collision between boxes and the ground. But the vehicle just drops straight through it. I'm using Newton 1.53. But I would be happy to use 1.35 but can't seem to find a copy to use :'(.

But as far as I can tell, all my call-backs are being called and it should all be working. Any help would be appreciated.

Posted: Thu Jul 27, 2006 7:11 am
by Zeuss
Huzza, nevermind its all good. Got it all working properly and cool.

I might make up a tutorial/sample code if anyone is interested.

Posted: Fri Jul 28, 2006 5:32 am
by andrei25ni
Yes we are interested ! :D

Posted: Sat Jul 29, 2006 7:32 am
by Zeuss
Ok, I have an example all done. But my webhosting has gone down.

Anyone know of a place i can upload it too?

Posted: Sun Jul 30, 2006 7:20 am
by Zeuss
Yay webhost fix. :)

http://caswal.com/irrlicht/Newton%20Veh ... xample.rar

Thanks to Nick_Japan and mercior for the tutorials they provided. It saved me a lot of time than trying to write it all from scratch.

Its all on Irrlicht 1.0 and Newton 1.53 so you will need those dlls, libs and header files. I have also left my Visual 2005 Express project/solution files in there for anyone who uses it.

The Impreza is taken from: http://modelsbank.3dm3.com/details.php? ... ode=search

So all credit to valcoey and my friend drewk for exporting and scaling it for me.

Have fun, feel free to ask any questions u guys have.

I also know this doesnt clean-up and of newtons stuff on the vehicles after it is done. This is all just example code.

Posted: Sun Jul 30, 2006 3:30 pm
by dawasw
Lol man thats pro.

It's not only the great working vehicle tutorial but also terrain tutorial (for those who didnt find any earlier)

Great job Zeuss

Posted: Mon Jul 31, 2006 3:46 am
by Zeuss
Oh yeah, and If you take a look at the vehicle assemble function or the make ramp function.

It generates a proxy mesh for newton from there irrlicht meshes. So you can have a ramp instead of just colliding with a box.

Right click fires the ramps, space bar drops one.

Im currently working on getting a system to deform the car when it hits something hard, we'll see how that goes.