Some helpful Object3D,Camera, and SimpleVector functions

Started by Anonymous, March 19, 2003, 04:07:17 AM

Previous topic - Next topic

Anonymous

Ok, I think I've got the object manipulation figured out.  I needed to use SimpleVectors instead of Matricies :idea:

Ok on to some suggestions.
It would be helpful to have to some useful functions for the Camera
manipulation that are present in Object3D class. For example:
Camera.getXAxis(),Camera.getYAxis(), and Camera.getZAxis() would be helpful so that I can use the Camera.rotateAxis(SimpleVector axis,float angle) function on them. Or would it be better to do these operations on a Matrix and use the setBack() function (inherited from the BufferedMatrix class)?    
Also, I'm trying to write a simple space shooter in which my ship is at an arbitrary rotation on the X,Y, and Z axies.  I want to fire a projectile (which is an Object3D) from my ship and need to the projectile to be the same orientation as my ship before I fire it off.  How  do I go about this? Would be nice to have a function like such:
Object3D.copyOrientation(Object3D obj2) or Object3D.setOrientation(Object3d obj2).  This kind of function to set the orientation of an object the same as another object would be very helpful.  Another function that would be helpful is:
Object3D.setOrientation(Camera cam).  This would set an Objects orientation the same as the Camera.
or:
Camera.setOrientation(Object3D obj).  This would set the Cameras orientation the same as an Object3D's orientation.

SimpleVector functions

It would be nice to have a SimpleVector.scale(float scale) type of function
I'm using the following code to move an object forward

public void moveObject()
{
     float forward[3];
     SimpleVector xaxis=ship.getXAxis();
     SimpleVector zaxis=ship.getZAxis();
     /*would be nice to be able to scale my zaxis vector
        right here instead of doing the following line*/
     forward=zaxis.toArray();
     sphere1.translate(forward[0]*.2f,forward[1]*0.2f,forward[2]*0.2f);
     sphere1.rotateAxis(xaxis,xrot);
     sphere1.rotateAxis(zaxis,zrot);
}

Well, hopefully I didn't confuse you on what I'm trying to do  :?  This is a becoming a great pure java 3D engine and hopefully with the addition of a few more object and camera manipulation functions for dummies like me  :roll: it will become even better  :D I really Hope it gains popularity and keep up the good work!

p.s.  Thanks for putting flat shading in, works great for my low poly objects.

EgonOlsen

I guess what you want to do is to align a projectile (or another object) in a way so that it points into the direction of the camera (or an Object3D). Like firing a rocket from your ship into the ship's direction!?
I'll think about it later (don't have much time now...maybe next week).
About this part of your code:

forward=zaxis.toArray();
sphere1.translate(forward[0]*.2f,forward[1]*0.2f,forward[2]*0.2f);


...calling toArray() is not needed here. The x, y and z components of a SimpleVector are public members (for performance reasons), so you can access them directly like this:

sphere1.translate(zaxis.x*.2f, zaxis.y*0.2f, zaxis.z*0.2f);

Edit: I think i'm going to add the requested scale()-method to SimpleVector anyway...

Anonymous

Ok, thanks I forgot the x,y,and z members of SimpleVector were public.  

About that ship and projectile question.  Sounds like your were a little confused with what I was asking.  I'm going to be firing a projectile FROM my ship, I need to make sure the projectile is axis aligned with my ship before I send it off.  As I was saying before it would be handy to have functions that:
1. axis aligns a Object3D with another Object3D
2. axis aligns an Object3D with the camera
3. axis aligns an the camera with an Object3D

This can probably already be done with the existing functions but I'm not quite sure how, maybe I need to experiment a little more.

EgonOlsen

No, we are both confused now  :wink:  What you are describing is what i understood too. Maybe my wording wasn't that good...
Anyway, i'll think about it..next week or so...

EgonOlsen

0.86 is out and it comes with three align()-methods. Two in Object3D and one in Camera. Keep in mind that alignment always happens with the z-axis of either the camera or the object (depending on the method), i.e. if you want to make the camera facing into the direction of another axis than z, the rotation (from z to ...) has to be applied to the camera afterwards:

camera.align(obj); // the camera is now aligned with the positive z-axis of obj (transformed into worldspace)
camera.rotateY((float) Math.PI/2f); // Now it's aligned with the positive x-axis of obj
...


Something similar is required to align an object with another camera-axis than z. Here's an example of just one possibility:


// tmpCam is a temporary camera initialized somewhere and reused here
tmpCam.setBack(camera.getBack().cloneMatrix()); // clone it, to ensure that the rotation does not modify the normal camera
tmpCam.rotateY((float) Math.PI/2f);
obj.align(tmpCam); //The object's positive z-axis is now aligned to camera's negative x-axis


This may look more complicated then it actually is. In your case, you don't have to deal with these cases anyway, i assume. I just wanted to mention them here to show that it's possible even if the standard align()-behaviour is a kind of z-axis-matching. I hope that these new methods are helping you out. If not or if any other questions arrise, please let me know.

Anonymous

Thanks for the added functionality.  One question though.  Does the cloneMatrix() function create a new Object everytime therefore causing pauses in the garbage collector?  Or do you think it wont cause a problem.

EgonOlsen

Quote from: "Anonymous"Thanks for the added functionality.  One question though.  Does the cloneMatrix() function create a new Object everytime therefore causing pauses in the garbage collector?  Or do you think it wont cause a problem.
It does, but that shouldn't be too much of a problem. There are others ways that can be taken to avoid this (rotate the camera, do the alignment, rotate it back for example). But as i said: You usually don't need to do this, if you are happy with alignment with the z-axis (which should be the normal case for rockets, lasers etc.).
BTW: Albeit it does create a new matrix, i don't think that you'll ever notice pauses or hickups caused by the gc because of this.