|
Re: [Newton] How to do some things with Newton
[Re: vartan_s]
#85761
08/13/06 16:01
08/13/06 16:01
|
Joined: Jul 2006
Posts: 783 London, UK
sheefo
User
|
User
Joined: Jul 2006
Posts: 783
London, UK
|
This is how I made ball movement. It was mostly taken from the example (although I had to work most of it out myself): Code:
var force[3]; function movement_forces(body) { var bodyMass; bodyMass = NewtonGetBodyMass(body); NewtonBodyAddForce(body, 0, 0, bodyMass * (newtonGravity + force.z)); NewtonBodyAddTorque(body, bodyMass * my.move_vec_x, bodyMass * my.move_vec_y, bodyMass * my.move_vec_z); } //////////////////////////////////////////////////////////// // Player Initialization //////////////////////////////////////////////////////////// define move_vec_x, skill98; define move_vec_y, skill99; define move_vec_z, skill100; action initialize_player { player = my;
var body; my.collision_sph_box = on; // sphere? my.mass = 10; my.linear_drag = 0.1; my.angular_drag_x = 0.1; my.angular_drag_y = 0.1; my.angular_drag_z = 0.1; my.start_active = on; my.shape_factor = 0.9; // density NewtonCreateGravityEntity(ivory_material); dll_handle = newtonHandle;
body = NewtonGetBody(my); NewtonSetBodyAutoActiveState(body, 0); NewtonSetBodyActiveState(body, 1); // asign a special force event to the rover NewtonSetBodyForceAndTorque(body, movement_forces);
while(1) { vec_set(my.move_vec_x, nullvector); vec_set(force, nullvector); my.move_vec_x = key_cur - key_cul; my.move_vec_y = key_cuu - key_cud; if(key_space) { force.z = 1000; } //vec_rotate(my.move_vec_x, vector(camera.pan, 0, 0)); vec_normalize(my.move_vec_x, 100); wait(1); } }
|
|
|
Re: [Newton] How to do some things with Newton
[Re: sheefo]
#85762
08/13/06 18:32
08/13/06 18:32
|
Joined: Apr 2006
Posts: 265
vartan_s
OP
Member
|
OP
Member
Joined: Apr 2006
Posts: 265
|
Thanks a lot. Unfortunately, I don't know enough to understand it. eg: Code:
NewtonBodyAddForce(body, 0, 0, bodyMass * (newtonGravity + force.z)); NewtonBodyAddTorque(body, bodyMass * my.move_vec_x, bodyMass * my.move_vec_y, bodyMass * my.move_vec_z); I don't really know what the parameters between the brackets mean... if you could help me out by explaining to me the useful functions for newton I'd be greatful. Thanks.
|
|
|
Re: [Newton] How to do some things with Newton
[Re: vartan_s]
#85763
08/13/06 18:54
08/13/06 18:54
|
Joined: Jul 2006
Posts: 783 London, UK
sheefo
User
|
User
Joined: Jul 2006
Posts: 783
London, UK
|
Well, I don't know but here’s my guess: This is meant to be the direction of gravity, the first argument is the object, and then the last three are the xyz vector stuff. You can add wind blowing it off a ledge with this. Code:
NewtonBodyAddForce(body, 0, 0, bodyMass * (newtonGravity + force.z));
The same applies with this, but this is the movement of the object. It uses user-defined skill vectors, 'move_vec_x', 'move_vec_y' and 'move_vec_x' for the direction relitive to the object. Its maths is simple, BodyMass * move_vec, so it’s weight can effect its movement speed. Code:
NewtonBodyAddTorque(body, bodyMass * my.move_vec_x, bodyMass * my.move_vec_y, bodyMass * my.move_vec_z);
This is just what I think it is, I may be wrong. But it appears to make sense. I hope that was of some help to you...?
|
|
|
|