Author Topic: trying to understand the Car sample 2  (Read 2329 times)

Offline athanazio

  • byte
  • *
  • Posts: 49
    • View Profile
    • http://www.athanazio.pro.br
trying to understand the Car sample 2
« on: November 21, 2006, 06:04:28 pm »
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 ? :)

Code: [Select]

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);

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
trying to understand the Car sample 2
« Reply #1 on: December 06, 2006, 08:46:10 pm »
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~?

Offline athanazio

  • byte
  • *
  • Posts: 49
    • View Profile
    • http://www.athanazio.pro.br
trying to understand the Car sample 2
« Reply #2 on: December 06, 2006, 11:57:45 pm »
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.

Offline manumoi

  • long
  • ***
  • Posts: 121
    • View Profile
    • http://www.iro.umontreal.ca/~blanchae
trying to understand the Car sample 2
« Reply #3 on: December 07, 2006, 05:23:43 am »
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:
Code: [Select]

translate(0, -10, 0);

Then, you have those lines :
Code: [Select]

  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