|
Re: change point of rotation in-game
[Re: xbox]
#443530
07/18/14 23:41
07/18/14 23:41
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Hi, you will need to rotate the offset vector from the rotation point to the origin of the entity.
vec_sub ( vTemp, ent.x, vRotOrigin );
vec_rotate ( vTemp, vector ( ang(angRotation - ent.pan), 0, 0 ) );
vec_add ( vTemp, vRotOrigin );
vec_set ( ent.x, vTemp );
ent.pan = angRotation;
|
|
|
Re: change point of rotation in-game
[Re: txesmi]
#443851
07/26/14 09:20
07/26/14 09:20
|
Joined: Jan 2002
Posts: 454 Germany
CD_saber
Senior Member
|
Senior Member
Joined: Jan 2002
Posts: 454
Germany
|
I have the same problem. TXESMI, could you give us an example, using the given parameters (vTemp etc. ?)
Thanks!
Ja, lach du nur du haariges Pelzvieh!
|
|
|
Re: change point of rotation in-game
[Re: CD_saber]
#443853
07/26/14 12:14
07/26/14 12:14
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Here you go!
#include <acknex.h>
#define PRAGMA_PATH "%EXE_DIR%\\templates\\models"
void ent_rotateXY_from_point ( ENTITY *ent, VECTOR *vRotOrigin, var angRotation )
{
VECTOR vTemp;
vec_diff ( vTemp, ent.x, vRotOrigin );
vec_rotate ( vTemp, vector ( angRotation, 0, 0 ) );
vec_add ( vTemp, vRotOrigin );
vec_set ( ent.x, vTemp );
ent.pan += angRotation;
}
void main ()
{
level_load ( "" );
camera.x = -500;
camera.z = 200;
camera.tilt = -20;
ENTITY *ent = ent_create ( "buggy.mdl", nullvector, NULL );
while ( !key_esc )
{
ent_rotateXY_from_point ( ent, ent.max_x, time_step * 5 );
wait(1);
}
sys_exit(NULL);
}
Salud!
|
|
|
Re: change point of rotation in-game
[Re: txesmi]
#443859
07/26/14 16:45
07/26/14 16:45
|
Joined: Nov 2006
Posts: 497 Ohio
xbox
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2006
Posts: 497
Ohio
|
My sincerest apologies as I try to understand vector manipulation, I've been playing with this code trying to change the point which is pans around and I'm getting no where. The level I loaded through ent_create originally panned around the outer most x point(max_x) so I changed it with a vector I created as one of the points to rotate around, however when I replace ent->max_x with a different vector, the entity just rotates around 0,0,0 no matter what. Normally after a few minutes of trial and error I can figure it out, but I can't think straight long enough today might be time for more coffee...
|
|
|
Re: change point of rotation in-game
[Re: xbox]
#443874
07/27/14 07:38
07/27/14 07:38
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Hi, I have been testing the function with big and small origin offsets and did not find any case that the vector length get null. How do you declare the rotation origin vector? Anyway I realized that the function call alters the length of the computed offset vector because of the innacuracy of the variables so I would save the offset vector of the unrotated state of the entity and rotate it with the absolute rotation of the entity each frame. This way the offset vector mantains its length during the run.
#include <acknex.h>
#define PRAGMA_PATH "%EXE_DIR%\\templates\\models"
#define vOriginX skill20
#define vOriginY skill21
#define vOriginZ skill22
#define vOffsetX skill23
#define vOffsetY skill24
#define vOffsetZ skill25
void ent_offset_rotateXY ( ENTITY *ent, var angRotation )
{
ent.pan += angRotation;
vec_set ( ent.x, ent.vOffsetX );
vec_rotate ( ent.x, vector ( ent.pan, 0, 0 ) );
vec_add ( ent.x, ent.vOriginX );
}
void main ()
{
level_load ( "" );
camera.x = -500;
camera.z = 200;
camera.tilt = -20;
ENTITY *ent = ent_create ( "buggy.mdl", nullvector, NULL );
vec_set ( ent.vOriginX, ent.max_x );
vec_diff ( ent.vOffsetX, ent.x, ent.vOriginX );
while ( !key_esc )
{
ent_offset_rotateXY ( ent, time_step * 5 );
wait(1);
}
}
Last edited by txesmi; 07/27/14 07:59.
|
|
|
Re: change point of rotation in-game
[Re: txesmi]
#443998
07/28/14 16:57
07/28/14 16:57
|
Joined: Nov 2006
Posts: 497 Ohio
xbox
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2006
Posts: 497
Ohio
|
This is the vector length I'm using, nothing special. The only thing I changed was in the main function here.
ENTITY *ent = ent_create ( "Room02.wmb", nullvector, NULL );
ent_create( "cube.mdl", vector(0,248,24), NULL); //Point to rotate around
ent_create( "cube.mdl", vector(0,0,0), NULL); //origin reference
vec_set ( ent.vOriginX, vector(0,0,0));
vec_diff ( ent.vOffsetX, vector(0,248,24), ent.vOriginX );
Maybe I'm reading this wrong and that is causing the issue. Here's what I think the code is doing. I set the vector (0,0,0) to the vOrigin vector, I then calculate the difference between the vOrigin and the new point I want to rotate around, (0,248,24), and store it to the offset vector. When I run this code, the map rotates around vector(0,0,0), and I can see the other cube that is supposed to rotating around off to the side, but it's clearly not the point it's rotating around.
|
|
|
|