this is already answered
You need to generate a NewtonCollision from your mesh.
TreeCollision is static, anything else not. So use anything else but TreeCollision
Moderators: Sascha Willems, walaber

collision := NewtonCreateBox (NewtonWorld, GLCube1.CubeWidth, GLCube1.CubeHeight, GLCube1.CubeDepth, 0, nil);
NewtonBody := NewtonCreateBody(Newtonworld,collision);
pMass := 100;
Ixx := pMass * (GLCube1.CubeHeight * GLCube1.CubeHeight GLCube1.CubeDepth * GLCube1.CubeDepth) / 12;
Iyy := pMass * (GLCube1.CubeWidth * GLCube1.CubeWidth GLCube1.CubeDepth * GLCube1.CubeDepth) / 12;
Izz := pMass * (GLCube1.CubeWidth * GLCube1.CubeWidth GLCube1.CubeHeight * GLCube1.CubeHeight) / 12;
NewtonBodySetMassMatrix(NewtonBody, pMass, Ixx, Iyy, Izz);
NewtonBodySetMatrix(NewtonBody,NewtonImport.PFloat(GLCube1.AbsoluteMatrixAsAddress));
NewtonBodySetUserData(NewtonBody,GLCube1);
GLCube1.TagObject := TObject(NewtonBody);
NewtonBodySetForceAndTorqueCallBack(NewtonBody, @ForceAndTorqueCallBack);
Kjow wrote:I opened a thread called "Lazarus + GLScene" because in the GLScene community Newton is not so much used (there is ODE component, but I hope there will be soon a Newton component also), so I don't think that ask about GLScene usage WITH Newton is a so strange thing.
Stucuk wrote:Kjow wrote:I opened a thread called "Lazarus + GLScene" because in the GLScene community Newton is not so much used (there is ODE component, but I hope there will be soon a Newton component also), so I don't think that ask about GLScene usage WITH Newton is a so strange thing.
I didn't mean you shouldn't have opened this thread. I ment you to ask the GLScene community how to extract info from a GLFreeForm as its something thats a part of GLScene and not Newton.
GLFreeForm.LoadFromFile(ExtractFilePath(Application.ExeName)+'dyn.obj');
GLFreeForm.Roll(-45);
GLFreeForm.Position.Y:=30;
xD:= 5;
yD:= 5;
zD:= 5;
massD:=10;
IxxD := massD * (1/12) * (yD*yD+zD*zD);
IyyD := massD * (1/12) * (xD*xD+zD*zD);
IzzD := massD * (1/12) * (xD*xD+yD*yD);
dyn:= NewtonCreateConvexHull(Newtonworld, GLFreeForm.MeshObjects.Items[0].Vertices.Count, @(GLFreeForm.MeshObjects.Items[0].Vertices.List), sizeof(GLFreeForm.MeshObjects.Items[0].Vertices)*3, 0.002, 2, NewtonImport.PFloat(GLFreeForm.AbsoluteMatrixAsAddress));
NewtonBodyDyn:= NewtonCreateBody(Newtonworld, dyn);
NewtonBodySetMassMatrix(NewtonBodyDyn, massD, IxxD, IyyD, IzzD);
NewtonBodySetMatrix(NewtonBodyDyn,NewtonImport.PFloat(GLFreeForm.AbsoluteMatrixAsAddress));
NewtonBodySetUserData(NewtonBodyDyn,GLFreeForm);
GLFreeForm.TagObject:= TObject(NewtonBodyDyn);
NewtonBodySetForceAndTorqueCallBack(NewtonBodyDyn, @ForceAndTorqueCallBack); collision := NewtonCreateBox (NewtonWorld, GLCube1.CubeWidth, GLCube1.CubeHeight, GLCube1.CubeDepth, 0, nil);
NewtonBody := NewtonCreateBody(Newtonworld,collision);
pMass := 100;
Ixx := pMass * (GLCube1.CubeHeight * GLCube1.CubeHeight + GLCube1.CubeDepth * GLCube1.CubeDepth) / 12;
Iyy := pMass * (GLCube1.CubeWidth * GLCube1.CubeWidth + GLCube1.CubeDepth * GLCube1.CubeDepth) / 12;
Izz := pMass * (GLCube1.CubeWidth * GLCube1.CubeWidth + GLCube1.CubeHeight * GLCube1.CubeHeight) / 12;
NewtonBodySetMassMatrix(NewtonBody, pMass, Ixx, Iyy, Izz);
NewtonBodySetMatrix(NewtonBody,NewtonImport.PFloat(GLCube1.AbsoluteMatrixAsAddress));
NewtonBodySetUserData(NewtonBody,GLCube1);
GLCube1.TagObject := TObject(NewtonBody);
NewtonBodySetForceAndTorqueCallBack(NewtonBody, @ForceAndTorqueCallBack);NewtonBodySetTransformCallback(NewtonBodyDyn, @UpdateGraphicObject);
NewtonMaterial* NewtonWorldGetFirstMaterial (const NewtonWorld* world);
NewtonMaterial* NewtonWorldGetNextMaterial (const NewtonWorld* world, const NewtonMaterial* material);
NewtonBody* NewtonWorldGetFirstBody (const NewtonWorld* world);
NewtonBody* NewtonWorldGetNextBody (const NewtonWorld* world, const NewtonBody* curBody);
NewtonJoint* NewtonBodyGetFirstJoint (const NewtonBody* body);
NewtonJoint* NewtonBodyGetNextJoint (const NewtonBody* body, const NewtonJoint* joint);
NewtonJoint* NewtonBodyGetFirstContactJoint (const NewtonBody* body);
NewtonJoint* NewtonBodyGetNextContactJoint (const NewtonBody* body, const NewtonJoint* contactJoint);for (NewtonBody* body = NewtonWorldGetFirstBody (world); body; body = NewtonWorldGetNextBody (world, body)
{
...
}
// =============================================================================
// Debug_ShowGeometryCollision
// =============================================================================
// Callback that shows collision geometry of a body
// =============================================================================
procedure Debug_ShowGeometryCollision(const Body : PNewtonBody; VertexCount : Integer; const FaceArray : PFloat; FaceId : int); cdecl;
var
i : Integer;
v0,v1 : array[0..2] of Single;
vA : array of Single;
begin
if VertexCount = 0 then
exit;
SetLength(vA, VertexCount*3);
Move(FaceArray^, vA[0], VertexCount*3*SizeOf(Single));
v0[0] := vA[(VertexCount-1)*3];
v0[1] := vA[(VertexCount-1)*3+1];
v0[2] := vA[(VertexCount-1)*3+2];
for i := 0 to VertexCount-1 do
begin
v1[0] := vA[i*3];
v1[1] := vA[i*3+1];
v1[2] := vA[i*3+2];
Form1.GLLines1.AddNode(v0[0], v0[1], v0[2]);
Form1.GLLines1.AddNode(v1[0], v1[1], v1[2]);
v0 := v1;
end;
end;
// =============================================================================
// Debug_ShowBodyCollision
// =============================================================================
// Show collision geometry for all bodies in the current scene
// =============================================================================
procedure Debug_ShowBodyCollision(const Body : PNewtonBody); cdecl;
var
TmpM : TMatrix4f;
begin
NewtonBodyGetMatrix(Body, @TmpM[0,0]);
NewtonCollisionForEachPolygonDo(NewtonBodyGetCollision(Body), @TmpM[0,0], @Debug_ShowGeometryCollision, nil);
end;
// =============================================================================
// Debug_ShowCollision
// =============================================================================
// Show all collision geometries.
// =============================================================================
procedure Debug_ShowCollision;
begin
NewtonWorldForEachBodyInAABBDo(Form1.NewtonWorld, @(Form1.WorldSizeMin[0]), @(Form1.WorldSizeMax), @Debug_ShowBodyCollision, nil);
end;
main.pas(136,103) Error: Incompatible type for arg no. 3: Got "<address of procedure(const PNewtonBody,LongInt,const PFloat,LongInt);CDecl>", expected "<procedure variable type of procedure(Pointer,LongInt,const PFloat,LongInt);CDecl>"
NewtonImport.pas(864,11) Hint: Found declaration: NewtonCollisionForEachPolygonDo(const PNewtonCollision,const PFloat,NewtonCollisionIterator,Pointer); CDecl;
main.pas(146,125) Error: Incompatible type for arg no. 4: Got "<address of procedure(const PNewtonBody);CDecl>", expected "PNewtonBodyIterator"
NewtonImport.pas(596,11) Hint: Found declaration: NewtonWorldForEachBodyInAABBDo(const PNewtonWorld,const PFloat,const PFloat,PNewtonBodyIterator,Pointer); CDecl;
main.pas(426) Fatal: There were 2 errors compiling module, stopping
Users browsing this forum: No registered users and 3 guests