Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2] 3
  ignore  |  Print  
  Xith3d progress  (Read 10545 times)
0 Members and 1 Guest are viewing this topic.
Offline DavidYazel

Junior Member




Java games rock!


« Reply #30 - Posted 2003-08-11 15:47:03 »

You need to have your rotate as a transform below your translate or else you will rotate your translation, which is what is happening here.

so it should be:

translate -> rotate -> model

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline aNt

Senior Member




AFK


« Reply #31 - Posted 2003-08-11 17:20:12 »

arrr!!! this is doing my head in - and its to HOT Cool

all i get is my object spinning on itself and moving. i have tryed all orders i can think of. i must be getting something realy wrong here.

Cry Cry Cry
Offline DavidYazel

Junior Member




Java games rock!


« Reply #32 - Posted 2003-08-11 17:26:43 »

Well your example there shows the model being added to the translation transform group.  It should be added to the rotation group and the rotation group should be added to the translate group.

That WILL work.  I do it all the time.

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline aNt

Senior Member




AFK


« Reply #33 - Posted 2003-08-11 22:20:31 »

yer i no it must be a snap.. i can do it in GL normal action.. maybe i need a book on java3d and stuff?

im probbly doing it all wrong anyways Smiley

if anyone can see where i am going wrong- ring me bell, i havent got to all the cool questions yet:

package ant.xith3dtest;

import com.xith3d.scenegraph.*;
import com.xith3d.render.*;
import com.xith3d.render.jogl.*;
import com.xith3d.loaders.ase.*;
import javax.vecmath.*;
import java.util.Random;
import com.xith3d.image.*;
import java.awt.image.*;
import java.io.*;
import com.xith3d.loaders.texture.*;
import java.util.ArrayList;

import net.java.games.input.*;

/**
* <p>Draws a simple cube on the screen</p>
* <p> </p>
* <p>Copyright (c) 2003 David Yazel Copyright (c) 2003</p>
* <p>Company: </p>
* @author David Yazel - aNt messing
* @version 1.0
*/

public class CubeTest3 {
 Keyboard kb = null;

 public CubeTest3() {
   Texture2D textureWood = null;
   TextureLoader.tf.registerPath("c:/xith3d/demo/");
   TextureLoader.tf.registerPath("./");
   TextureLoader.tf.registerPath("../");

   BranchGroup landModel = null;
   BranchGroup hellcatModel = null;

   try {
     hellcatModel = AseFile.getModel("hellcat.ase");
   } catch (Exception er) {
     System.out.println("cant load mod: " + er.toString());
   }

   Transform3D hellcat_translation = new Transform3D();
   Transform3D hellcat_rotation = new Transform3D();

   Vector3f hellcat_trans = new Vector3f();
   Vector3f hellcat_rota = new Vector3f();

   // create a transform and rotation for the hellcat.
   TransformGroup hellcat_group_trans = new TransformGroup(hellcat_translation);
   TransformGroup hellcat_group_rota = new TransformGroup(hellcat_rotation);

   // create a branch group to put in the locale
   BranchGroup top_group = new BranchGroup();
   BranchGroup hellcat_group = new BranchGroup();

   hellcat_group.addChild(hellcat_group_trans);
   hellcat_group_trans.addChild(hellcat_group_rota);
   hellcat_group_rota.addChild(hellcatModel);
   
   // have also tryed.
   // hellcat_group.addChild(hellcat_group_rota);
   // hellcat_group_rota.addChild(hellcat_group_trans);
   // hellcat_group_rota.addChild(hellcatModel);

   top_group.addChild(hellcat_group);

   VirtualUniverse universe = new VirtualUniverse();
   View view = new View();
   view.setFieldOfView(35f * 3.14f / 180f);
   Locale locale = new Locale();
   universe.addLocale(locale);
   universe.addView(view);

   locale.addBranchGraph(top_group);

   RenderPeer rp = new RenderPeerImpl();
   CanvasPeer cp = rp.makeCanvas(null, 640, 480, 32, false);
   Canvas3D canvas = new Canvas3D();
   canvas.set3DPeer(cp);
   canvas.setView(new View());

   view.addCanvas3D(canvas);

   view.getTransform().lookAt(new Vector3f(0, 0, 950f), new Vector3f(0, 0, 0),
                              new Vector3f(0, 1, 0));

   view.setTransparencySortingPolicy(view.TRANSPARENCY_SORT_GEOMETRY);
   // view.setSceneAntialiasingEnable(true);
   // Background bgcolor = new Background(new Color3f(0f, 0f, 1f));
   // view.addChild(bgcolor);
   ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
   Controller[] cont = ce.getControllers();

   System.out.println("cont: " + cont.length);
   for(int i = 0; i < cont.length; i++) {
     if(cont.getType() == cont.getType().KEYBOARD) {
       kb = (Keyboard) cont;
     }
   }

   long startTime = System.currentTimeMillis();
   long numFrames = 0;
   float anum = 0f;

   ////////////////////////////////////////////////// RENDER!
   for (int i = 0; i < 10000; i++) {
     numFrames++;

     keyboardupdate();

     hellcat_trans.z = hellcat_trans.z + -5f;
     hellcat_translation.setTranslation(hellcat_trans);
     hellcat_rotation.rotXYZ(updown, 0f, leftright);

     hellcat_group_trans.setTransform(hellcat_translation);
     hellcat_group_rota.setTransform(hellcat_rotation);

     view.getTransform().lookAt(new Vector3f(0f, 0f, 1000f),
                                new Vector3f(0f, 0f, 1f), new Vector3f(0, 1, 0));

     view.renderOnce();
   }


   long deltaTime = (System.currentTimeMillis() - startTime) / 1000;

   if (deltaTime > 0) {
     System.out.println("done frame speed test at " + (numFrames) / (deltaTime) +
                        " fps");
     System.out.println("there are " + canvas.get3DPeer().getTriangles() +
                        " triangles in scene");
     System.out.println("rendering " +
                        canvas.get3DPeer().getTriangles() * (numFrames) /
                        (deltaTime) + " triangles/sec");

   }
   System.out.println("   Num frames = " + numFrames);
   System.out.println("   Delta ms = " + deltaTime);

   System.exit(0);
 }

 float updown = 0f;
 float leftright = 0f;

 public void keyboardupdate() {
   kb.poll();
   Axis[] ax = kb.getAxes();

   for (int x = 0; x < ax.length; x++) {
     float num = ax
  • .getPollData();
         if (num != ax
  • .getDeadZone()) {
           // System.out.println("key: " + ax
  • .getName());
           if (ax
  • .getName().equalsIgnoreCase("key 113")) {
             // System.out.println("right arrow");
             leftright = (leftright - 0.01f);
           }

           if (ax
  • .getName().equalsIgnoreCase("key 112")) {
             // System.out.println("left arrow");
             leftright = (leftright + 0.01f);
           }

           if (ax
  • .getName().equalsIgnoreCase("key 110")) {
             // System.out.println("up arrow");
             updown = (updown - 0.01f);
           }

           if (ax
  • .getName().equalsIgnoreCase("key 115")) {
             // System.out.println("down arrow");
             updown = (updown + 0.01f);
           }
         }
       }
     }

     public static void main(String[] args) {
       CubeTest3 cubeTest1 = new CubeTest3();
     }
    }
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #34 - Posted 2003-08-12 00:04:51 »

aNt,

I am currently experiancing the exact same problem as you - and it is driving me nuts.  I spent countless hours last night trying to get it to work but to no avail.  This morning I tried with a simple cube and still no cigar.

This is code that I ported from j3d and was working fine in j3d.  I thought I understood this concept.  Back when I was using gl4java I encountered and solved (easily) the same problem.  And I have a few books on j3d/opengl to assist.  I have compiled and run my code so many times that my processor has almost melted.

Seriously though, here is the problem.

Take a small cube, at the position  10, 10, 0.  (ie. 10 to the right, and 10 up).
1  
2  
3  
4  
5  
6  
7  
             |             [_]
             |            
             |            
_______________
             |            
             |            
             |            


Now I want to rotate that cube in place.
1  
2  
3  
4  
5  
6  
7  
             |             \_\
             |            
             |            
_______________
             |            
             |            
             |            


How I did it with straight OpenGL calls and j3d was this:
Move the cube to (0,0,0) >  rotate it > move back to (10,10,0).
Rotating without that move caused it to rotate (or orbit) around the (0,0,0) "pivot point" which is correct but not wanted in my case.

not wanted:
1  
2  
3  
4  
5  
6  
7  
             |             [_]
             |                 [_]
             |                  
_______________
             |                [_]
             |              [_]
             |             etc...


Now no matter what I tried last night and this morning I can not get any object in Xith3D to change it's "point of rotation".
move to origin > rotate > move back simply has the same effect as
rotate
move to some place > rotate just moves the whole bloody thing to a different area.
So no matter what I wanted the "Reference point/pivot point/point of rotation" to be for the rotation - I always go the same (see "not wanted" ASCII diagram).  It seemed like moving the object moved it's origin as well and thus I just couldn't rotate it around an arbitrary reference.


Now, sure - I could simply load the object in relitive to (0,0,0) but this is a work around and I have spent too many hours trying the other way that I must as least know how to do it correctly (and then I won't mind about applying any work arounds).

This was tested using a Single TransformGroup so no funny stuff is happening with TransformGroup children.

here is a handy method that recursivly prints the contects of a group.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
            public static void printGroup (Group g, String offset) {
                 
                  System.out.println(offset + (g.getClass().getName()));
                 
                  for (int i = 0; i < g.numChildren(); i++) {
                        Class c = g.getChild(i).getClass();
                       
                       
                       
                        if (c.getName().lastIndexOf("Group") != -1)
                              printGroup((Group) g.getChild(i), offset + "  ");
                        else
                              System.out.println(offset + "  " + c.getName() + " group");
                  }
            }


This is my very simple cube, so as you can see no funny stuff:
1  
2  
3  
com.xith3d.scenegraph.TransformGroup
  com.xith3d.scenegraph.BranchGroup      
    com.xith3d.scenegraph.Shape3D


I am using Xith3d from CVS and keeping up to date which I am hoping fixes more problems than it introduces however it is a double edged sword.

What am I doing wrong?  I thought I understood the transform concept and have managed to do this exact thing fine in OpenGL and j3d.  But I am running out of ideas for this one.

I can easily do my work around and I know that will work - but I refuse to believe that it isn't possbile this way.

Please tell me what you think.

Cheers,

Will.

[edit: formatting, correcting]
[edit: aNt, I wish I had read your posts before hitting the same brick wall myself and trying a similar cube test - it would have saved me some time but at least now there are two case studies :D]

Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #35 - Posted 2003-08-12 00:30:00 »

Here is a code snippet from one of my many tries at solving this connundrum.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
  // setup rotation transform (angleYAxis is passed).
                 Transform3D angle = new Transform3D();
                  angle.setIdentity();
                  angle.rotAxis(new Vector3f(0f,0f,1f), (float)((angleYAxis) * Math.PI / 180.0));

// apply move transform
                 Transform3D t = new Transform3D();
                  geomRoot.getTransform(t);
                  t.setTranslation(new Vector3f(-10,10,0));
                  geomRoot.setTransform(t);

// apply rotation transform
                 t = new Transform3D();
                  geomRoot.getTransform(t);
                  t.mul(angle);
                  geomRoot.setTransform(t);

// apply move back transform
                 t = new Transform3D();
                  geomRoot.getTransform(t);
                  t.setTranslation(new Vector3f(10,10,0));
                  geomRoot.setTransform(t);


geomRoot is the only TransformGroup in the scene.

I tried several different permetations but not once did the "Reference point" around which the object is rotated change in relation to the placement of the object.

I won't bother posting all of my code - but suffice to say that in concept is it is just about the same as aNt's.

[edit]
I have also tried making a tree of TransformGroups, in the order:
rotation > translate to reference point > model

but to no avail
[/edit]

Cheers,

Will.

Offline aNt

Senior Member




AFK


« Reply #36 - Posted 2003-08-12 09:52:42 »

well i dont no- i have tryed loads of stuff now. even to the stange of pot luck.

i can translate the object and have it rotate around its self in it new translated location. and i can rotate the object and have it rotate around a 0,0,0 Vurtual Univerce. i cant get it to rotate then translate(along z of the new rotated vector) from its new translated location (like a aircraft).

so i can do this:

   |
   |   [ ]
   |      ]
   |     .... move around rotate around the VurtulUni


i can also do this:

   |       [ ]
   |     ---
   |     ---
   |  /  /
   |[ ]
------------------ translate -> rotate -> model
   | move and rotate on itself


what i want to do is this:

   |  --- ---
   |  --- --- \  \
   | /  /       [ ]
   |/  /        \  \
   |[ ]
------------------ ?? dont no.... [translate -> rotate -> translate -> model ? maybe.. didnt work Sad ]
   | fly around the space
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #37 - Posted 2003-08-12 13:00:38 »

The difference between your second and third cases is not clear to me.

Stepping back and thinking of a single frame of animation..  you have the location of your jet fighter and the direction that it is facing.

That's one translate to set the location.
One rotate to set the heading.

Now you have it in the right place facing the right direction.. what more do you want?

Offline aNt

Senior Member




AFK


« Reply #38 - Posted 2003-08-12 13:12:04 »

it seems to reset evey time. the second one is every update.. so the cube is just moving out to a point, and rotating on itself. the next draw update it gets moved out more and rotates on its self.

its not heading in the direction of the new rotation tranform. it just keeps heading into z, with the object spining around itself without a care.

Quote
Now you have it in the right place facing the right direction.. what more do you want?


i would like it to move in the direction of the rotation. and then on the next update just tell the transform to move in z a little bit more. and because the rotation vector has changed - it heads off in that new changed direction.

at the moment the transform just keeps heading off into z without a care of the rotations change in direction.
Offline DavidYazel

Junior Member




Java games rock!


« Reply #39 - Posted 2003-08-12 13:39:41 »

OK this could be a bug.  Could you e-mail a test program to david@yazel.net and I will look at it tonight.  

It sounds like that a change to a parent transform is causing information in a child transform to be ignored.  I could see the possibility of a bug here because the optimization I have in the scenegraph for transform chaining are a bit tricky.

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #40 - Posted 2003-08-12 14:21:21 »

Quote
its not heading in the direction of the new rotation tranform. it just keeps heading into z, with the object spining around itself without a care.


i would like it to move in the direction of the rotation. and then on the next update just tell the transform to move in z a little bit more. and because the rotation vector has changed - it heads off in that new changed direction.

But, looking at your example code you only have one translation followed by one rotation..  If you only ever adjust the Z coordinate of the translation then rotate after that you will never move along anything but the Z axis.

To move the object in the direction of the heading. you will need to rotate the vector that you are adding to the translation vector.  

E.g. the code way above always adds 0,0,-5 to the translation vector.  that is assuming the heading is always 0,0,-1  (normalized vector heading into the monitor along the z axis)

If you want to move the ship in the direction of the heading you must take the 0,0,-5 vector, rotate it by the same rotation as the ship heading, then add it to the translation.  That way you will change the x,y coordinates of the object not just the z coordinate.  E.g. don't always move along the z axis, because unless you are also rotating before your transform that will appear as the object following a straight line, regardless of how the object is oriented.

Draw the movements on a piece of graph paper..

if you have
1  
2  
3  
4  
5  
6  
7  
8  
9  
-z
|              b
|
|
|                              c
|
|
| a
--------------------------+x

and you want the object to travel from a to b, then from b to c,
your translation can't add just to the z coordinate.. you are moving along the +ve x axis as well.  You need to rotate the 0,0,-1 vector so that it points toward 'b' before adding it to the current translation that got you to point 'a'.  then when you reach point 'b' you would need to change the 0,0,-1 vector to point parallel to the line bc before adding it to the current translation.

If you want to keep your translation as holding the world coordinates of the object, you must rotate the velocity vector
that you are adding to the position (translation) vector. It sounds as if you are mixing polar coordinates in with this and getting into a messy chain of translations and rotations

Offline aNt

Senior Member




AFK


« Reply #41 - Posted 2003-08-12 14:32:19 »

     Transform3D tempTrans = new Transform3D();
     Transform3D ourTrans = new Transform3D();
     hellcat_group_trans.getTransform(ourTrans);
     tempTrans.rotXYZ(updown, 0f, leftright);
     // tempTrans.rotZ(leftright);
     tempTrans.setTranslation(new Vector3f(0.0f, 0.0f, -1f));
     ourTrans.mul(tempTrans);
     hellcat_group_trans.setTransform(ourTrans);

done it.. only need one group.. and u need to get and add to the transtation Smiley.
Offline DavidYazel

Junior Member




Java games rock!


« Reply #42 - Posted 2003-08-12 14:42:29 »

Well, yes and no Smiley

You basically worked around what could be a bug.  You are concatonating the rotation and translation matrix yourself.  What you did there should be identical to having a nested transform.

I am still going to investigate the possibility of a bug in Xith3d here.

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline aNt

Senior Member




AFK


« Reply #43 - Posted 2003-08-12 15:49:31 »

nice one dude Smiley

ok how do i set the near far clipping plane of the view?

<- doing more action...
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #44 - Posted 2003-08-12 23:10:12 »

Quote
it seems to reset evey time


In six words, I think that describes my exact problem too Smiley

Quote
You basically worked around what could be a bug.  You are concatonating the rotation and translation matrix yourself.  What you did there should be identical to having a nested transform.


David, thanks for looking into it I shall boil my code down to a small test case and get it to you today hopefully.

If it's a bug i'm quite surprised you wouldn't have found it when porting Cosm.  Is that game up and running yet?

Cheers,

Will.

Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #45 - Posted 2003-08-13 08:22:05 »

I have emailed David, but for anyone else who is interested, my test case is here:

http://tanksoftware.com/dev/xith-test-case01.zip

Quote

basically I load a small cube which is at position (10,10,0) then try to move
it to the origin by the translation(-10,-10,0) rotate it and move it back.

I tried about 5 different ways of doing this same thing and they all more or
less turned out exactally the same.


here is the problem code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
       public void turn (float angle) {
             
            // convert to radians
           angle = (float)((angle) * Math.PI / 180.0);
           
            // angle of rotation
           Transform3D angleTrans = new Transform3D();
            angleTrans.setIdentity();
            angleTrans.rotAxis(new Vector3f(0f,0f,1f), angle);

            //distances to origin
           float xDis = -10;
            float yDis = -10;
            float zDis = 0;
           
            // move transform moves to origin
           Transform3D move = new Transform3D();
            move.setIdentity();
            move.setTranslation(new Vector3f(xDis,yDis,zDis));
           
            // move back transform - oppsotie of move transform
           Transform3D back = new Transform3D();
            back.setIdentity();
            back.setTranslation(new Vector3f(-1 * xDis,-1 * yDis,-1 * zDis));

           
           
            Transform3D t3 = new Transform3D();
            geomRoot.getTransform(t3);
           
            t3.mul(move); //move cube to origin
           t3.mul(angleTrans); //rotate
           t3.mul(back); //move back in it's rotated state
           
            geomRoot.setTransform(t3);
           

           
      }

geomRoot is a TransformGroup containing said cube loaded from the ASE loader.

Cheers,

Will.

Offline abies

Senior Member





« Reply #46 - Posted 2003-08-13 10:05:19 »

As far as I understand transforms, rotating and then multiplying by reverse translation will not get you back to origin, because translation will be already applied to turned transform. I think that you need to transform reverse translation by 2nd stage matrix and then apply it as third stage - this way, you should be back at zero.
But I don't think you will get what you want - I do not think it is possible at all. To achieve what you want, you would need few stage transform, which is applied to every point in order, at each stage using already x,y,z from this stage (not from original point as it is with multiplied transforms).

My suggestion - center you shapes around 0 Smiley

Artur Biesiadowski
Offline aNt

Senior Member




AFK


« Reply #47 - Posted 2003-08-13 12:04:17 »

view.setBackClipDistance(10000f);

dont seem to do anything..
Offline DavidYazel

Junior Member




Java games rock!


« Reply #48 - Posted 2003-08-13 14:37:17 »

I will take a look at the file you sent me.  Also, the clips are not being set from the view settings, that is a bug.

I have almost completed the terrain system for Xith3d.  I will be posting it within a couple of days.

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline aNt

Senior Member




AFK


« Reply #49 - Posted 2003-08-13 16:37:02 »

sweet!!!!!!!!
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #50 - Posted 2003-08-13 21:42:13 »

abies,

What I am trying to achieve is definitally possible.  I have done it both in OpenGL (GL4Java) and j3d.  Centering the object before loading it is the work around which I can do however it should be possible not to have to do it that way and since I have sunk so much time into trying I will not quit untill I have found how to do it in Xith3d.

Here is code that worked in j3d.  If you don't believe me I can send you the entire source.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
            /**
             * Rotate around the X and Y axies
             */

            public void tiltXYAxis (float angleXAxis, float angleYAxis) {
                 
                  Transform3D angle = new Transform3D();
                  Transform3D orig = new Transform3D();
                  Transform3D back = new Transform3D();
                  Vector3d tmpVector = new Vector3d (3.6,3.5,0); //set rotation reference point

                  Transform3D t3d = new Transform3D();
                  geomRoot.getTransform(t3d);
                 
                  orig.setTranslation(tmpVector); // reference point translation
                 back.invert(orig); // inverse reference point
                 
                  // angle rotation
                 angle.setRotation(new AxisAngle4f (1f,0f,0f,(float)((angleXAxis) * Math.PI / 180.0)));
                  angle.setRotation(new AxisAngle4f (0f,0f,1f,(float)((angleYAxis) * Math.PI / 180.0)));
                 
                  t3d.set(initt); // move to starting location (which is not (0,0,0)
                 t3d.mul(orig); // apply move to origin
                 t3d.mul(angle); //rotate
                 t3d.mul(back); // move back
                 geomRoot.setTransform(t3d);
                 
            }

geomRoot is a TransformGroup.  A note that in this program I use x,y,z from a top down perspective - ie. substituting z and y.  This makes more sense for this app as it is a top down view and z is best suited for height.  Just personal preference however it doesn't effect the actuall code at all.

Xith3d doens't have a setRotation(AxisAngle4f) method however I found a way to substitute that using the methods it does have.

Perhaps my test case is not 100% correct but it should be possible.

Cheers,

Will.

Offline abies

Senior Member





« Reply #51 - Posted 2003-08-14 07:19:33 »

Well, I have checked it at home and it indeed seems to be possible to rotate around arbitrary point. Mea culpa.

In your second example
angle.setRotation(new AxisAngle4f (1f,0f,0f,(float)((angleXAxis) * Math.PI / 180.0)));
angle.setRotation(new AxisAngle4f (0f,0f,1f,(float)((angleYAxis) * Math.PI / 180.0)));

First line has no effect ? AFAIK setRotation replaces transform rotation component instead of multiplying it ?

Artur Biesiadowski
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #52 - Posted 2003-08-14 09:12:33 »

abies,

I think you are right about the first line - it probably does squat.  Since i never actually rotated anything around the X axis in this particular program I never noticed the bug.  Thanks Smiley.

David,

Thank you for looking at my test case.

Incidentally is there any reason why setRotation(AxisAngle4f) was removed from the API?


For anyone that did use it - here is a little static method that I have used to replace it:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
      // replacement for Transform3D.setRotation(AxisAngle4f)
     // t.setRotation(new AxisAngle4f (1f,0f,0f,angle));
     // becomes
     // Object3D.setRotation(t, new Vector3f(1f,0f,0f), angle);
       //
     public static void setRotation(Transform3D trans, Vector3f axis, float angle) {
           
            // Gets the rotation matrix
           Transform3D rotation = new Transform3D();
            rotation.rotAxis(axis, angle);
            Matrix3f rotationMatrix = new Matrix3f();
            rotation.getRotation(rotationMatrix);
           
            // Applies rotation matrix to passed Transform3D  in a non destructive manner
           trans.setRotation(rotationMatrix);      
           
      }

Offline aNt

Senior Member




AFK


« Reply #53 - Posted 2003-08-15 12:26:24 »

new cvs - all complied and stuff.

but still Background dont seem to work Sad. or maybe i am using it wrong.. also view.setBackClipDistance(50000f); dont seem to do anything Smiley..

maybe i is testing updates to fast - hehehe...

keep on rolling the rock dudes

Offline aNt

Senior Member




AFK


« Reply #54 - Posted 2003-08-15 12:42:33 »

also i seem to find the shading is abit FLAT. As u can see from my screen shot. my Hellcat is compleatly blue at some angles:



can i change this someplace?
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #55 - Posted 2003-08-15 23:06:33 »

Could it be the normals?  I'm not sure how Xith3d deals with them but I know that the shading can go haywire using OpenGL if all the normals are pointing in the same direction which could be one reason for that effect.  What format is the model in?

Will.

Offline DavidYazel

Junior Member




Java games rock!


« Reply #56 - Posted 2003-08-16 00:23:43 »

Or it could be the total lack of supports for lights Smiley  Looks like I better get that done!

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #57 - Posted 2003-08-16 01:49:23 »

I think I found that pesky rotation bug Cheesy

From the Xith3d source:
1  
2  
3  
4  
5  
6  
7  
8  
    /**
     * Sets the rotation by replacing the upper 3x3 matrix values of
     * this transform with the values in the Matrix3f m. The other
     * elements of this transform are unchanged.
     */

    public final void setRotation(Matrix3f m) {
        matrix.set(m);
    }


From the javax.vecmath.Matrix4f javadocs:
1  
2  
set(Matrix3f m1)
          Sets the rotational component (upper 3x3) of this matrix to the matrix values in the single precision Matrix3f argument; the other elements of this matrix are initialized as if this were an identity matrix (i.e., affine matrix with no translational component).


The conflict is that Xith3d claims NOT to be reseting the other elements but the javax.vecmath IS reseting it.

I tried various things to correct this problem in com.xith3d.scenegraph.Transform3D - but then saw this in the docs: again from javax.vecmath.Matrix4f
1  
2  
setRotation(Matrix3f m1)
          Sets the rotational component (upper 3x3) of this matrix to the matrix values in the single precision Matrix3f argument; the other elements of this matrix are unchanged; a singular value decomposition is performed on this object's upper 3x3 matrix to factor out the scale, then this object's upper 3x3 matrix components are replaced by the passed rotation components, and then the scale is reapplied to the rotational components.


Using setRotation instead of plain set - I changed the method in com.xith3d.scenegraph.Transform3D:
1  
2  
3  
4  
5  
6  
7  
8  
9  
    /**
     * Sets the rotation by replacing the upper 3x3 matrix values of
     * this transform with the values in the Matrix3f m. The other
     * elements of this transform are unchanged.
     */

    public final void setRotation(Matrix3f m) {
        matrix.setRotation(m);
     
    }


And that seemed to fix the problem Cheesy

This explains why aNt had to have a tree of TransformGroups to do his rotation stuff - and why I had to do the same with my scaling (which I wanted only to set once).  The reason it _would_ work with the nested TransformGroups - is that how the scenegraph works out the final single matrix is it multiplies them all up nullifying the effect that setRotation had by setting the identity.

With the fix applied you don't need these extra TransformGroups.  I tested this on my code and could successfully remove the nested TG in question, and it still worked exactally the same (which is better - as I didn't think nested TG's were nessesary, afterall OpenGL doesn't have this concept and only has a single transform matrix).  Basically anything you can do with a TransformGroup inside a TransformGroup you should be able to do with just the one I think - not that that changes the fact that TransformGroups are still very usefull.

David - if you are happy with the bug fix, could you please patch the CVS source (I havn't faxed my agreement yet).

Cheers,

Will.

Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #58 - Posted 2003-08-16 08:12:35 »

Here is a method I have coded to mimmick the Transform3D.setRotation(AxisAngle3f) from Java3d.  Technically it is redundant to have so many setRotation methods - but since Xith3d follows the j3d API I think it should be included for completeness.

In Transform3D.java :-
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
    /**
     * Rotates the matrix around the passed axis by the passed angle.
     * Non rotational elements are unchanged.
     * @param a1 Rotation amount and axis of rotation
     */

    public final void setRotation(AxisAngle4f a1) {
     
      // Extracts the axis
     Vector3f axis = new Vector3f(a1.x, a1.y, a1.z);
     
      // Extracts the angle
     float angle = a1.angle;
     
      // Calculates the rotation matrix by rotating a Transform
     Transform3D rotation = new Transform3D();
      Matrix3f rotationMatrix = new Matrix3f();
      rotation.rotAxis(axis, angle);  //performs the rotation
     rotation.getRotation(rotationMatrix); //extracts the rotation
     
      // Applies rotation matrix to the current Transform3D
     setRotation(rotationMatrix);      
    }


I have tested it and it worked as expected (so long as my fix from my previous post in this thread is also applied).

It is similar to the static method I posted earlier - but this one is in the Transform3D class and I believe is true to the original counterpart method from Java3D.

Cheers,

Will.

Offline aNt

Senior Member




AFK


« Reply #59 - Posted 2003-08-18 06:55:00 »

View works now - nice one Smiley

is there any docs or info on the 'xith_utilities.jar' stuff. it looks intresting dude!

oh and just messing with the Terrain stuff. what sort of file duss it exspect? grayscale? jpg/png? oh and how do u add the Terrain to a say 'BranchGroup'. so to render it.

top stuff. any news on lights? Wink - keeping it going...
Pages: 1 [2] 3
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (25 views)
2014-04-15 18:08:23

BurntPizza (20 views)
2014-04-15 03:46:01

UprightPath (36 views)
2014-04-14 17:39:50

UprightPath (18 views)
2014-04-14 17:35:47

Porlus (34 views)
2014-04-14 15:48:38

tom_mai78101 (60 views)
2014-04-10 04:04:31

BurntPizza (118 views)
2014-04-08 23:06:04

tom_mai78101 (218 views)
2014-04-05 13:34:39

trollwarrior1 (185 views)
2014-04-04 12:06:45

CJLetsGame (192 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!