|
Re: Calculating the angle of a point in relation to another February 01, 2012 10:32PM | Registered: 15 years ago Posts: 363 |
guVector a, b; float theta_x, theta_y, theta_z; float dot=0; a = (0,0,-1); b = player_direction; b.y=0; //we doing y dot=guVecDotProduct( &a, &b ); theta_y=acos( dot / ( sqrt(a.x+a.y+a.z) * sqrt(b.x+b.y+b.z) ) ) * 57.2957795; //repeat about for x, z GRRLIB_ObjectViewRotate( theta_x, theta_y, theta_z ); //do rotation
|
Re: Calculating the angle of a point in relation to another February 02, 2012 12:18PM | Registered: 14 years ago Posts: 99 |
|
Re: Calculating the angle of a point in relation to another February 02, 2012 03:28PM | Registered: 15 years ago Posts: 363 |
theta_y=acos( dot / ( sqrt(a.x+a.y+a.z) * sqrt(b.x+b.y+b.z) ) ) * 57.2957795;I think its generating so kinda weird number that crashs anything I pass it to :( plus weird graphical artifacts show up on the screen. I'm not sure whats wrong with it.
guVector a= { 0.0f,0.0f,-1.0f}, b;
float theta_x=0.0f, theta_y=0.0f, theta_z=0.0f;
float dot=0.0f;
b = player_direction;
b.x=0.0f; //we doing y
dot=guVecDotProduct( &a, &b );
theta_x=acos( dot / ( sqrt(a.x+a.y+a.z) * sqrt(b.x+b.y+b.z) ) ) ;
b = player_direction;
b.y=0.0f; //we doing y
dot=guVecDotProduct( &a, &b );
theta_y=acos( dot / ( sqrt(a.x+a.y+a.z) * sqrt(b.x+b.y+b.z) ) ) ;
b = player_direction;
b.z=0.0f; //we doing y
dot=guVecDotProduct( &a, &b );
theta_z=acos( dot / ( sqrt(a.x+a.y+a.z) * sqrt(b.x+b.y+b.z) ) ) ;
player_rotation.x = theta_x;
player_rotation.y = theta_y;
player_rotation.z = theta_z;
|
Re: Calculating the angle of a point in relation to another February 02, 2012 09:28PM | Registered: 14 years ago Posts: 99 |
void calcPitchAndYaw( guVector* c, guVector* targetP, float* pitchX, float* yawY )
{
float dX = targetP->x - c->x; // horizontal plane
float dY = targetP->y - c->y; // vertical plane
float dZ = targetP->z - c->z; // horizontal plane
float hypotenuse = sqrt(dX*dX + dZ*dZ); // distance along horizontal plane
*pitchX = RadsToDegs ( atan2(dY, hypotenuse) ) ; // angle to look up/down
*yawY = RadsToDegs ( atan2(dX, dZ) ); // angle to look left/right
}
|
Re: Calculating the angle of a point in relation to another February 03, 2012 09:53PM | Registered: 15 years ago Posts: 363 |
|
Re: Calculating the angle of a point in relation to another February 07, 2012 05:00PM | Registered: 15 years ago Posts: 363 |
guVector get_rotation_degrees_to_face_target(guVector current, guVector target ) {
float dx=target.x-current.x;
float dy=target.y-current.y;
float dz=target.z-current.z;
float hyp = sqrt(dx*dx + dz*dz);
float rx= atan2(dy, hyp);
float ry= atan2(dx, dz);
rx= rx * 57.2957795;
ry= ry * 57.2957795;
return (guVector){rx, ry, 0};
}guVector rotation; cp = player_position; tp = player_direction; rotation=get_rotation_degrees_to_face_target( cp, tp ); GRRLIB_ObjectViewRotate( rotation.x, rotation.y, rotation.z ); //do rotation
|
Re: Calculating the angle of a point in relation to another February 09, 2012 10:23PM | Registered: 15 years ago Posts: 87 |
guMtxIdentity(ObjTransformationMtx); guMtxIdentity(m); guMtxScaleApply(m, m, 0.005, 0.005, 0.005); guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); guMtxIdentity(m); guMtxTransApply(m, m, 0, -0.1, -0.5); // move the model a little to front and down to make it visible guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); GX_LoadPosMtxImm(ObjTransformationMtx, GX_PNMTX0); guMtxInverse(ObjTransformationMtx, mvi); guMtxTranspose(mvi, mv); GX_LoadNrmMtxImm(mv, GX_PNMTX0); ........ Draw yor model .........
void MtxSisRef(Mtx m, guVector u, guVector v, guVector w){
m[0][0]=u.x; m[1][0]=v.x; m[2][0]=-w.x;
m[0][1]=u.y; m[1][1]=v.y; m[2][1]=-w.y;
m[0][2]=u.z; m[1][2]=v.z; m[2][2]=-w.z;
m[0][3]=0.0; m[1][3]=0.0; m[2][3]=0.0;
}MtxSisRef(rotm, p, right, up, front); guMtxIdentity(ObjTransformationMtx); guMtxConcat(rotm, ObjTransformationMtx, ObjTransformationMtx); // move to ship position guMtxIdentity(m); guMtxTransApply(m, m, position.x, position.y, position.z); guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); // apply camera proyection matrix guMtxConcat(_Object3D_view, ObjTransformationMtx, mv); GX_LoadPosMtxImm(mv, GX_PNMTX0); guMtxInverse(mv, mvi); guMtxTranspose(mvi, mv); GX_LoadNrmMtxImm(mv, GX_PNMTX0);
void Object3D_Camera3dSettings(f32 posx, f32 posy, f32 posz,
f32 upx, f32 upy, f32 upz,
f32 lookx, f32 looky, f32 lookz) {
_Object3D_cam.x=posx;
_Object3D_cam.y=posy;
_Object3D_cam.z=posz;
_Object3D_up.x=upx;
_Object3D_up.y=upy;
_Object3D_up.z=upz;
_Object3D_look.x=lookx;
_Object3D_look.y=looky;
_Object3D_look.z=lookz;
GRRLIB_Camera3dSettings(posx, posy, posz, upx, upy, upz, lookx, looky, lookz);
}
void Object3D_3dMode(f32 minDist, f32 maxDist, f32 fov, bool texturemode, bool normalmode) {
guLookAt(_Object3D_view, &_Object3D_cam, &_Object3D_up, &_Object3D_look);
GRRLIB_3dMode(minDist,maxDist,fov,texturemode,normalmode);
}
void Turn_y(f32 ang){
Mtx m;
guMtxRotAxisDeg(m, &player_up, ang);
guVecMultiply(m, &player_right, &player_right);
guVecCross(&player_up, &player_right, &player_front);
guVecScale(&player_front, &player_front, -1);
guVecScale(&player_front, &lookat, 100.0f);
guMtxIdentity(m);
guMtxTrans(m, player_position.x, player_position.y, player_position.z);
guVecMultiply(m, &lookat, &lookat);
}
void Turn_x(f32 ang){
Mtx m;
guMtxRotAxisDeg(m, &player_right, ang);
guVecMultiply(m, &player_up, &player_up);
guVecCross(&player_up, &player_right, &player_front);
guVecScale(&player_front, &player_front, -1);
guVecScale(&player_front, &lookat, 100.0f);
guMtxIdentity(m);
guMtxTrans(m, player_position.x, player_position.y, player_position.z);
guVecMultiply(m, &lookat, &lookat);
}|
Re: Calculating the angle of a point in relation to another February 10, 2012 03:51PM | Registered: 14 years ago Posts: 99 |
guVector get_rotation_degrees_to_face_target(guVector* pCurrent, guVector* pTarget ) {
float dx = pTarget->x - pCurrent->x;
float dy = pTarget->y - pCurrent->y;
float dz = pTarget->z - pCurrent->z;
... rest the same
example calling code..
guVector p1 = {20, 20, 20};
guVector p2 = {-33, -33, -33};
guVector vec = get_rotation_degrees_to_face_target(&p1, &p2);
printf ("%f %f %f",vec.x,vec.y,vec.z );
|
Re: Calculating the angle of a point in relation to another February 10, 2012 05:11PM | Moderator Registered: 16 years ago Posts: 686 |
|
Re: Calculating the angle of a point in relation to another February 10, 2012 09:52PM | Registered: 14 years ago Posts: 99 |
|
Re: Calculating the angle of a point in relation to another February 10, 2012 10:10PM | Registered: 15 years ago Posts: 363 |
guVector rotate_vec_to_angle( guVector position_vec, guVector center_vec, float rot_deg_x, float rot_deg_y, float rot_deg_z ) {
guVector orig_direction = position_vec;
Mtx m,om;
guMtxIdentity(m);
guMtxApplyTrans (m, om, -center_vec.x, -center_vec.y, -center_vec.z);
guMtxRotDeg(m, 'x', rot_deg_x); // rotate around y axis
guMtxConcat(m, om, om);
guMtxRotDeg(m, 'y', rot_deg_y); // rotate around x axis
guMtxConcat(m, om, om);
guMtxRotDeg(m, 'z', rot_deg_z); // rotate around z axis
guMtxConcat(m, om, om);
guMtxIdentity(m);
guMtxApplyTrans (m, m, center_vec.x, center_vec.y, center_vec.z);
guMtxConcat(m, om, om);
guVecMultiply(om, &orig_direction, &position_vec);
return position_vec;
}
|
Re: Calculating the angle of a point in relation to another February 11, 2012 01:37PM | Registered: 14 years ago Posts: 99 |
|
Re: Calculating the angle of a point in relation to another February 11, 2012 02:18PM | Registered: 15 years ago Posts: 363 |
|
Re: Calculating the angle of a point in relation to another February 11, 2012 02:21PM | Registered: 14 years ago Posts: 99 |
|
Re: Calculating the angle of a point in relation to another February 11, 2012 02:27PM | Registered: 14 years ago Posts: 99 |
|
Re: Calculating the angle of a point in relation to another February 11, 2012 02:37PM | Registered: 15 years ago Posts: 363 |
Quote
Titmouse
wilco2009 β do you have any open projects (i.e. shared Google code) with these techniques. (your wii brew link is blocked)
Things like guVecScale(&player_front, &player_front, -1); // to flip, is something I would not thought of doing, obvious now I've seen it!
Infact I've never though about changing things like the up,left vectors, to alow for 360 rotation without issues!
|
Re: Calculating the angle of a point in relation to another February 11, 2012 04:46PM | Moderator Registered: 16 years ago Posts: 686 |
C is only a language specification, it has nothing to do with how the ABI is defined. A struct is simply a fixed size array that is allowed to have different sized elements. If it's declared const or the function doesn't modify it there's no need to create a temporary copy.Quote
Titmouse
Array & functions yes - but structures using pointers for you? (just checked guVector is a struct), new one on me! that would break C.
Is it in some way marked as an array, hidden away somewhere - I've yet to see this How does it do this???
|
Re: Calculating the angle of a point in relation to another February 11, 2012 05:27PM | Registered: 15 years ago Posts: 87 |
As Owen says you can take a look to the 11th part of my course. The only thing it is in Spanish.Quote
Titmouse
wilco2009 β do you have any open projects (i.e. shared Google code) with these techniques. (your wii brew link is blocked)
Things like guVecScale(&player_front, &player_front, -1); // to flip, is something I would not thought of doing, obvious now I've seen it!
Infact I've never though about changing things like the up,left vectors, to alow for 360 rotation without issues!
|
Re: Calculating the angle of a point in relation to another February 13, 2012 12:33AM | Registered: 14 years ago Posts: 99 |
|
Re: Calculating the angle of a point in relation to another February 13, 2012 12:43AM | Registered: 14 years ago Posts: 99 |