Author Topic: get angle from objects  (Read 2130 times)

Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
get angle from objects
« on: November 25, 2012, 09:38:48 pm »
Here's a problem I'm having.

I want a car to align to a surface. so what I've got is 4 dummy objects that are in position of the wheels.
These dummies are always on the ground polygon where the wheels intersect the ground.
That all works fine but how do I align my car to the angle created by these?

I've got this (forward angle only) but it doesnt quite work:
Code: [Select]
forward_angle = collision_fr_dummy.getTransformedCenter().calcAngle(collision_fl_dummy.getTransformedCenter()););
player_vectortest_matrix = player.getRotationMatrix();

if (player_vectortest_matrix.getYAxis().z > forward_angle) {
car_angle_current_frame.z = forward_angle;
} else if (player_vectortest_matrix.getYAxis().z < forward_angle) {
car_angle_current_frame.z = -forward_angle;
} else {
car_angle_current_frame.z = 0;
}

player.rotateZ(car_angle_current_frame.x*2);


any help much appreciated

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: get angle from objects
« Reply #1 on: November 25, 2012, 09:53:02 pm »
The car example that comes with desktop jPCT does something like that...maybe it's worth a look. It might not be applicable directly, but maybe it gives some ideas. You should find the code in the place()-method of the Car class.