trying to understand the Car sample 2

Started by athanazio, November 21, 2006, 06:04:28 PM

Previous topic - Next topic

athanazio

another detail in the sample that is not clear for me is how come the car go over the surface of the terrain ? is this because of the collision definition of the terrain ?

this is the piece of code that I think is doing the "magic"... am I correct, if so how ? :)


OcTree oc=new OcTree(terrain,50,OcTree.MODE_OPTIMIZED);
terrain.setOcTree(oc);
oc.setCollisionUse(OcTree.COLLISION_USE);

Config.collideOffset=250;

terrain.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
terrain.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);

Mizuki Takase

So sorry that I am not at a place that I can read the car sample code. However, I recalled that there was some sort of Car class that did some placement work; detecting the angle of which the car's main body had to be placed... The code that you have shown on the forum also have something to do with the detection as well... Its like the car is checking if it would collide onto the terrain or something...

Off topic! I am curious now! Are you making some sort of car game? With rearview mirror and question with the car sample, one would come to that conclusion... Right~?

athanazio

hehehehe,
no car game, just trying to cover the concepts of an generic game, as I'm learning all about this new world :)

but ... to reveal the secrets ... me and some other 2 are planning to begin the matrix, and those models will be projected inside the freezing humans :)

moving from my crazy side, we are planning a game for the new year, something about simulation, working on the story and some game details now.

manumoi

for what i understand (and i did something that works more or less correctly), what you are looking for is located in the "place" method of the car class



By default, the car is located 10 upper than its last position with the following call:

translate(0, -10, 0);

Then, you have those lines :

 float rightFrontHeight=ground.calcMinDistance(rightFront.getTransformedCenter(), dropDown, 4*30);
     float rightRearHeight=ground.calcMinDistance(rightRear.getTransformedCenter(), dropDown, 4*30);
     float leftFrontHeight=ground.calcMinDistance(leftFront.getTransformedCenter(), dropDown, 4*30);
     float leftRearHeight=ground.calcMinDistance(leftRear.getTransformedCenter(), dropDown, 4*30);


Each of the value obtained determine the distance between one of the wheel of the car and the ground...

The rest of the place method will consist in dropping down the car until each wheel collide with the ground... (as expressed by the lines you gave before). If i remenber, the angle will be used to orientate the body of the car but not so sure of that... Egon will probably complete it with his "magical expanations" :P