Gamestudio Links
Zorro Links
Newest Posts
Why Zorro supports up to 72 cores?
by 11honza11. 04/26/24 08:55
M1 Oversampling
by 11honza11. 04/26/24 08:32
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, VoroneTZ, Quad, 1 invisible), 826 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
change point of rotation in-game #443526
07/18/14 20:11
07/18/14 20:11
Joined: Nov 2006
Posts: 497
Ohio
xbox Offline OP
Senior Member
xbox  Offline OP
Senior Member

Joined: Nov 2006
Posts: 497
Ohio
Is it possible to alter the "origin" of a WMB entity in-game so it can be rotated around this new point? If so, any pointers as to how I can do so? I need to be able to load a map, grab a subentities coordinate, and rotate the map around that point.

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 Offline
Serious User
txesmi  Offline
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.

Code:
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 Offline
Senior Member
CD_saber  Offline
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 Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Here you go!

Code:
#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 Offline OP
Senior Member
xbox  Offline 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 grin 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 Offline
Serious User
txesmi  Offline
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.

Code:
#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 Offline OP
Senior Member
xbox  Offline OP
Senior Member

Joined: Nov 2006
Posts: 497
Ohio
This is the vector length I'm using, nothing special.
Code:
vector(0,248,24);


The only thing I changed was in the main function here.

Code:
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.

Re: change point of rotation in-game [Re: xbox] #444009
07/28/14 20:21
07/28/14 20:21
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Mixed alltogether laugh

The origin of an entity is 'ent.x', you know. 'ent.vOriginX' is the origin of the rotation in world space. 'ent.vOffsetX' is the offset vector from the rotation origin to the unrotated entity origin. You do not need to change its calculation:
Code:
vec_diff ( ent.vOffsetX, ent.x, ent.vOriginX );


Re: change point of rotation in-game [Re: txesmi] #444020
07/29/14 04:34
07/29/14 04:34
Joined: Nov 2006
Posts: 497
Ohio
xbox Offline OP
Senior Member
xbox  Offline OP
Senior Member

Joined: Nov 2006
Posts: 497
Ohio
....and there it is. It's working beautifully. I appreciate your help and patience with this. The worst part is, this was supposed to be of the easier parts of this project... grin


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1