A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Jagang » Fri Jun 04, 2010 2:07 pm
Hello
Firstly I'm French.
I would like use Newton 2.21 with Irrlicht 1.7.1. But, on internet, all tutorials I can find are obsolete ! For example
this tutorial.
- M of matrix4 is private
- NewtonCreate have 0 argument
Moreover, the api database on the wiki isn't updated (NewtonCreate have again 2 arguments)
As a result, I wrote a code but it crash :
main.cpp
- Code: Select all
#include <math.h>
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
// irrlicht
#include <irr/irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
// newton
#include <newton/Newton.h>
#include "matrix.hpp"
void ApplyForce(const NewtonBody *nbody,float r,int r1)
{
float mass, ixx, iyy, izz;
NewtonBodyGetMassMatrix(nbody, &mass, &ixx, &iyy, &izz);
float force[3] = {0, mass * -9.82, 0};
NewtonBodyAddForce(nbody, force);
}
int main(int argc, char* argv[])
{
u32 lasttick=0;
// Init the Irrlicht engine
IrrlichtDevice* device = createDevice(
EDT_OPENGL, //video::E_DRIVER_TYPE deviceType = video::EDT_SOFTWARE,
dimension2d<u32>(800, 600), //const core::dimension2d< u32 > & windowSize = (core::dimension2d< u32 >(640, 480)),
16, //u32 bits = 16,
false, //bool fullscreen = false,
false, //bool stencilbuffer = false,
false, //bool vsync = false,
false); //IEventReceiver * receiver = 0
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
// Newton vars
NewtonWorld *nWorld;
// Init newton
nWorld = NewtonCreate();
float min[3];
float max[3];
min[0] = -200.0;
min[1] = -100.0;
min[2] = -200.0;
max[0] = 200.0;
max[1] = 100.0;
max[2] = 200.0;
NewtonSetWorldSize( nWorld, min, max );
// Set up default material properties for newton
int i = NewtonMaterialGetDefaultGroupID(nWorld);
NewtonMaterialSetDefaultFriction (nWorld, i, i, 0.8f, 0.4f);
NewtonMaterialSetDefaultElasticity (nWorld, i, i, 0.3f);
NewtonMaterialSetDefaultSoftness (nWorld, i, i, 0.05f);
NewtonMaterialSetCollisionCallback (nWorld, i, i, NULL, NULL, NULL);
ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(
NULL,//ISceneNode * parent = 0,
100.0f,//f32 rotateSpeed = 100.0f,
0.01f//f32 moveSpeed = 0.5f,
//s32 id = -1,
//SKeyMap * keyMapArray = 0,
//s32 keyMapSize = 0,
//bool noVerticalMovement = false,
//f32 jumpSpeed = 0.f,
//bool invertMouse = false,
);//bool makeActive = true
cam->setPosition(vector3df(5, 5, 0));
cam->setTarget(vector3df(0, 5, 0));
device->getCursorControl()->setVisible(false);
//! cube 1
ISceneNode* cube1 = smgr->addCubeSceneNode(1,0,-1,vector3df(0, 5, 0));
cube1->setMaterialTexture(0, driver->getTexture("tex/crate.jpg"));
cube1->setMaterialFlag(EMF_LIGHTING, false);
// Créer le corp // ------------------
NewtonBody* body1;
// On Initialise le corp // ----------
body1 = NewtonCreateBody(nWorld,NewtonCreateBox(nWorld,1,1,1,0,NULL)) ;
// On lui assigne une matrice // -----
Matrix mat1;
NewtonBodySetMatrix(body1,mat1.p());
mat1.info();
// Configurer la masse et l'inertie //-
NewtonBodySetMassMatrix(body1,10,2,2,2);
// On affecte au corp la force de gravité // ---
NewtonBodySetForceAndTorqueCallback(body1, ApplyForce);
//! cube 2
ISceneNode* cube2 = smgr->addCubeSceneNode(1,0,-1,vector3df(0, 0, 0));
cube2->setMaterialTexture(0, driver->getTexture("tex/crate.jpg"));
cube2->setMaterialFlag(EMF_LIGHTING, false);
while(device->run())
{
// calcule de la physique
if (device->getTimer()->getTime() > lasttick + 10)
{
NewtonUpdate(nWorld, (device->getTimer()->getTime()-lasttick)/1000);
lasttick = device->getTimer()->getTime();
NewtonBodyGetMatrix(body1,mat1.p());
/*cube1->setRotation(vector3df(mat1[0]));
cube1->setPosition(mat1.getTranslation());*/
mat1.info();
}
driver->beginScene(true, true, video::SColor(0,220,220,255));
smgr->drawAll();
driver->endScene();
}
NewtonDestroy(nWorld);
device->drop();
return 0;
}
matrix.hpp
- Code: Select all
#ifndef MATRIX_HPP_INCLUDED
#define MATRIX_HPP_INCLUDED
class Matrix
{
public:
Matrix();
float* p();
void info(int indice=-1);
private:
float M[16];
};
#endif // MATRIX_HPP_INCLUDED
matrice.cpp
- Code: Select all
#include <iostream>
#include "matrix.hpp"
using namespace std;
Matrix::Matrix()
{
for(int i=0;i<16;i++)
M[i]=150;
}
float* Matrix::p()
{
return M;
}
void Matrix::info(int indice)
{
for(int i=0;i<16;i++)
if(i==indice || indice == -1) cout << i << " : " << M[i] << endl;
}
(Sorry for the comments in French)
This code crash on line 123, NewtonUpdate(nWorld, (device->getTimer()->getTime()-lasttick)/1000);
How to use Newton 2.21 ?
Thank you in advance
Cordially
Jagang
-
Jagang
-
- Posts: 7
- Joined: Fri Jun 04, 2010 1:40 pm
by Cannos » Fri Jun 04, 2010 2:35 pm
I know this is a dumb question, but are you sure that these calls are not NULL?
device->getTimer()
device->getTimer()->getTime()
It might be worth computing the time to pass into NewtonUpdate on a different line to make sure you're passing in a valid time.
-
Cannos
-
- Posts: 129
- Joined: Thu Mar 04, 2010 5:41 pm
by Jagang » Fri Jun 04, 2010 2:47 pm
I'm sure that these calls are not NULL
I changed this part :
- Code: Select all
// calcule de la physique
float tps = device->getTimer()->getTime();
cout << tps << endl;
if (tps > lasttick + 10)
{
NewtonUpdate(nWorld, (tps - lasttick + 10)/1000);
lasttick = device->getTimer()->getTime();
NewtonBodyGetMatrix(body1,mat1.p());
/*cube1->setRotation(vector3df(mat1[0]));
cube1->setPosition(mat1.getTranslation());*/
mat1.info();
}
And the debugger crash on NewtonUpdate(nWorld, (tps - lasttick + 10)/1000);
The backtrace :
#0 100483AB NewtonCreateCompoundCollisionFromMesh() (G:\********\C++\teleportal\newton.dll:??)
#1 0022FE9C ??() (??:??)
#2 10049BF9 NewtonCreateCompoundCollisionFromMesh() (G:\********\C++\teleportal\newton.dll:??)
#3 00000001 ??() (/mingw/src/gccbf/mingw32/libstdc++-v3/include/ext/concurrence.h:75)
#4 00221C70 ??() (??:??)
#5 C2C80000 ??() (??:??)
#6 00000000 ??() (??:??)
CONFIG :
- Irrlicht 1.7.1
- Newton 2.21
- Code::Blocks 8.02 with GNU GCC 4.4.0 Compiler
- Windows XP SP1
-
Jagang
-
- Posts: 7
- Joined: Fri Jun 04, 2010 1:40 pm
by Julio Jerez » Fri Jun 04, 2010 2:50 pm
what is this
- Code: Select all
Matrix::Matrix()
{
for(int i=0;i<16;i++)
M[i]=150;
}
that will not initialize a normal transformantion matrix
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Jagang » Fri Jun 04, 2010 3:46 pm
Sorry, it's for test. I forgot to change it. For me, the normal initialization is :
- Code: Select all
Matrix::Matrix()
{
for(int i=0;i<16;i++)
M[i]=0;
}
Is it a normal initialization transformation matrix ?
-
Jagang
-
- Posts: 7
- Joined: Fri Jun 04, 2010 1:40 pm
by Cannos » Fri Jun 04, 2010 4:11 pm
The identity matrix is:
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
All 0s is an invalid matrix and will probably have undefined results. Not sure if this is the cause of the crash.
-
Cannos
-
- Posts: 129
- Joined: Thu Mar 04, 2010 5:41 pm
by Jagang » Fri Jun 04, 2010 4:28 pm
- Code: Select all
Matrix::Matrix()
{
for(int i=0;i<16;i++)
M[i]=0;
M[0]=1;
M[5]=1;
M[10]=1;
M[15]=1;
}
But, it crash always on NewtonUpdate(nWorld, (tps - lasttick + 10)/1000);
-
Jagang
-
- Posts: 7
- Joined: Fri Jun 04, 2010 1:40 pm
by Julio Jerez » Fri Jun 04, 2010 5:18 pm
you maybe be using the wrong DLL
you are not using mesh function but the crash happens on a mesh function.
0 100483AB NewtonCreateCompoundCollisionFromMesh() (G:\********\C++\teleportal\newton.dll:??)
by reading the address of the function it looks like you are using a 64 bit library with and 32 by exe
make sure you are usin teh right library wit and teh right float mode.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Jagang » Sat Jun 05, 2010 4:23 am
In fact, I don't known which .dll and .lib use.
I have Code::Blocks 8.02 with GNU GCC 4.4.0 Compiler but in the SDK all .lib and .dll are for VisualStudio.
I took .dll and .lib which were in this path : NewtonWin-2.21\sdk\x32\dll_double_vs7
But, I don't known if is the right path. (Windows XP SP1 x32)
-
Jagang
-
- Posts: 7
- Joined: Fri Jun 04, 2010 1:40 pm
by Jagang » Sat Jun 05, 2010 5:08 am
I tested with .dll and .lib in NewtonWin-2.21\sdk\x32\dll_vs9 and it don't crash !!
Thank you.
One other question. In the matrix, translations are in M[3][0]=X, M[3][1]=Y and M[3][2]=Z but, where are rotations ? In degrees or in radian ?
-
Jagang
-
- Posts: 7
- Joined: Fri Jun 04, 2010 1:40 pm
by Carli » Sat Jun 05, 2010 5:10 am
Jagang wrote:NewtonWin-2.21\sdk\x32\dll_double_vs7
you took the double precision library.
this is predestined to crash.
-
Carli
-
- Posts: 245
- Joined: Fri Oct 02, 2009 5:28 am
by Carli » Sat Jun 05, 2010 5:11 am
Jagang wrote:One other question. In the matrix, translations are in M[3][0]=X, M[3][1]=Y and M[3][2]=Z but, where are rotations ? In degrees or in radian ?
in the matrix.
the first row is the side vector, the second is the up vector and the third is the front vector.
-
Carli
-
- Posts: 245
- Joined: Fri Oct 02, 2009 5:28 am
by Jagang » Sat Jun 05, 2010 5:38 am
Thank you
-
Jagang
-
- Posts: 7
- Joined: Fri Jun 04, 2010 1:40 pm
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 13 guests