I need to create a space sim movement in Newton. I started using a falling box tutorial by Haramanai http://www.blitzmax.com/Community/posts.php?topic=51140.
When I change the values for force, Newton does'nt use the new values. Maybe I need to call a function somewhere.
Here's the Newton functions
When I change the values for force, Newton does'nt use the new values. Maybe I need to call a function somewhere.
Here's the Newton functions
'=============================================== '------------------- Physics ------------------- '=============================================== Function T_irrGetMatrix(NSceneNode:T_irrISceneNode , NewtonMat:Float Ptr) Local Euler:Float[3] Euler[0] = NSceneNode.GetRotation().getX() * (Pi / 180.0) Euler[1] = NSceneNode.GetRotation().getY() * (Pi / 180.0) Euler[2] = NSceneNode.GetRotation().getZ() * (Pi / 180.0) NewtonSetEulerAngle(Varptr Euler[0] , Varptr NewtonMat[0]) NewtonMat[12] = NSceneNode.getPosition().getX() newtonMat[13] = NSceneNode.getPosition().getY() NewtonMat[14] = NSceneNode.getPosition().getZ() End Function Function T_irrSetMatrix(NSceneNode:T_irrISceneNode , NewtonMat:Float Ptr) Local Euler:Float[3] NewtonGetEulerAngle(Varptr NewtonMat[0] , Varptr Euler[0]) NSceneNode.setPosition(T_irrVector3df.createFromVals(NewtonMat[12] , NewtonMat[13] , NewtonMat[14])) NSceneNode.SetRotation(T_irrVector3df.createFromVals(Euler[0] * (180 / Pi) , Euler[1] * (180 / Pi) , Euler[2] * (180 / Pi))) End Function Rem THE FUNCTIONS FROM TUTORIAL 2 endrem Function PhysicsAlloc:Byte Ptr(SizeInBytes:Int) Return MemAlloc(SizeInBytes) End Function Function PhysicsFree( MemPtr:Byte Ptr) MemFree (MemPtr) End Function Function PhysicsApplyForceAndTorque (Body:Byte Ptr) Local Mass:Float Local IXX:Float Local IYY:Float Local IZZ:Float 'I change the Force values with player input 'Newton only uses the values if they are preset. Global ForceX:Float Global ForceY:Float Global ForceZ:Float Local Force:Float[] = [-mass * ForceX, -mass * ForceY, -mass * ForceZ] Local Torque:Float[] = [TorqueX, TorqueY, TorqueZ] NewtonBodyGetMassMatrix (Body,Varptr Mass, Varptr IXX, Varptr IYY, Varptr IZZ); NewtonBodyAddForce (Body, Varptr Force[0]) NewtonBodyAddTorque (Body, Varptr Torque[0]) End Function Function PhysicsSetTransform (Body:Byte Ptr, NewtonMat:Float Ptr) Local Primitive:T_irrISceneNode Primitive = T_irrISceneNode.createFromHandle(Int(NewtonBodyGetUserData(Body)),False) NewtonBodyGetMatrix(Body , Varptr NewtonMat[0]) T_irrSetMatrix(Primitive , Varptr NewtonMat[0]) End Function Function PhysicsBodyDestructor(Body:Byte Ptr) Local Primitive:T_irrISceneNode Primitive = T_irrISceneNode.createFromHandle(Int(NewtonBodyGetUserData(Body)),False) Primitive.Remove() End Function Function CleanUp () 'destroy the Newton world NewtonDestroy (nWorld); End Function Function InitScene() Global BoxBody:Byte Ptr Global Collision:Byte Ptr Global mat:Float[16] 'create the newton world 'set the linear solver model For faster speed NewtonSetSolverModel(nWorld, 8) 'set the adpative friction model For faster speed NewtonSetFrictionModel(nWorld, 'Create PlayerNode Collision = NewtonCreateBox(nWorld, 0.5 , 0.5, 0.5 , Null) Local Location:Float[] = [0.0 , 0.0 , 0.0] PlayerNode.setPosition(T_irrVector3df.createFromVals(Location[0] ,Location[1] , Location[2])) BoxBody = NewtonCreateBody(nWorld , Collision) ' GG: changed to store the scenenode C++ object handle instead of a reference to the BMAX object with falls out of scope NewtonBodySetUserData(BoxBody ,Byte Ptr(PlayerNode.handle)) 'set a destrutor For this rigid body NewtonBodySetDestructorCallback(BoxBody, PhysicsBodyDestructor) 'set the tranform call back Function NewtonBodySetTransformCallback(BoxBody, PhysicsSetTransform) 'set the force And torque call back funtion NewtonBodySetForceAndTorqueCallback(BoxBody, PhysicsApplyForceAndTorque) 'set the mass matrix ' NewtonBodySetMassMatrix (BoxBody, 1.0F, 1.0F / 6.0F, 1.0F / 6.0F, 1.0F / 6.0F); NewtonBodySetMassMatrix(BoxBody, 1.0, 1.0, 1.0, 1.0) 'set the matrix For tboth the rigid body and the graphic body T_irrGetMatrix(PlayerNode , Varptr mat[0]) NewtonBodySetMatrix(BoxBody,Varptr mat[0]) PhysicsSetTransform(BoxBody, Varptr mat[0]) ' Location[0] :+ 0.5 * 2.0 'Release the collsion geometry when Not needed NewtonReleaseCollision(nWorld, Collision) EndFunction