finding a point with a given direction and distance [help me]

Started by
1 comment, last by Nanoha 12 years, 11 months ago
sorry if this is in the wrong section, i am new here, so anyway here is my problem.
currently I am developing a rendering engine (mostly for making models to insert into a game), inside this engine I have a class (designed for making vector points) when you use this you set a distance and direction relative to a point (the bone joint) it then sets the XYZ points depending on the given rotation and distance. Here is the coding so far
public class Vec
{
//their dropin us presents... why are they explodin???
int distanceToJoint;
int directionToJointY;
int directionToJointX;
int directionToJointZ;
int xpos;
int ypos;
int zpos;
SkelBone skel;
public Vec (int ds, int dry, int drx,int drz, SkelBone sk)
{
distanceToJoint = ds;
directionToJointY = dry;
directionToJointX = drx;
directionToJointZ = drz;
skel = sk;
}
}

basically I need to find a way to set xpos, ypos and zpos
Advertisement
... Sorry, what?

Please organize your thoughts and ask your question more clearly. What do you know? What don't you know? What are the inputs and outputs to your process?
are drx/dry/drz euler angles? First I think you will definately need to change most of those values to being floats and not ints. My guess is your bone is at (0, 0, 0) initially, you want to rotate it by the given angles and find the end point (storing those in xpos/ypos/zpos). This is not a difficult task if you have some maths things to use (matrices/vectors). Do you have anyhting like that?

I'd look at using a math lib, if not then make a Vector class and a function that takes euler angles and a vector, rotates by those angles and returns a rotated vector (that will be a fair amount of work). Then you can do:

Vector pos;
SkelBone skel;
public Vec (int ds, int dry, int drx,int drz, SkelBone sk)
{
distanceToJoint = ds;
directionToJointY = dry;
directionToJointX = drx;
directionToJointZ = drz;
skel = sk;
pos = new Vector(0, 0, distanceToJoint); // This would be the default "forward", where the bone points with no rotation
pos = RotateFromEulerAngles(drx, dry, drz, pos);
}


Vector RotateFromEulerAngles(float xr, float yr. float zr, Vector in);

To implement that you will need to know a bit of maths. Do you know matrix multiplication (there may be other ways)? This shows a general matrix for rotations: http://en.wikipedia.org/wiki/Rotation_matrix#Rotations_in_three_dimensions

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

This topic is closed to new replies.

Advertisement