Author Topic: Object3D not displayed  (Read 2498 times)

Anonymous

  • Guest
Object3D not displayed
« on: December 14, 2005, 10:01:10 pm »
Hi!

I can't figure this one out. I am loading a quake2 MD2 model to an Object3D, but it's not displayed. I can only see the "map" that I loaded in 3DS format from the fps example. My code is like this:

texman_.addTexture("claymore", new Texture("models"+c+"male"+c+"claymore.jpg"));

....

            obj = Loader.loadMD2(tokens[1], 1f);
            obj.setTexture(tokens[3]);
            obj.setCenter(SimpleVector.ORIGIN);

(where tokens[1] is the filename and tokens[3] is "claymore")
...

obj.translate(800, -120, -480);
world_.addObject(obj);
...

world_.buildAllObjects();
camera_.setPosition(new SimpleVector(800, -120, -400));
...

I can see the 3DS level I loaded, but not the MD2 model. Is there anything I did wrong?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11749
    • View Profile
    • http://www.jpct.net
Object3D not displayed
« Reply #1 on: December 14, 2005, 10:09:22 pm »
When looking down the z-axis (default, if you don't rotate the view), your model (-480) is behind the camera (-400). Maybe that's the problem?

Anonymous

  • Guest
Object3D not displayed
« Reply #2 on: December 14, 2005, 10:44:21 pm »
Thanks for the fast answer, but I think that's not the problem. I also tried

obj.translate(800, -120, -320);

and

obj_rel_pos = camera_.getDirection();
obj_rel_pos.scalarMul(100f);
//obj_rel_pos.scalarMul(10f);
obj_rel_pos.add(camera_.getPosition());
obj.translate(obj_rel_pos);

to set the object in front of the camera.

Here are the relevant log messages:
Loading Texture...models/male/claymore.jpg
Loading file models/male/tris.md2
File models/male/tris.md2 loaded...278592 bytes
Magic number: 844121161
Version: 8
Skin width: 284
Skin height: 195
Frame size: 1300
Number of skins: 0
Number of Vertices: 315
Number of Texture coordinates: 473
Number of triangles: 590
Number of GL-commands: 3038
Number of Frames: 198
Reading Texture coordinates...
Done!
Reading polygonal data...
Done!
Reading keyframes...
Done!
Coverting MD2-format into jPCT-format...
Processing: stand...
Processing: run...
Processing: attack...
Processing: pain...
Processing: jump...
Processing: flip...
Processing: salute...
Processing: taunt...
Processing: wave...
Processing: point...
Processing: crstnd...
Processing: crwalk...
Processing: crattak...
Processing: crpain...
Processing: crdeath...
Processing: death...
Done!

They look all right to me.

I should probably mention that my game logic, display logic and input logic happen in different threads, but I'm pretty sure that that's not the problem either. Also, I am using the OpenGL renderer.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11749
    • View Profile
    • http://www.jpct.net
Object3D not displayed
« Reply #3 on: December 14, 2005, 11:36:27 pm »
Loading is fine IMHO. Try
Code: [Select]
camera_.lookAt(obj.getTransformedCenter()); to see, if this brings the object into view. I think you are somehow looking into the wrong direction. Or maybe just printing out obj.getTransformedCenter() would help to see, if the object is really located where it's supposed to be.
Doing the game logic in another thread is fine as long as you are not manipulating jPCT entities directly in that thread (i.e. don't do translations, rotations, collision detection etc) without synchronizing that with your rendering thread. Doing a rotation in the game logic thread while the render thread is using the matrix for rendering will most likely hurt you sooner or later. Anyway, that shouldn't be the cause of your problem.

Anonymous

  • Guest
Object3D not displayed
« Reply #4 on: December 15, 2005, 08:42:53 pm »
I just got it working - it was a problem with my code. Sorry to bother you and thanks for the help!