May 02, 2024, 04:45:51 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Skinned X example

Started by Ionic Wind Support Team, July 19, 2006, 04:20:08 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ionic Wind Support Team

As requested shows how to load a skinned .X file and animate it.

Quote
//Skinned X example
//Arrow keys to move camera.
//PgUp/PgDn to pan up and down.
//Z and X to rotate on Z axis.

declare import,timeGetTime(),int;

global sub main()
{
   C3DScreen s;
   C3DCamera c;
   C3DMesh m;
   C3DObject scene;
   C3DLight light;
   CDirectInput di;
   float fadjust,fTarget;
   //target 60FPS for camera movement
   fTarget = 1.0f / /*FPS*/60.0f * 1000.0f;
   fAdjust = 1.0f;
   
   s.CreateWindowed(0,0,800,600,AWS_CAPTION|AWS_VISIBLE|AWS_SIZE|AWS_CENTERED,0,"Skinned X example - ESC exits",NULL,false);
   di.Init(s);
   c.Create(s);
   c.Position(0,0,-700);
   c.Orient(0,0,1,0,1,0);
   c.SetBackPlane(10000);
   
   s.Clear(RGBA(0,0,0,255));
   s.BeginScene(c);
   s.RenderText(0,10,"Loading objects...",RGBA(255,255,0,255));
   s.RenderScene();
   
   m.LoadSkinnedX(s,GetStartPath() + "media\\tiny.x");
   m.SetAnimation(0,0,800,timeGetTime());
   
   light.Create(s,LIGHT_POINT,1);
   light.Position(0,100,-300);
   light.SetAttenuation(0,1/200.0,0);
   light.SetSpecular(.5,.5,.5,1);
   light.SetAmbient(.4,.4,.4,1);
   
   scene.CreateScene(s);
   scene.AddChild(light);
   scene.AddChild(m);
   int fps = 0;
   int startTime;
   do
   {
      startTime = timeGetTime();
      //check for keys and move camera accordingly
      IF di.KeyDown(DIK_UP)
         c.Move(0.0f,10f * fAdjust);
      IF di.KeyDown(DIK_DOWN)
         c.Move(0.0f,-10f * fAdjust);
      IF di.KeyDown(DIK_RIGHT)
         c.Rotate(1*.01745 * fAdjust,0,0);
      IF di.KeyDown(DIK_LEFT)
         c.Rotate(-1*.01745 * fAdjust,0,0);
      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,10000);
      
      s.Clear(RGBA(0,0,0,255));
      s.BeginScene(c);
      m.UpdateAnimation(timeGetTime());
      scene.Draw();
      s.RenderText(0,10,"FPS:"+NumToStr(fps),RGBA(255,255,0,255));
      s.RenderText(0,30,"Use arrow keys to move around",RGBA(255,255,0,255));
      fps = s.RenderScene();
      fAdjust = (timeGetTime() - startTime) / fTarget;
   }until di.KeyDown(DIK_ESCAPE);
   Scene.Free();
}
Ionic Wind Support Team

kryton9

Awesome, after you told me in the other post about the skinned x I got it to load, but of course no animation then. This is really cool. Going to see if I can get my animated x file to work.
Thanks for so much so quickly Paul!!

Rock Ridge Farm (Larry)

My getstartpath returns the current dir - Have I set something up wrong? What should it return?

kryton9

Make sure you save the source in the 3d3 folder, I had the same problem originally.

kryton9

Attached is a simpler x file than what I had planned on. But I am getting errors in trying to load and run it. There is no animation in this file.

I also included a gif of a screenshot in the x object viewer that I wrote in another language. It loads up fine with that program.

I did save all the editable polygons as one mesh before exporting it out to the x file too.

I tried both LoadX and LoadSkinnedX and had no luck. I couldn't attach my other viewer so you could see it, as it was too big too attach.

Ionic Wind Support Team

Perhaps it is saved in the wrong X format.  There is an older .x for DX7 which will give problems using Microsofts DX9 loader.
Ionic Wind Support Team

kryton9

No the other program also requires direct x 9. But it must be something in the multitude of polygons not being a continuous mesh, although it is saved as one mesh. I am able to load like simple cubes I export in the same manner. Working on a model viewer got a rough one going,  hopefully will have something by late tonight as got to go do some stuff this afternoon. Rather be home with Aurora :)