Skip to main content

3dobject->rotate matrix->projection (need help)

4 replies [Last post]
america70
Offline
Joined: 2007-01-21

Hi,guys!

I have a 3d-object. I need a projection of it using matrix of rotation. I have already done 3/4 of my program... but I don't know how to get matrix(when object is rotating), change geometry of the projection and print matrix on the screen.

screenshot:
http://www.box.net/index.php?rm=box_v2_download_shared_file&file_id=f_38...

How to do it?

import com.sun.j3d.utils.universe.SimpleUniverse;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.Transform3D;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.geometry.Text2D;

import com.sun.j3d.utils.geometry.*;
import javax.vecmath.*;
import javax.media.j3d.LineStripArray;
import javax.media.j3d.TriangleFanArray;
import javax.media.j3d.Geometry;
import javax.media.j3d.Appearance;
import javax.media.j3d.Shape3D;
import javax.media.j3d.BoundingSphere;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import javax.media.j3d.LineStripArray;

import javax.swing.JFrame;
import java.lang.String;
import javax.media.j3d.Text3D;
import javax.media.j3d.Font3D;
import java.awt.Font;
import javax.media.j3d.FontExtrusion;

public class gem extends JFrame {

//parameters======================================================
float r = 0.3f;
int N = 40;
int s=10;
//yge ne parameters===============================================

private float level(int c){
float m=0;

if((c>1)||(c

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
zesharp
Offline
Joined: 2006-12-21

You can get your matrix using

[code]
// this is a copy!!
// not a reference
tg.getTransform(tr3d);
[/code]

You can also subclass MouseRotate and override method transformChanged(Transform3D t3d) to print out your transform3D.
Like this

[code]
public class MyMouseRotate extends MouseRotate{

@Override
public void transformChanged( Transform3D t3d ) {
Sytem.out.printn(t3d);
}
}
[/code]

btw, avoid using variables starting with uppercase in the first letter. This hurts Java naming convenctions :
http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html

zesharp
Offline
Joined: 2006-12-21

Sorry, I have to time to study your code,
but here goes my 2 cents.

When you have a scene like this

bg -> tg -> shape3D

you can get your transform matrix this way

[code]
Transform3D t3d = new Transform3D()
// get a copy
tg.getTransform(t3d);

// get 4x4 matrix
Matrix4d m4x4 = new Matrix4d();
//copy
t3d.get(m4x4);

// get rotational 3x3 matrix
Matrix3d m3x3 = new Matrix3d();
//copy
t3d.get(m3x3);

[/code]

Of course you must set proper capability bits to read Transform3D from your TransformGroup tg. (ALLOW_TRANSFORM_READ)

tips:
You can use Swing to display your matrix (JTextArea perhaps);
MatrixXX classes has a toString() method to print out content values.

america70
Offline
Joined: 2007-01-21

Thank you for response!

I am using mouse to rotate my object.
[code]
TransformGroup TG=new TransformGroup();
TG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

MouseRotation mouseSpin = new MouseRotate();
mouseSpin.setSchedulingBounds(bounds);
mouseSpin.setTransformGroup(TG);

Transform3D Tr3D=new Transform3D();
TG.addChild(Tr3D);
[/code]

Will mouseSpin have effect on matrix of Tr3D?

america70
Offline
Joined: 2007-01-21

I think not:/