May 02, 2024, 04:20:54 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Collision

Started by J B Wood (Zumwalt), July 27, 2006, 11:34:48 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

J B Wood (Zumwalt)

Anyone have sample code to compare 2 objects for collision?
How about animation, using key frames for start points and give final frame for given animation when single mesh contains multiple animations?
Physics documentation?

kryton9

The landscape and park examples Paul gave have collision in them and also the microsoft character has animation.
landscape files in your examples:d3d folder
skinned animation:
http://www.ionicwind.com/forums/index.php?topic=742.0

Ionic Wind Support Team

For each object you want to collison test you have to call InitCollision.  If the mesh contains multiple objects, such as some 3DS meshes, or you want to initialize collision testing for all objects in a scene then set the bChildren parameter to true.  You only need to call InitCollision once for each mesh.

mesh1.InitCollision(true);
mesh2.InitCollison(true);

if(mesh1.ObjectCollided(mesh2, true))
{
   //collided
}

Object scaling is not taken into account when collision testing against another object.

A better method (and much faster) is sphere collisions. 

MD2 animation supports the start and end frames, or even refer to the animation by name.  I'll post an example in a day or so.

Skinned X supports specifying the start frame and duration.  Skinned X uses 'tracks' of animations and you specify the current track using SetAnimationMode.

Update your animations with the UpdateAnimation member, or you can update all child meshes of a scene using UpdateAllAnimations.

There isn't any documentation at all.  Except for the skeleton help file.  And the engine has no physics code yet.

Paul.
Ionic Wind Support Team

J B Wood (Zumwalt)

Why doesn't this return on the else?

if(z.ObjectCollided(m, true))
{
s.RenderText(0,70,"Robot Hit Terrain",RGBA(255,255,0,255));
}
else
{
s.RenderText(0,90,"Robot Missed Terrain",RGBA(255,255,0,255));
}


If works just fine, but when the robot is not colliding it doesn't state the second message, its returning true always.

J B Wood (Zumwalt)

Going to bed, but here is what I have done so far, if you can point me in the right direction to fixing the terrain and the collision, it would be of great help. Its ok if not.

kryton9

Ran fine here.

Glad to see someone even more excited about all of these cool new things to play with!!

J B Wood (Zumwalt)

I am thinking about adding ODE to it.
Unless the devs are already working on it.
I think what I need to do, now that I have slept on it, is point the camera at the terrain and look at the rotation factor.
I have alot more work to do on the thing.

Ionic Wind Support Team

ObjectCollided is broken for Rev 7.  It's a quick fix but you'll need to wait for the next update.
Ionic Wind Support Team

J B Wood (Zumwalt)

July 28, 2006, 06:43:05 AM #8 Last Edit: July 28, 2006, 06:56:18 AM by zumwalt
That answer works for me, atleast I helped to find a bug.

Ionic Wind Support Team

Attached to the message is an update program that will replace your a3d.lib with a working one.  Just double click and enjoy.

You'll need to change a few things in your code for it to work.  The bChildren paramter of InitCollision/LoadFrom3DS is only if your 3ds file contains multiple meshes.  Which usually only happens when you have multiple textures.

I've also turned ambient lighting to max in your light, just to see things better.


declare import,timeGetTime(),int;

global sub main()
{
C3DScreen s;
C3DCamera c;
C3DMesh m;
C3DObject scene;
C3DLight light;
CDirectInput di;
VECTOR3 myMesh;
float fadjust,fTarget;
//target 60FPS for camera movement
fTarget = 1.0f / /*FPS*/60.0f * 1000.0f;
fAdjust = 1.0f;


//Zumwalts FUN stuff!!!
C3DMesh z;

s.CreateWindowed(0,0,1024,768,AWS_CAPTION|AWS_VISIBLE|AWS_SIZE,0,"Zumwalts 3D Test - ESC exits",NULL,false);
di.Init(s);
s.CenterWindow();
c.Create(s);
c.Position(10,10,50);
c.Orient(0,0,1,0,10,0);
c.SetBackPlane(500);


z.Load3DS(s,GetStartPath() + "media\\robot.3ds",false);
z.Scale(1,1,1);
z.Position(54,-50,100);
z.Rotate(-22.5 * .01745,180 * .01745,0);
z.EnableLighting(true);
z.UseVertexColor(true);

m.Load3DS(s,GetStartPath() + "media\\zumwalt.3ds",false);
m.Scale(1,1,1);
m.Position(0,0,0);
m.Rotate(-22.5 * .01745,180 * .01745,0);
m.EnableLighting(true);
m.UseVertexColor(true);

light.Create(s,LIGHT_POINT,1);
light.Position(110,110,150);
light.SetAttenuation(0,1/250.0,0);
light.SetSpecular(.5,.5,.5,1);
light.SetAmbient(1,1,1,1);
light.SetRange(1000);

scene.CreateScene(s);
scene.AddChild(light);
scene.AddChild(m);
scene.AddChild(z);

z.initcollision(false);
m.initcollision(false);

int fps = 0;
int startTime;
do
{
startTime = timeGetTime();
//check for keys and move camera accordingly
IF di.KeyDown(DIK_UP)
{
//c.Move(myMesh.x+0.0f,myMesh.y+.25f * fAdjust);
z.Position(myMesh.x+0.0f,myMesh.y+0.0f,myMesh.z+.25f * fAdjust);
}
IF di.KeyDown(DIK_DOWN)
{
//c.Move(myMesh.x+0.0f,myMesh.y -.25f * fAdjust);
z.Position(myMesh.x+0.0f,myMesh.y+0.0f,myMesh.z-.25f * fAdjust);
}
IF di.KeyDown(DIK_RIGHT)
{
//c.Rotate(1*.01745 * fAdjust,0,0);
z.Position(myMesh.x+.25 * fAdjust,myMesh.y+0.0f,myMesh.z+0.0f);
}
IF di.KeyDown(DIK_LEFT)
{
//c.Rotate(-1*.01745 * fAdjust,0,0);
z.Position(myMesh.x-.25 * fAdjust,myMesh.y+0.0f,myMesh.z+0.0f);
}
IF di.KeyDown(DIK_Z)
c.Rotate(0,0,-1 *.01745 * fAdjust);
IF di.KeyDown(DIK_X)
c.Rotate(0,0,1 *.01745 * fAdjust);
IF di.KeyDown(DIK_PRIOR)
c.Rotate(0,-1 *.01745 * fAdjust,0);
IF di.KeyDown(DIK_NEXT)
c.Rotate(0,1 *.01745 * fAdjust,0);
//IF di.KeyDown(DIK_R)
//c.LookAt(0,0,0);

s.Clear(RGBA(0,0,0,255));
s.BeginScene(c);
scene.Draw();
s.RenderText(0,10,"FPS:"+NumToStr(fps),RGBA(255,255,0,255));

myMesh = z.GetPosition(0);
s.RenderText(0,30,"X:"+NumToStr(myMesh.x),RGBA(255,255,0,255));
s.RenderText(0,40,"Y:"+NumToStr(myMesh.y),RGBA(255,255,0,255));
s.RenderText(0,50,"Z:"+NumToStr(myMesh.z),RGBA(255,255,0,255));
c.LookAt(myMesh.x,myMesh.y,myMesh.z);

if(m.ObjectCollided(z, true))
{
s.RenderText(0,70,"Robot Hit Terrain",RGBA(255,255,0,255));
}
else
{
s.RenderText(0,90,"Robot Missed Terrain",RGBA(255,255,0,255));
}

fps = s.RenderScene();
fAdjust = (timeGetTime() - startTime) / fTarget;
}until di.KeyDown(DIK_ESCAPE);
Scene.Free();
}






[attachment deleted by admin]
Ionic Wind Support Team

J B Wood (Zumwalt)

YAY! Thanks!
I have started the ODE import, downloaded the latest build and have imported the lib.
Going to work on the structures later. I am burried at the moment in something else, but this works great!

J B Wood (Zumwalt)

Code with camera now following mech.


//#include "ode.inc"
declare import,timeGetTime(),int;

global sub main()
{
C3DScreen s;
C3DCamera c;
C3DMesh m;
C3DObject scene;
C3DLight light;
CDirectInput di;
VECTOR3 myMesh,myTerrain;
float fadjust,fTarget;
//target 60FPS for camera movement
fTarget = 1.0f / /*FPS*/60.0f * 1000.0f;
fAdjust = 1.0f;

//Zumwalts FUN stuff!!!
C3DMesh z;

s.CreateWindowed(0,0,1024,768,AWS_CAPTION|AWS_VISIBLE|AWS_SIZE,0,"Zumwalts 3D Test - ESC exits",NULL,false);
di.Init(s);
s.CenterWindow();
c.Create(s);
c.Position(1,1,1);
c.Rotate(0,0,0);
c.Orient(0,0,1,0,10,0);
//c.Orient(0,0,1,0,100,0);
c.SetBackPlane(500);

z.Load3DS(s,GetStartPath() + "media\\robot.3ds",false);
z.Scale(1,1,1);
z.Position(0,-7.45,0); // hit is at -7.5, need to look into mesh later
z.Rotate(0,0,0);
z.EnableLighting(true);
z.UseVertexColor(true);

m.Load3DS(s,GetStartPath() + "media\\zumwalt.3ds",false);
m.Scale(1,1,1);
m.Position(0,0,0);
m.Rotate(0,0,0);
m.EnableLighting(true);
m.UseVertexColor(true);

light.Create(s,LIGHT_POINT,1);
light.Position(110,110,150);
light.SetAttenuation(0,1/250.0,0);
light.SetSpecular(.5,.5,.5,1);
light.SetAmbient(1,1,1,1);
light.SetRange(1000);

scene.CreateScene(s);
scene.AddChild(light);
scene.AddChild(m);
scene.AddChild(z);

z.initcollision(false);
m.initcollision(false);

int fps = 0;
int startTime;
do
{
startTime = timeGetTime();
//check for keys and move mech and camera accordingly
IF di.KeyDown(DIK_UP)
{
z.Position(myMesh.x+0.0f,myMesh.y+0.0f,myMesh.z+.25f * fAdjust);
}
IF di.KeyDown(DIK_DOWN)
{
z.Position(myMesh.x+0.0f,myMesh.y+0.0f,myMesh.z-.25f * fAdjust);
}
IF di.KeyDown(DIK_RIGHT)
{
z.Position(myMesh.x+.25 * fAdjust,myMesh.y+0.0f,myMesh.z+0.0f);
}
IF di.KeyDown(DIK_LEFT)
{
z.Position(myMesh.x-.25 * fAdjust,myMesh.y+0.0f,myMesh.z+0.0f);
}

/*
IF di.KeyDown(DIK_Z)
c.Rotate(0,0,-1 *.01745 * fAdjust);
IF di.KeyDown(DIK_X)
c.Rotate(0,0,1 *.01745 * fAdjust);
IF di.KeyDown(DIK_PRIOR)
c.Rotate(0,-1 *.01745 * fAdjust,0);
IF di.KeyDown(DIK_NEXT)
c.Rotate(0,1 *.01745 * fAdjust,0);
//IF di.KeyDown(DIK_R)
//c.LookAt(0,0,0);
*/

s.Clear(RGBA(0,0,0,255));
s.BeginScene(c);
scene.Draw();
s.RenderText(0,10,"FPS:"+NumToStr(fps),RGBA(255,255,0,255));

myMesh = z.GetPosition(0);
myTerrain = m.GetPosition(0);

s.RenderText(0,30,"X:"+NumToStr(myMesh.x),RGBA(255,255,0,255));
s.RenderText(0,40,"Y:"+NumToStr(myMesh.y),RGBA(255,255,0,255));
s.RenderText(0,50,"Z:"+NumToStr(myMesh.z),RGBA(255,255,0,255));
c.Position(myMesh.x+10,myMesh.y+5,myMesh.z+10);
c.LookAt(myMesh.x,myMesh.y,myMesh.z);
//c.LookAt(myTerrain.x,myTerrain.y,myTerrain.z);

if(m.ObjectCollided(z, true))
{
s.RenderText(0,70,"Robot Hit Terrain",RGBA(255,255,0,255));
}
else
{
s.RenderText(0,90,"Robot Missed Terrain",RGBA(255,255,0,255));
}

fps = s.RenderScene();
fAdjust = (timeGetTime() - startTime) / fTarget;
}until di.KeyDown(DIK_ESCAPE);
Scene.Free();
}


kryton9

Hmmm, I installed the 3d update.
Booted up Aurora

Loaded up Aurora1.src from the Aurora3d folder
I copied and pasted the code from Paul's mod over the one in Aurora1.src.
I get a compiler error.

I went and did the same thing with zumwal'ts latest code and the same compiler error.

So I went back and unzipped the Aurora3d.zip from last night. And it worked last night, but
it too gives the same message: compiler error.

J B Wood (Zumwalt)

July 28, 2006, 01:29:31 PM #13 Last Edit: July 28, 2006, 01:31:39 PM by zumwalt
Did you run the updater from the updater.zip?

Attaching the latest build to src.

Ionic Wind Support Team

Delete the .opts file from the directory.
Ionic Wind Support Team

kryton9

July 28, 2006, 04:20:50 PM #15 Last Edit: July 28, 2006, 04:26:03 PM by kryton9
Had to run some errands and was hoping there would be replies when I got back so I can look at those examples. Thanks, great to get such quick answers.

Deleting the Opts file did it. So what is the Opts file?

Enjoyed both examples. The mech must be a member of Buckaroo Banzai, being able to cross the 8th dimension  :)
http://www.imdb.com/title/tt0086856/

Ionic Wind Support Team

The opts file is created when you compile in single file mode, as opposed to using a project.   It saves the current icon used, and the path to the executable to be created.  So your directory structure doesn't match his.

Projects automaticaly update from foreign directories.
Ionic Wind Support Team

J B Wood (Zumwalt)

This currently is a projectless example.
I am trying to keep it simple, as simple as humanly possible.