|
Re: Newton 2 wrapper
[Re: VeT]
#225528
09/04/08 23:31
09/04/08 23:31
|
Joined: Oct 2006
Posts: 36
BigM
Newbie
|
Newbie
Joined: Oct 2006
Posts: 36
|
I am using the user input to move a corkscrew joint. This worked in 1.53; I'm not sure it works with 2.0 - a lot other bugs popped first and I haven't been able to properly test this part. I haven't looked up whether joint specific functions like NewtonCorkscrewGetJointVeloc are the same in 2.0 or if the callback is still passed a NewtonHingeSliderUpdateDesc argument. Initialization of the corkscrew joint elements:
thing = ent_create("model.mdl", vector(0, 1, 1), NULL);
nthing = newton_addentity(thing, .05, NEWTON_CONVEXHULL, NULL);
joint = NewtonConstraintCreateCorkscrew (nworld, vectorf(0, QUANTTOMETER*1, QUANTTOMETER*1), vectorf(1, 0, 0), nthing, NULL); //no need for an actual second body
NewtonCorkscrewSetUserCallback(joint, movement_callback); In the user input loop in main: sensitivity = 0.005; //this is used to scale the mouse movement to acceptable velocities.
actual_velocity = NewtonCorkscrewGetJointVeloc(joint);
target_velocity = mickey.y * sensitivity /(time_frame/16) //mickey.y is given by the engine
acceleration = (target_velocity - actual_velocity)/(time_frame/16) In callback: movement_callback (const NewtonJoint* joint, NewtonHingeSliderUpdateDesc* desc){
desc[0].m_accel = acceleration; //the NewtonHingeSliderUpdateDesc struct was provided, as is, by the wrapper in 1.53
retCode |= 1; //or with 0x01 to tell newton this axis is active. Don't know if it is still required in 2.0
}
Hope this clears things up! Anyway, the concept of using PROC_LATE does not depend on any actual implementation of user input processing or callback code: time_frame values used in main and in callbacks will be different if there is a screen update in between. The slicing woks exactly as you re-wrote, but don't cast advance as an 'int'; it must be a 'float'. The objective is that you gain control of how many times Newton is updated and how long the slices are. The NewtonSetMinimumFrameRate function let you set the same limit; however, in my case, it turned out that the several sub-splittings automatically made by the newton engine would not add up to the passed update time, and so I created my own slicing.
|
|
|
Re: Newton 2 wrapper
[Re: VeT]
#226019
09/07/08 11:14
09/07/08 11:14
|
Joined: Aug 2004
Posts: 1,345 Kyiv, Ukraine
VeT
OP
Serious User
|
OP
Serious User
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
|
oops, i found bug in v.9, so i decide to wrap quickly one of the simplest examples, but with comments in every step v.10 - found bug in map11 with uncorrect action name, fixed - added map16 - Customizing Sphere(step-by-step creation of body) - espeshially for beginners yes, i forgot to say that i wouldn't going to wrap levels like "tower" or "pyramide" as they are usefull only as demonstration of NewtonPlayGround, i dont think that they include nessesary and new info for users... but if somebody wants to see level like this in Gamestudio, you can write to me
|
|
|
|