Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Kennt hier Jemand die Function NewtoncreateCompoundCollision (https://www.delphipraxis.net/71278-kennt-hier-jemand-die-function-newtoncreatecompoundcollision.html)

Corpsman 12. Jun 2006 14:12


Kennt hier Jemand die Function NewtoncreateCompoundCollision
 
Hi,

Ich bin gerade mal wieder dabei ein kleines Spiel zu schreiben, diesmal in OpenGL und Newton.dll für Delphi.

Das Spiel Läuft auch schon wunderbar.

Nu wollte ich noch ein klein wenig was erweitern.

Das Prob ist nur,das das Forum für die Newton.dll auf English ist und die Irgendwie nur Antworten wenn man nach C++ Fragt oder was weis ich, mir antworten sie jedenfalls net.

Bis Jetzt habe ich es zumindest ganz Gut auch so geschafft.

Nur komme ich nun nicht mehr weiter.

Was ich machen will :

Ich habe Diverse Elemente in meiner Newtonwelt erstellt. ( Fast immer nur NewtonCreateBox )

Nun mus man denen dan eine Masse einen Schwerpunkt und eine Callback function geben für die Schwerkraft.

Alles Kein problem habe ich auch gemacht und läuft wunderbar.

Mein Prob ist das ich 2 dieser Objecte zu einem Zusammenfassen will, Laut dem Newton Forum soll das Gehen.

Ich habe es mit
Delphi-Quellcode:
Function Combine(box1, Box2: Pnewtonbody): PNewtonCollision;
Var
  Arr: Array[0..1] Of pNewtonbody;
Begin
  Arr[0] := Box1;
  Arr[1] := Box2;
  Result := newtoncreateCompoundCollision(newtonworld, 2, @arr);
End;
Probiert aber es geschieht nichts.

nu seid Ihr meine Letzte Hoffnung.

Gibts hier vielleicht jemanden der Weis wie's geht ?

DGL-luke 12. Jun 2006 14:17

Re: Kennt hier Jemand die Function NewtoncreateCompoundColli
 
Ich nicht persönlich, aber bei delphigl.com/forum gibts einige.
Sascha Willems ist leider kaum mehr aktiv.
Ich kann dir leider persönlich jetzt nicht mehr sagen, hab grad was anderes zu tun, sorry.

TurboMartin 12. Jun 2006 14:35

Re: Kennt hier Jemand die Function NewtoncreateCompoundColli
 
Ich weiß zwar nicht, wie du C kannst, aber vielleicht hilft das:
Code:
********************************************************************************************** 
// 
// complex collision primitives creation functions
// note: can only be used with static bodies (bodies with infinite mass)
// 
// ********************************************************************************************** 
inline NewtonCollision* NewtonCreateCompoundCollision (const NewtonWorld* newtonWorld, int count,
                                             NewtonCollision* const collisionPrimitiveArray[])

   assert(count >= 0);
   for (int i = 0; i < count; ++i)
      assert(collisionPrimitiveArray[i]);
   return nw::NewtonCreateCompoundCollision(newtonWorld, count, collisionPrimitiveArray);


inline NewtonCollision* NewtonCreateUserMeshCollision (const NewtonWorld* newtonWorld, const float *minBox,
                                             const float *maxBox, void *userData, NewtonUserMeshCollisionCollideCallback collideCallback,
                                             NewtonUserMeshCollisionRayHitCallback rayHitCallback, NewtonUserMeshCollisionDestroyCallback destroyCallback)

   NewtonValidateVector(minBox);
   NewtonValidateVector(maxBox);
   return nw::NewtonCreateUserMeshCollision(newtonWorld, minBox, maxBox, userData, collideCallback, rayHitCallback, destroyCallback);


//

Corpsman 12. Jun 2006 14:41

Re: Kennt hier Jemand die Function NewtoncreateCompoundColli
 
Der Code den du da hast ist Gegoogelt. Den Habe ich auch gefunden und daraus ja meine Combine Function gemacht.

Sie Tut nur leider net.

TurboMartin 12. Jun 2006 14:52

Re: Kennt hier Jemand die Function NewtoncreateCompoundColli
 
Zitat:

Zitat von Corpsman
Ich habe es mit
Delphi-Quellcode:
Function Combine(box1, Box2: Pnewtonbody): PNewtonCollision;
Var
  Arr: Array[0..1] Of pNewtonbody;
Begin
  Arr[0] := Box1;
  Arr[1] := Box2;
  Result := newtoncreateCompoundCollision(newtonworld, 2, @arr);
End;
Probiert aber es geschieht nichts.

mach mal

Delphi-Quellcode:
Function Combine(box1, Box2: Pnewtonbody): PNewtonCollision;
Var
  Arr: Array[0..1] Of pNewtonbody;
Begin
  Arr[0] := Box1;
  Arr[1] := Box2;
  Result := NewtonCreateCompoundCollision(newtonworld, 1, @Arr);
End;
und bind newtonwrap.cpp oder newtonwrap.h in den Code ein.
Danach stellst du bei den Projektoptionen ein, dass er C++-Code erzeugen soll.

PS: is nicht gegoogelt :) ist vonhier!

DGL-luke 12. Jun 2006 14:54

Re: Kennt hier Jemand die Function NewtoncreateCompoundColli
 
@TurboMartin:

C einbinden :shock:

@Corpsman: Arbeitest du mit Sascah Willems' Pascal-headern? http://newton.delphigl.de ?

TurboMartin 12. Jun 2006 15:03

Re: Kennt hier Jemand die Function NewtoncreateCompoundColli
 
Zitat:

Zitat von DGL-luke
@TurboMartin:

C einbinden :shock:

Wieso nicht?
Bei mir ging es ma, aber seit dem Delphi 7 auf dem einen Rechner kaputt ist, und nicht reparierbar ist, ohne Windows neu aufzusetzen, weiß ich nicht mehr genau wie.

Corpsman 12. Jun 2006 15:08

Re: Kennt hier Jemand die Function NewtoncreateCompoundColli
 
Liste der Anhänge anzeigen (Anzahl: 1)
Also die Inteer Zahl gibt die Anzahl der Body's an diese ist ja 2 mit 1 tut es auch nicht, was du da mit dem C sach meinst verstehe ich net ganz.

Ich lade euch nu einfach mal das gesamte Sample mit hoch dann könnt ihr euch das Chaos selbst ansehen ;)

Übrigens Progge ich mit D5 Prof.
Und Ja ich benutze diese Header Files

TurboMartin 12. Jun 2006 15:27

Re: Kennt hier Jemand die Function NewtoncreateCompoundColli
 
Zitat:

Zitat von NewtonImport.pas
Delphi-Quellcode:
function NewtonCreateCompoundCollision( const newtonWorld : PNewtonWorld; count : int;
                                        const collisionPrimitiveArray : TcollisionPrimitiveArray ) : PNewtonCollision; cdecl; external{$IFDEF __GPC__}name 'NewtonCreateCompoundCollision'{$ELSE}NewtonDLL{$ENDIF __GPC__};

Ich glaub, du brauchst einen anderen Array:
Delphi-Quellcode:
  const collisionPrimitiveArray : TcollisionPrimitiveArray
Edit:
Musst du noch einfügen:
Delphi-Quellcode:
type
  TCollisionPrimitiveArray = array of PNewtonCollision;

Corpsman 12. Jun 2006 15:31

Re: Kennt hier Jemand die Function NewtoncreateCompoundColli
 
Liste der Anhänge anzeigen (Anzahl: 1)
Ich glaube ich mus mich für das Code Chaos in meinem Sample erst mal entschukdigen,

Das mit dem Array war mir auch aufgefallen.

Ich habe mir gerade das NewtonBasic Demo noch mal rein gezogen.

Und damit Folgendes Gemacht.

Delphi-Quellcode:

Procedure InitNewton;
Var
  TmpV: TVector3f;
  i: Integer;
  Arr: Array[0..1] Of pNewtonbody;
  Arr1: Array[0..1] Of PNewtonCollision;
  Collision2, Collision1: PNewtonCollision;
  Matrix: TMatrix4f; // Used to retrieve the matrix from newton

Begin
  Randomize;
  NewtonWorld := NewtonCreate(Nil, Nil);

  Collision1 := NewtonCreateBox(NewtonWorld, 1, 1, 1, Nil);
  Collision2 := NewtonCreateBox(NewtonWorld, 1, 1, 1, Nil);
  // Create the rigid body

  //  NewtonBody := NewtonCreateBody(NewtonWorld, Collision);
  // Remove the collider, we don't need it anymore

  // Now we calculate the moment of intertia for this box. Note that a correct
  // moment of inertia is CRUCIAL for the CORRECT PHYSICAL BEHAVIOUR of a body,
  // so we use an special equation for calculating it
{  Inertia.x := pMass * (pSize.y * pSize.y + pSize.z * pSize.z) / 12;
  Inertia.y := pMass * (pSize.x * pSize.x + pSize.z * pSize.z) / 12;
  Inertia.z := pMass * (pSize.x * pSize.x + pSize.y * pSize.y) / 12;
}
  te := Combine(Collision1, Collision2);

  NewtonBody1 := NewtonCreateBody(NewtonWorld, Te);

  NewtonReleaseCollision(NewtonWorld, Te); // Wenn wir das machen könne wir es nicht mehr an CompundCollsiion übergeben.

  // Set the bodies mass and moment of inertia
  NewtonBodySetMassMatrix(NewtonBody1, 10, 160, 160, 160);
  // Now set the position of the body's matrix
  NewtonBodyGetMatrix(NewtonBody1, @Matrix[0, 0]);
  Matrix[3, 0] := 4;
  Matrix[3, 1] := 15;
  Matrix[3, 2] := 1;
  NewtonBodySetMatrix(NewtonBody1, @Matrix[0, 0]);
  // Finally set the callback in which the forces on this body will be applied
  NewtonBodySetForceAndTorqueCallBack(NewtonBody1, ForceAndTorqueCallBack);
Sieht Caotisch aus , und noch viel schlimmer ich habe keine Ahnung wo ich nun meine Renderfucntion hinpacken soll.

Aber der Pointer Newtonbody1 hat nun irgendwas bekommen, da meine Renderfunction anzeigt das die y - Coordinate fällt, was bedeuten würde das ich es zumindest geschafft habe ein Object in der Newtonwelt zu erstellen.

Ich lade nun nochmals die Unit1 hoch das ihr euch das ansehen könnt, der Rest hat sich ja nicht geändert.


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:35 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz