Official Pascal-Header (SDK 1.53), last update 26.05.2006

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: OOPs i did it again

Postby Sascha Willems » Thu Jan 26, 2006 7:16 am

aidave2 wrote:Is there a way to pass a procedure of a class to the callbacks?


Sadly not, or at least not that I know off. I spent hours (or days) trying to get that working, but after searching through dozens of google search results and trying everything I had in mind, I gave up. So for my biggest project (NewtonPlayGround) I have just moved all the callbacks into a separate unit, so at least it looks half-way clean.
User avatar
Sascha Willems
Moderator
Moderator
 
Posts: 346
Joined: Fri Aug 27, 2004 10:18 am
Location: Germany

Re: OOPs i did it again

Postby aidave2 » Thu Jan 26, 2006 11:32 am

Sascha Willems wrote:Sadly not, or at least not that I know off. I spent hours (or days) trying to get that working, but after searching through dozens of google search results and trying everything I had in mind, I gave up. So for my biggest project (NewtonPlayGround) I have just moved all the callbacks into a separate unit, so at least it looks half-way clean.


doh. It makes sense in a way, because the object may change or get deleted, by the time the callback is run. That would be bad..

In order to get around this, I'm trying this solution:
I am inheriting from an object class I made called AIRNewtonObject. When the callback is set, I put the assignment inside a virtual method like so:

Code: Select all
AIRNewtonObject.Create;
begin
  inherited Create;
  SetForceAndTorqueCallBack;
end;

// override this to set descendant callbacks
AIRNewtonObject.SetForceAndTorqueCallback; //virtual;
begin
    NewtonBodySetForceAndTorqueCallBack(NewtonBody, OnGeneralForceTorque);
end;


Any descendants can set their own callback properly, although the callback procedure is not in the class, it is a bit closer to OO

8)
User avatar
aidave2
 
Posts: 56
Joined: Sun Jan 08, 2006 7:09 pm

Postby _Tux_ » Thu Jan 26, 2006 1:59 pm

instead of having loads of callbacks for each class (gets a bit messy), you could try this...

set the body's user data as the class
set the callback to the general callback
in the general callback get the userdata and typecast it to the class and call a procedure in that class for the callback.

loosing a little bit of OO but it should work nicely :)
_Tux_
 
Posts: 81
Joined: Wed Sep 08, 2004 10:38 am
Location: UK

Postby aidave2 » Thu Jan 26, 2006 10:04 pm

thats a good idea :idea:
User avatar
aidave2
 
Posts: 56
Joined: Sun Jan 08, 2006 7:09 pm

serialize

Postby aidave2 » Thu Mar 02, 2006 7:09 pm

hi are there any examples of using
NewtonTreeCollisionSerialize
and
NewtonCreateTreeCollisionFromSerialization

im trying to use these with Delphi and am a little stumped.
im not sure how to convert this into Delphi:
Code: Select all
void SerialiseTree(void* serializeHandle, const void* buffer, size_t size)
{
   fwrite(buffer, size, 1, (FILE *)serializeHandle);
}

procedure NewtonSerializeCallback( serializeHandle : Pointer; const buffer : Pointer; size : size_t ); cdecl;
begin
  ?
end;


take it easy!
dave
User avatar
aidave2
 
Posts: 56
Joined: Sun Jan 08, 2006 7:09 pm

Postby Sascha Willems » Thu Mar 02, 2006 7:15 pm

Just use a FileStream, it's very easy :
Code: Select all
procedure NewtonSerializeCallback(serializeHandle : Pointer; const buffer : Pointer; size : size_t ); cdecl;
begin
TFileStream(SerializeHandle).WriteBuffer(Buffer^, Size);
end;

procedure NewtonDeSerializeCallback( serializeHandle : Pointer; buffer : Pointer; size : size_t ); cdecl;
begin
TFileStream(SerializeHandle).ReadBuffer(Buffer^, Size);
end;
User avatar
Sascha Willems
Moderator
Moderator
 
Posts: 346
Joined: Fri Aug 27, 2004 10:18 am
Location: Germany

Postby aidave2 » Thu Mar 02, 2006 10:34 pm

thanks its working great now!!

saves some loading time

8)
User avatar
aidave2
 
Posts: 56
Joined: Sun Jan 08, 2006 7:09 pm

Postby aidave2 » Thu Mar 09, 2006 3:03 am

in this record,

PNewtonHingeSliderUpdateDesc = ^NewtonHingeSliderUpdateDesc;
NewtonHingeSliderUpdateDesc = record
m_accel : float;
m_minFriction : float;
m_maxFriction : float;
m_timestep : float;
end;

is this only for linear?
how do i access the omega m_accel?

in the callback,
function CorkscrewCallBack(const corkscrew : PNewtonJoint; desc : PNewtonHingeSliderUpdateDesc ) : Unsigned_int; cdecl;

according to this thread, it should have two m_accel:
http://newtondynamics.com/forum/viewtop ... =corkscrew


+vibes,
dave
User avatar
aidave2
 
Posts: 56
Joined: Sun Jan 08, 2006 7:09 pm

Postby walaber » Thu Mar 09, 2006 3:18 am

the corkscrew and universal use a pointer to an array of 2 of those.

so in C/C++ its desc[0] for the first axis of the joint, and desc[1] for the 2nd axis.
Independent game developer of (mostly) physics-based games. Creator of "JellyCar" and lead designer of "Where's My Water?"
User avatar
walaber
Moderator
Moderator
 
Posts: 393
Joined: Wed Mar 17, 2004 3:40 am
Location: California, USA

Postby aidave2 » Thu Mar 09, 2006 4:11 pm

walaber wrote:the corkscrew and universal use a pointer to an array of 2 of those.

so in C/C++ its desc[0] for the first axis of the joint, and desc[1] for the 2nd axis.


hmm i realize that, but i cant get access to the 2nd array item

+ ~~
dave
User avatar
aidave2
 
Posts: 56
Joined: Sun Jan 08, 2006 7:09 pm

Postby Cochrane » Thu Mar 09, 2006 5:24 pm

My Pascal/Delphi knowledge isn't the best, but I think it should work if you have a variable like
Code: Select all
secondDesc : PNewtonHingeSliderUpdateDesc
in your function and set that using
Code: Select all
secondDesc := desc + 1;
Cochrane
 
Posts: 3
Joined: Mon Sep 05, 2005 10:41 am

Postby aidave2 » Sun Mar 12, 2006 6:04 pm

The +1 didnt do it but inc works!

Code: Select all
  desc2: PNewtonHingeSliderUpdateDesc;
   desc2 := desc;
   inc(desc2);


:)
User avatar
aidave2
 
Posts: 56
Joined: Sun Jan 08, 2006 7:09 pm

Postby Sascha Willems » Mon Mar 13, 2006 8:41 am

Just updated the header to NGD 1.52. Only two small changes :

Code: Select all
   + NewtonWorldForEachBodyInAABBDo             : Function added
   - NewtonCreateConvexHull                     : Added consts to pointer params     


So if needed please update your headers.
User avatar
Sascha Willems
Moderator
Moderator
 
Posts: 346
Joined: Fri Aug 27, 2004 10:18 am
Location: Germany

Postby aidave2 » Sun Apr 09, 2006 3:26 am

Hi are there any examples of this:

NewtonUserJointAddLinearRow

been making joints and am trying to make custom ones now.
But any values I pass to it gives me access violations.

trying to make a rigid joint.


edit: nm, i was trying to use this after joint was created. i found it works only in the callback!


cheers dave
User avatar
aidave2
 
Posts: 56
Joined: Sun Jan 08, 2006 7:09 pm

Postby aidave2 » Fri Apr 14, 2006 1:27 pm

hey Sascha,

how do you get the full 3 normal values from the ray cast callback?

function ClosestWorldRayCastCallBack(
const ABody: PNewtonBody;
const AHitNormal: PFloat;
ACollisionID: Int;
AUserData: Pointer;
AIntersectParam: Float): Float;
User avatar
aidave2
 
Posts: 56
Joined: Sun Jan 08, 2006 7:09 pm

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 4 guests

cron