A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Stucuk » Fri Mar 06, 2009 12:11 pm
While there is still quite a bit to convert below is a link to the current version of the 2.0 Headers iv been working on. Which is based on the 1.53 headers.
Newton2.0BetaHeaders_WIP_06-03-09.rar ~57KB
-
![User avatar](./download/file.php?avatar=575_1233522237.jpg)
Stucuk
-
- Posts: 801
- Joined: Sat Mar 12, 2005 3:54 pm
- Location: Scotland
-
by JernejL » Sat Mar 07, 2009 1:46 pm
After building a game engine using newton betas i am left with a lot of serialized compound collisions made of convex hulls that need converting to new newton version, so i came up with a plan, to use NewtonCollisionGetInfo to get pointers to all collisions that make the compound, then i use NewtonCollisionForEachPolygonDo to access the vertex cloud, and re-create the convex hulls with the new newton version.
It doesn't work right, the vertices i get aren't the vertices i sent (because NewtonCreateConvexHull returns null, and the data in hex editor looks wrong) but i assume the problem is in the NewtonCollisionForEachPolygonDo callback function:
- Code: Select all
procedure Newpolies(const userdata: pointer; vertexCount: integer; const FaceArray: PFloat; faceId: integer); cdecl;
begin
Tmemorystream(userdata).Write( facearray^, vertexCount * 12);
vcnt:= vcnt + vertexCount;
end;
Does anybody have any idea what i'm doing wrong? i don't know the right "pointer wrestling" so that memorystream would write the right data.
EDIT: nevermind, i fixed, first i write sizeof blank bytes and overwrite it it using:
- Code: Select all
CopyMemory( pointer(integer(Tmemorystream(userdata).memory) + Tmemorystream(userdata).Position - vertexCount * 12),
FaceArray, vertexCount * 12
);
-
![User avatar](./download/file.php?avatar=446_1516040955.png)
JernejL
-
- Posts: 1578
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by Stucuk » Sun Mar 08, 2009 9:24 pm
Iv finished converting every procedure/function, tho its still missing the NewtonCollisionInfoRecord as i have no clue how to convert it(Help would be nice). Anyway you can download the 2.0 Beta header below.
-
http://newton.freemapeditor.com/downloads/DelphiNewtonImport_NGD2.0Beta_WIP.rar ~62KB
Note: I have only converted the NewtonImport.h, not the Joint Libary's header.
-
![User avatar](./download/file.php?avatar=575_1233522237.jpg)
Stucuk
-
- Posts: 801
- Joined: Sat Mar 12, 2005 3:54 pm
- Location: Scotland
-
by JernejL » Thu Jul 09, 2009 3:51 am
I'm translating the NewtonCollisionInfoRecordTag record now, i have added case into the record, to accomodate the structure having different records based on collision type, there's however a problem with these structures at the end:
- Code: Select all
int m_referenceCount; // the current reference count for this collision
char m_collisionType[32]; // tag id to identify the collision primitive
Because delphi engineers in all their sillyness made records with variable structure only possible at end of a record, so i will have to split this record into two separate ones, in altogether 3 "packed records", i will ask julio if he can move those parts of record, then we can use a clean single record
-
![User avatar](./download/file.php?avatar=446_1516040955.png)
JernejL
-
- Posts: 1578
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by Stucuk » Thu Jul 09, 2009 7:37 am
If Julio has modified the header since i last posted then some functions in the header i posted may be out of data (Not checked).
-
![User avatar](./download/file.php?avatar=575_1233522237.jpg)
Stucuk
-
- Posts: 801
- Joined: Sat Mar 12, 2005 3:54 pm
- Location: Scotland
-
by JernejL » Thu Jul 09, 2009 8:17 am
There are some added functions and few changed structs which may be missing in your header, my header i posted isnt up to date either, but the one i use for tdc is since i'm adding changes regularly with each new beta release i do a diff to see what changed.
I havent published my up to date header yet because im trying to resolve the NewtonCollisionInfoRecordTag record problem so it will be 100% complete.
-
![User avatar](./download/file.php?avatar=446_1516040955.png)
JernejL
-
- Posts: 1578
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by JernejL » Thu Jul 09, 2009 2:59 pm
I talked to Julio, and the record will be changed in next beta release, m_referenceCount and m_collisionUserID will be moved to start of structure and variable part will be at the end, so this is how the translation should be correct structure for the next release (unless other things are added / changed):
- Code: Select all
// NewtonCollisionInfoRecord
TNewtonBoxParam = packed record
m_x,
m_y,
m_z: float;
end;
TNewtonSphereParam = packed record
m_r0,
m_r1,
m_r2: single;
end;
TNewtonCylinderParam = packed record
m_r0,
m_r1,
m_height: single;
end;
TNewtonCapsuleParam = packed record
m_r0,
m_r1,
m_height: single;
end;
TNewtonConeParam = packed record
m_r,
m_height: single;
end;
TNewtonChamferCylinderParam = packed record
m_r,
m_height: single;
end;
TNewtonConvexHullModifierParam = packed record
m_chidren: PNewtonCollision;
end;
TNewtonCompoundCollisionParam = packed record
m_chidrenCount: integer;
m_chidren: pointer; // pointer to array of pnewtoncollisions
end;
TNewtonHeightFieldCollisionParam = packed record
m_width,
m_height,
m_gridsDiagonals: integer;
m_horizonalScale,
m_verticalScale: single;
m_elevation: pointer; //unsigned short *m_elevation;
m_atributes: pchar;
end;
TNewtonSceneCollisionParam = packed record
m_childrenProxyCount: integer;
end;
TNewtonCollisionInfoRecord = packed record
m_offsetMatrix: array[0..3,0..3] of single;
m_collisionType, // tag id to identify the collision primitive
m_referenceCount, // the current reference count for this collision
m_collisionUserID: integer;
Case collisiontype: integer of
SERIALIZE_ID_BOX :
(shapedatabox: TNewtonBoxParam );
SERIALIZE_ID_CONE :
(shapedata: TNewtonConeParam );
SERIALIZE_ID_SPHERE :
(shapedatasphere: TNewtonSphereParam );
SERIALIZE_ID_CAPSULE :
(shapedatacapsule: TNewtonCapsuleParam );
SERIALIZE_ID_CYLINDER :
(shapedatacylinder: TNewtonCylinderParam );
SERIALIZE_ID_COMPOUND :
(shapedatacompound: TNewtonCompoundCollisionParam );
// SERIALIZE_ID_CONVEXHULL :
// (shapedataconvexhull: );
SERIALIZE_ID_CONVEXMODIFIER :
(shapedataxonvexhull: TNewtonConvexHullModifierParam );
SERIALIZE_ID_CHAMFERCYLINDER :
(shapedatachamfercylinder: TNewtonChamferCylinderParam );
// SERIALIZE_ID_TREE :
// (shapedata: );
// SERIALIZE_ID_NULL :
// (shapedata: );
SERIALIZE_ID_HEIGHTFIELD :
(shapedataheightfield: TNewtonHeightFieldCollisionParam );
SERIALIZE_ID_USERMESH :
(m_paramArray: array[0..63] of float);
SERIALIZE_ID_SCENE :
(shapedatascenecollision: TNewtonSceneCollisionParam);
end;
PNewtonCollisionInfoRecord = ^TNewtonCollisionInfoRecord;
Edit: i split this topic in two parts, so that 1.53 code and newton2 code arent mixed, should make it easier for people to find delphi headers for newton 2.0.
-
![User avatar](./download/file.php?avatar=446_1516040955.png)
JernejL
-
- Posts: 1578
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by Stucuk » Fri Jul 10, 2009 10:25 pm
Iv replaced my first post. Imo first post of the topic should have the latest downloadable links. Feel free to edit it. Note that if you add your own headers in the first post plz remove the link to mine (Should only work on one set rather than maintaining two). It would be good if Julio could put the latest Delphi headers in with the latest Beta's with a note somewhere (Say a readme) stating to check this topic for the latest ones.
-
![User avatar](./download/file.php?avatar=575_1233522237.jpg)
Stucuk
-
- Posts: 801
- Joined: Sat Mar 12, 2005 3:54 pm
- Location: Scotland
-
by JernejL » Sat Jul 11, 2009 10:10 am
Like i said in the PM, my header is a minimalistic one like the sury's original header, while yours & sascha's is made to work around glscene / delphigl.de headers so there's a distinct difference in some data type declarations used.
-
![User avatar](./download/file.php?avatar=446_1516040955.png)
JernejL
-
- Posts: 1578
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by Corpsman » Wed Aug 19, 2009 1:50 am
Hello,
I tried to use the Header files on a Kubuntu Jaunty Machine, with Lazarus.
To Compile the Headers i had to insert :
{$linklib stdc++}
in the FPC parts, and delete some units only aviable under Windows.
After this i could compile it.
I have written a game (
Balanced ) with Newton1.53 and now want to compile it under Linux, using the newton2.0. So i swapped the Header files without the need of changing one sourcecode file.
But unfortunatunely it does not work.
My "Ball" falls through all not moving objects without any collision.
So is there a tutorial or something like that, in wich i can read what i have to do different than :
- Code: Select all
type
TGLfloat = Single;
TVector3f = Record
x: GLfloat;
y: GLfloat;
z: GLfloat;
End;
Var
Collision: PNewtonCollision;
Fpoints: Array Of TVector3f;
Begin
If High(Fpoints) = -1 Then exit; // Array with Points
// Create collision
Collision := NewtonCreateConvexHull(newtonworld, high(Fpoints) + 1, @fpoints[0], 12, Nil);
// Create the rigid body
fNewtonBody := NewtonCreateBody(NewtonWorld, Collision);
// Remove the collider, we don't need it anymore
NewtonReleaseCollision(NewtonWorld, Collision);
// Solid Object
NewtonBodySetMassMatrix(fNewtonBody, 0, 0, 0, 0);
// Now set the position of the body's matrix
NewtonBodyGetMatrix(fNewtonBody, @FMatrix[0, 0]);
fMatrix[3, 0] := fPosition.x;
fMatrix[3, 1] := fPosition.y;
fMatrix[3, 2] := fPosition.z;
NewtonBodySetMatrix(fNewtonBody, @fMatrix[0, 0]);
// Finally set the callback in which the forces on this body will be applied
(*
is this really necessary for solid objects ???
*)
NewtonBodySetForceAndTorqueCallBack(fNewtonBody, @ForceAndTorqueCallBack);
NewtonBodySetMaterialGroupID(fnewtonbody, Material);
End;
-
Corpsman
-
- Posts: 38
- Joined: Mon May 01, 2006 11:42 am
-
by Corpsman » Wed Aug 19, 2009 4:32 am
The function
Old One:
- Code: Select all
function NewtonCreateConvexHull( const newtonWorld : PNewtonWorld; count : int; const vertexCloud : PFloat; strideInBytes : int; const offsetMatrix : PFloat) : PNewtonCollision; cdecl; external{$IFDEF __GPC__}name 'NewtonCreateConvexHull'{$ELSE}NewtonDLL{$ENDIF __GPC__};
new
- Code: Select all
function NewtonCreateConvexHull (const NewtonWorld : PnewtonWorld; count:int; const vertexCloud:PFloat; strideInBytes:Int; tolerance: Float; const offsetMatrix:PFloat) : PNewtonCollision; cdecl; external{$IFDEF __GPC__}name 'NewtonCreateConvexHull'{$ELSE}NewtonDLL{$ENDIF __GPC__};
and in delphinewton.inc
Old
- Code: Select all
{$IFDEF FPC}
{$MODE Delphi} { use Delphi compatibility mode }
{$H+}
{$PACKRECORDS 4} // Added for record
{$MACRO ON} // Added For OpenGL
{$THREADING on}
{$DEFINE Delphi}
{$DEFINE UseAT}
{$UNDEF USE_STDCALL}
{$DEFINE OS_BigMem}
{$DEFINE NO_EXPORTS}
{$DEFINE Has_Int64}
{$DEFINE NOCRT}
{$IFDEF unix}
{$DEFINE fpc_unix}
{$ELSE}
{$DEFINE __OS_DOS__}
{$ENDIF}
{$IFDEF WIN32}
{$DEFINE UseWin}
{$ENDIF}
{$ENDIF FPC}
New
- Code: Select all
{$IFDEF FPC}
{$MODE Delphi} { use Delphi compatibility mode }
{$H+}
{$PACKRECORDS 4} // Added for record
{$MACRO ON} // Added For OpenGL
{$THREADING on}
{$DEFINE Delphi}
{$DEFINE UseAT}
{$UNDEF USE_STDCALL}
{$DEFINE OS_BigMem}
{$DEFINE NO_EXPORTS}
{$DEFINE Has_Int64}
{$DEFINE NOCRT}
{$IFDEF unix}
{$DEFINE fpc_unix}
{$linklib stdc++} // Added by Corpsman, to support c++ code in libnewton.so
{$ELSE}
{$DEFINE __OS_DOS__}
{$ENDIF}
{$IFDEF WIN32}
{$DEFINE UseWin}
{$ENDIF}
{$ENDIF FPC}
-
Corpsman
-
- Posts: 38
- Joined: Mon May 01, 2006 11:42 am
-
by JernejL » Wed Aug 19, 2009 6:34 am
Corpsman: i merged your #2 post here.
About your #1 post: you should check if you set the positions properly - try the debug rendering, also how fast does the ball move?
-
![User avatar](./download/file.php?avatar=446_1516040955.png)
JernejL
-
- Posts: 1578
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by Stucuk » Wed Aug 19, 2009 2:17 pm
If you use "My" header with a version above about 2.03 then it shouldn't work correctly as the header has changed for some things (Mainly creating collisions). I havn't had any time to update it.
-
![User avatar](./download/file.php?avatar=575_1233522237.jpg)
Stucuk
-
- Posts: 801
- Joined: Sat Mar 12, 2005 3:54 pm
- Location: Scotland
-
by Stucuk » Wed Aug 19, 2009 4:33 pm
I have updated "my" header to 2.07 . But be warned i may have missed some changes. I have also included Delfi's NewtonCollisionInfoRecord code seen above, since i have never used it i don't know if its compatible with the latest version or not (Or if it works on any version) but its better than nothing
![Razz :P](./images/smilies/icon_razz.gif)
. Corpsman's changes have also been included. See top post for link to the latest header.
-
![User avatar](./download/file.php?avatar=575_1233522237.jpg)
Stucuk
-
- Posts: 801
- Joined: Sat Mar 12, 2005 3:54 pm
- Location: Scotland
-
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 28 guests