start && end > -1) { if (start > -1) { var res = data.substring(start, end); start = res.indexOf('>') + 1; res = res.substring(start); if (res.length != 0) { eval(res); } } cursor = end + 1; } } } //]]>
|
Calculating the angle of a point in relation to another January 12, 2012 02:57PM | Registered: 2 years ago Posts: 284 |
|
Re: Calculating the angle of a point in relation to another January 12, 2012 05:13PM | Moderator Registered: 3 years ago Posts: 464 |
Mtx m; guVector orig_direction = player_direction; guMtxRotDeg(m, "y", 60); // rotate around y axis by 60 degrees guVecMultiply(m, &orig_direction, &player_direction);I only peeked at gu.h for reference, this might not actually work properly.
|
Re: Calculating the angle of a point in relation to another January 12, 2012 05:46PM | Registered: 2 years ago Posts: 284 |
|
Re: Calculating the angle of a point in relation to another January 12, 2012 06:23PM | Registered: 2 years ago Posts: 87 |
|
Re: Calculating the angle of a point in relation to another January 12, 2012 06:50PM | Registered: 2 years ago Posts: 284 |
angle=DegToRad(60); player_direction.y = player_direction.y; player_direction.z' = player_position.z*cos(angle)-player_position.x*sin(angle); player_direction.x' = player_position.z*sin(angle)+player_position.x*cos(angle);
|
Re: Calculating the angle of a point in relation to another January 12, 2012 06:51PM | Moderator Registered: 3 years ago Posts: 464 |
Quote:You had player_direction.z set to 1000, I thought that implied the velocity.owen
the guVector is basically a float[3]. I haven't thought about momentum or velocity as yet. I could keep the direction normalized but it would mean having to mess around with the Mtx functions.
Quote:guVecMultiply expects different arguments for the source (IN) and destination (OUT) vectors so it gets copied to a temp vector.Why are you doing; orig_direction = player_direction? The way I planned is to have the player_direction change relative to the player_position. As in the player_direction is a point rotated around the player_position (center) by 60 degrees.
|
Re: Calculating the angle of a point in relation to another January 12, 2012 07:02PM | Registered: 2 years ago Posts: 284 |
|
Re: Calculating the angle of a point in relation to another January 12, 2012 08:36PM | Registered: 2 years ago Posts: 87 |
angle=DegToRad(60); player_direction.y = player_direction.y; player_direction.z = player_direction.z*cos(angle)-player_direction.x*sin(angle); player_direction.x = player_direction.z*sin(angle)+player_direction.x*cos(angle);
player.position.x += player.direction.x; player.position.y += player.direction.y; player.position.z += player.direction.z;
|
Re: Calculating the angle of a point in relation to another January 12, 2012 10:08PM | Registered: 2 years ago Posts: 284 |
|
Re: Calculating the angle of a point in relation to another January 12, 2012 10:32PM | Registered: 2 years ago Posts: 87 |
angle=DegToRad(60); player_direction.y = player_direction.y; player_direction.z = player_direction.z*cos(angle)-player_direction.x*sin(angle); player_direction.x = player_direction.z*sin(angle)+player_direction.x*cos(angle);- Then you have to calculate the lookup vector combining the position vector and the direction vector, and using a distance value to look more far.
lookup.x = player_direction.x*distance + player_position.x; lookup.y = player_direction.y*distance + player_position.y; lookup.z = player_direction.z*distance + player_position.z;- Finally you can use GRRLIB_Camera3dSettings to setup the view:
GRRLIB_Camera3dSettings (player_position.x, player_position.y, player_position.z, 0, 1, 0, lookup.x, lookup.y, lookup.z);
|
Re: Calculating the angle of a point in relation to another January 12, 2012 10:55PM | Registered: 2 years ago Posts: 284 |
|
Re: Calculating the angle of a point in relation to another January 13, 2012 03:09AM | Registered: 2 years ago Posts: 284 |
|
Re: Calculating the angle of a point in relation to another January 13, 2012 08:55AM | Registered: 2 years ago Posts: 87 |
Mtx m,m1; guVector orig_direction = player_direction; guMtxIdentity(m); guMtxApplyTrans (&m, &m1, -player_position.x, -player_position.y, -player_position.z) guMtxRotDeg(m1, "y", 60); // rotate around y axis by 60 degrees guMtxApplyTrans (&m1, &m, player_position.x, player_position.y, player_position.z) guVecMultiply(m, &orig_direction, &player_direction);
|
Re: Calculating the angle of a point in relation to another January 13, 2012 05:32PM | Registered: 2 years ago Posts: 284 |
guVector rotate_to_angle( float angle, guVector player_direction, guVector player_position ) {
guVector lookup;
float distance=1000;
angle=DegToRad(angle);
Mtx m,m1;
guVector orig_direction = player_direction;
guMtxIdentity(m);
guMtxApplyTrans (&m, &m1, -player_position.x, -player_position.y, -player_position.z);
guMtxRotDeg(m1, 'y', angle); // rotate around y axis by 60 degrees
guMtxApplyTrans (&m1, &m, player_position.x, player_position.y, player_position.z);
guVecMultiply(m, &orig_direction, &player_direction);
return player_direction;
}|
Re: Calculating the angle of a point in relation to another January 13, 2012 08:37PM | Moderator Registered: 3 years ago Posts: 464 |
|
Re: Calculating the angle of a point in relation to another January 13, 2012 08:48PM | Registered: 2 years ago Posts: 87 |
Mtx m,om;
guMtxIdentity(m);
guMtxApplyTrans (m, m, -player_position.x, -player_position.y, -player_position.z);
guMtxConcat(m, om, om);
guMtxRotDeg(m, 'y', angle); // rotate around y axis by 60 degrees
guVecMultiply(m, &orig_direction, &player_direction);
guMtxConcat(m, om, om);
guMtxIdentity(m);
guMtxApplyTrans (m, m, player_position.x, player_position.y, player_position.z);
guMtxConcat(m, om, om);|
Re: Calculating the angle of a point in relation to another January 13, 2012 09:10PM | Registered: 2 years ago Posts: 284 |
|
Re: Calculating the angle of a point in relation to another January 13, 2012 11:18PM | Registered: 2 years ago Posts: 284 |
|
Re: Calculating the angle of a point in relation to another January 14, 2012 12:50PM | Registered: 2 years ago Posts: 87 |
Mtx m,om; guMtxIdentity(m); guMtxApplyTrans (m, om, -player_position.x, -player_position.y, -player_position.z); guMtxRotDeg(m, 'y', angle); // rotate around y axis by 60 degrees guMtxConcat(m, om, om); guMtxIdentity(m); guMtxApplyTrans (m, m, player_position.x, player_position.y, player_position.z); guMtxConcat(m, om, om); guVecMultiply(om, &orig_direction, &player_direction); GRRLIB_Camera3dSettings(player_position.x,player_position.y,player_position.z, 0,1,0, player_direction.x,player_direction.y,player_direction.z);
guVecSub(&player_direction,&player_position,&normdir); guVecNormalize(&normdir); guVecScale(&normdir, &stepdir, 0.1); if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_UP) guVecAdd(&player_position, &stepdir, &player_position); if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_DOWN) guVecSub(&player_position, &stepdir, &player_position);
|
Re: Calculating the angle of a point in relation to another January 14, 2012 04:18PM | Registered: 2 years ago Posts: 284 |
if( button_left_held || button_2_held ) {
guVecAdd(&player_position, &stepdir, &player_position);
guVecAdd(&player_direction, &stepdir, &player_direction); //i am moving the direction away from the position so they never meet
}
if( button_right_held || button_1_held ) {
guVecSub(&player_position, &stepdir, &player_position);
guVecSub(&player_direction, &stepdir, &player_direction);
}
if( button_up_held || button_down_held) {
guVector np;
angle=100;
if( button_down_held ) angle=-100;
np = rotate_to_angle( angle, (guVector){player_direction[0], player_direction[1], player_direction[2]}, (guVector){player_position[0], player_position[1], player_position[2]} ); //function wilco's matrix code
player_direction[0]=np.x;
player_direction[1]=np.y; player_direction[2]=np.z;
guVecSub(&player_direction,&player_position,&normdir);
guVecNormalize(&normdir);
guVecScale(&normdir, &stepdir, 10);
//angle+=10;
//if(angle >= 360) angle=1;
}