A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by 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.
-
Sascha Willems
- Moderator
-
- Posts: 346
- Joined: Fri Aug 27, 2004 10:18 am
- Location: Germany
-
by 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
-
aidave2
-
- Posts: 56
- Joined: Sun Jan 08, 2006 7:09 pm
-
by _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
by aidave2 » Thu Jan 26, 2006 10:04 pm
thats a good idea
-
aidave2
-
- Posts: 56
- Joined: Sun Jan 08, 2006 7:09 pm
-
by 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
-
aidave2
-
- Posts: 56
- Joined: Sun Jan 08, 2006 7:09 pm
-
by 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;
-
Sascha Willems
- Moderator
-
- Posts: 346
- Joined: Fri Aug 27, 2004 10:18 am
- Location: Germany
-
by aidave2 » Thu Mar 02, 2006 10:34 pm
thanks its working great now!!
saves some loading time
-
aidave2
-
- Posts: 56
- Joined: Sun Jan 08, 2006 7:09 pm
-
by 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
-
aidave2
-
- Posts: 56
- Joined: Sun Jan 08, 2006 7:09 pm
-
by 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?"
-
walaber
- Moderator
-
- Posts: 393
- Joined: Wed Mar 17, 2004 3:40 am
- Location: California, USA
-
by 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
-
aidave2
-
- Posts: 56
- Joined: Sun Jan 08, 2006 7:09 pm
-
by 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
by 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);
-
aidave2
-
- Posts: 56
- Joined: Sun Jan 08, 2006 7:09 pm
-
by 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.
-
Sascha Willems
- Moderator
-
- Posts: 346
- Joined: Fri Aug 27, 2004 10:18 am
- Location: Germany
-
by 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
-
aidave2
-
- Posts: 56
- Joined: Sun Jan 08, 2006 7:09 pm
-
by 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;
-
aidave2
-
- Posts: 56
- Joined: Sun Jan 08, 2006 7:09 pm
-
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 32 guests