Hello,
i want to write a sprite3D class, wich has the basic features of moving.
But i have several Problems which i can t solve on my own :
Here is my code:
/*
* Created on 05.05.2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package de.TWOmas.xith.sprite;
import java.text.DecimalFormat;
import javax.vecmath.Point3d;
import javax.vecmath.Tuple3f;
import javax.vecmath.Vector3f;
import com.xith3d.scenegraph.Switch;
import com.xith3d.scenegraph.Transform3D;
import com.xith3d.scenegraph.TransformGroup;
/**
* @author Besitzer
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class Sprite3D {
private Vector3f posVec = new Vector3f(0,0,0);
private Vector3f directionVec;
private Vector3f strafeVec;
// Y is pointing up
private Vector3f upVec = new Vector3f(0,1,0);
/** Speed of the Sprite */
private float spriteSpeed = 10;
private TransformGroup transformGroup;
private Transform3D transform = new Transform3D();
private Transform3D tmpTransform = new Transform3D();
/**
*
* @param transformGroup
* @param direction
*/
public Sprite3D(TransformGroup transformGroup, Vector3f direction) {
this.transformGroup = transformGroup;
transformGroup.getTransform(tmpTransform);
tmpTransform.get(posVec);
directionVec = direction;
}
public void move(Vector3f move){
transformGroup.getTransform(transform);
tmpTransform.setIdentity();
tmpTransform.setTranslation(move);
tmpTransform.scaleTranslation(spriteSpeed);
transform.mul(tmpTransform);
transformGroup.setTransform(transform);
}
public void rotXYZ (float x, float y, float z) {
transformGroup.getTransform(transform);
tmpTransform.setIdentity();
tmpTransform.rotXYZ(x,y,z);
//tmpTransform.scaleTranslation(spriteSpeed);
transform.mul(tmpTransform);
transformGroup.setTransform(transform);
}
}
I don t know, wether this methods work corectly, so plz comment, if u find any trouble.
Here are my problems:
Must i submit the direction of the sprite in the constructor? I think yes. How should the Class know how the sprite is aligned, right?
How do i update my Strafe Vec after rotation?
I need them to rot along strafe and direction axis,
because my sprites should move in terrain.
Thanks for helping…