www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: theFALCO on December 12, 2006, 08:24:21 pm

Title: rotation problem (it moves)
Post by: theFALCO on December 12, 2006, 08:24:21 pm
I'm rotating my cube like so:
Code: [Select]
               if(right) {
                    cube.rotateY(0.01f);
                    cube.translate(cube.getYAxis());
                }


when I rotate it, it moves down (while rotating), and when I rotate it the similar way with the X axis it moves right (while rotating).

any idea why it acts like that and how to fix it?
Title: rotation problem (it moves)
Post by: cyberkilla on December 12, 2006, 08:43:39 pm
If you just want it to rotate, I am pretty sure you dont need
the last line of code.

Maybe I don't get what your trying to do;)
Title: rotation problem (it moves)
Post by: theFALCO on December 12, 2006, 08:53:04 pm
yes but then it rotates very strange... from the begining while rotating up/down it behaves as it shoul - it changes it's pitch, when i turn it 90 deg to the right/left then up/down makes it to roll (become like up side down)
Title: rotation problem (it moves)
Post by: Mizuki Takase on December 12, 2006, 08:53:56 pm
Hee hee, cyberkilla is right. Translating is when you want to move.
Title: rotation problem (it moves)
Post by: cyberkilla on December 12, 2006, 09:02:46 pm
So it rotates but not around its center of origin?
Is this the problem?
Title: rotation problem (it moves)
Post by: Mizuki Takase on December 12, 2006, 09:07:28 pm
Object3D does have a function called setOrigin(SimpleVector)... Maybe you need to do that first... I am not sure~~ Maybe cube.setOrigin(new SimpleVector(0,0,0)); But then again, I always thought that this origin should be the default...

[edit]Oh right! I remember looking at your code, you did change the origin of your cube after creation... Maybe you should remove that line from your code and see what happens? I still do not know why you would have that problem since you did set it to 0,0,0
Title: rotation problem (it moves)
Post by: cyberkilla on December 12, 2006, 09:12:54 pm
Well, im guessing thats the problem.

When the object is created, the center of the bounding box appears to be set
as the origin.
Thats the assumption im working on anyway;)
Title: rotation problem (it moves)
Post by: theFALCO on December 12, 2006, 09:48:32 pm
i have created 4 balls: up, down, left and right to visualize it better

what i see is that it seems like it's rotating around the same unchangable axis... what I mean is when the cube rotates, the pivot, axis or whatever it is, doesn't (the cube rotates using some global axis, not it's local) so when it becomes "from the left side" it is rotated as thought it's side was the front... or like so

maybe I forgot something like: cube.recalculateThePivotAndOtherRotationStuffSoThatYouDontHaveProblemsRotatingThisCubeThatYouWasSoHappyAbout();
Title: rotation problem (it moves)
Post by: Mizuki Takase on December 12, 2006, 09:56:25 pm
I am very clueless on the reply, but anyway! I think that this may help?

Object3D.rotateMesh()
Quote
Rotates the raw mesh data using the rotation matrix specified for this object.


You use that after you set the rotation.. There is also a translateMesh(), but that's out of topic...
Title: rotation problem (it moves)
Post by: EgonOlsen on December 12, 2006, 09:57:16 pm
First of all, there's a method called setRotationPivot() to set the...rotation pivot  :wink: By default, this is set to the calculated center of the object, which is the average of its vertices. For a cube, it's the center.

The rotate?-methods are rotating around a fixed axis, that's correct. If you don't want that, you may use the rotateAxis()-method instead and feed it with the axis you want to rotate around. That should work.
Title: rotation problem (it moves)
Post by: Mizuki Takase on December 12, 2006, 10:02:16 pm
The god has spoken and now I am enlightened... I know that someday, whenever I get serious with game programming, I will need to know that... Thanks..
Title: rotation problem (it moves)
Post by: theFALCO on December 13, 2006, 03:57:24 pm
oh, yes I see it in the FPS example
Code: [Select]
     if (left) {
         camera.rotateAxis(camera.getBack().getYAxis(), -TURN_SPEED);
         playerDirection.rotateY(-TURN_SPEED);
      }
      if (right) {
         camera.rotateAxis(camera.getBack().getYAxis(), TURN_SPEED);
         playerDirection.rotateY(TURN_SPEED);
      }

I'll try it
Title: rotation problem (it moves)
Post by: theFALCO on December 13, 2006, 08:29:12 pm
nope, still have problems  :(
Title: rotation problem (it moves)
Post by: EgonOlsen on December 13, 2006, 10:23:04 pm
Of which kind?
Title: rotation problem (it moves)
Post by: theFALCO on December 14, 2006, 07:43:11 pm
this is the starting position:
(http://img440.imageshack.us/img440/3977/1am8.jpg)
this shows that from this orientation the up/down rotation is good:
(http://img335.imageshack.us/img335/4695/2sd1.jpg)
but when I turn left (the ball is one of those four balls which I added for better orientation):
(http://img335.imageshack.us/img335/40/3zh7.jpg)
the up/down rotation looks like this:
(http://img72.imageshack.us/img72/322/4tn5.jpg)
(http://img335.imageshack.us/img335/3231/5ro7.jpg)
Title: rotation problem (it moves)
Post by: EgonOlsen on December 14, 2006, 08:10:43 pm
I see...so how does the code that does this looks exactly?
Title: rotation problem (it moves)
Post by: theFALCO on December 14, 2006, 08:22:49 pm
cube init:
private Object3D cube = Primitives.getCube(1);
...
        cube.setOrigin(new SimpleVector(0, 0, 0));
        cube.setBaseTexture("teks");
        cube.setTexture("teks");
        cube.setTranslationMatrix(new Matrix());
... // then goes the theWorld.add(cube); and buildAll();

Code: [Select]
   private void gameLoop() {
        World.setDefaultThread(Thread.currentThread());
        buffer=new FrameBuffer(width, height, FrameBuffer.SAMPLINGMODE_NORMAL);
        buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE);
        buffer.setBoundingBoxMode(FrameBuffer.BOUNDINGBOX_NOT_USED);
        buffer.optimizeBufferAccess();
        Timer timer = new Timer(25);
        timer.start();

        while(!exit) {
            if(!isIdle) {
                buffer.clear();
                theWorld.renderScene(buffer);
                theWorld.draw(buffer);
                buffer.update();
                poll();
                camera.setPosition(cube.getTransformedCenter());
                camera.align(cube);
                if(right) {
                    cube.rotateAxis(camera.getBack().getYAxis(), 0.01f);
                    cube.rotateY(0.01f);
                }
                if(left) {
                    cube.rotateAxis(camera.getBack().getYAxis(), 0.01f);
                    cube.rotateY(-0.01f);
                }
                if(up) {
                    cube.rotateAxis(camera.getBack().getXAxis(), 0.01f);
                    cube.rotateX(0.01f);
                }
                if(down) {
                    cube.rotateAxis(camera.getBack().getXAxis(), -0.01f);
                    cube.rotateX(-0.01f);
                }
                camera.setPosition(cube.getTransformedCenter());
                camera.align(cube);
                //camera.moveCamera(Camera.CAMERA_MOVEOUT, 10);
                buffer.display(gFrame, leftBorderWidth, titleBarHeight);
                Thread.yield();
            }
        }
        if (openGL) {
            buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
        } else {
            if (fullscreen) {
                device.setFullScreenWindow(null);
            }
        }
        System.exit(0);
    }
Title: rotation problem (it moves)
Post by: EgonOlsen on December 14, 2006, 08:26:28 pm
Rotate one entity, not a mixture of cube and camera...that may work somehow, but seems to be too confusing to me. Try to change

Code: [Select]

if(right) {
    cube.rotateAxis(camera.getBack().getYAxis(), 0.01f);
    cube.rotateY(0.01f);
}


to

Code: [Select]
if(right) {
    cube.rotateAxis(cube.getYAxis(), 0.01f);
}


and the other rotations accordingly.
Title: rotation problem (it moves)
Post by: theFALCO on December 14, 2006, 08:37:25 pm
cool, it works
thanks  :D