Moving the camera around a static spot (trigonometry help?)
#1

hi,

so i would like to create a camera movement that circles around a spot. (e.g. a player)
First i tried to make it with a timer and some trigonometric functions (floatsin and floatcos) until i discovered there are better methods to accomplish this.

I discovered the functions:
InterpolateCameraPos and InterpolateCameraLookAt.

I tried around but i just cant get it done.
I deleted my previous code after i discovered these functinos but i still cant get it done.
Either im thinking way too complicated or im just too dump for this.

Do i still need trigonometric functions to accomplish a camera circling movement around a spot using the functions mentioned above?
Or is there an easier way? (i suppose there is as this functions are supposed to do this kinda stuff)
Atm im just to tired to go on trying.
I hope someone can help me or at least give me a hint please

thanks in advance!
Reply
#2

You need hacks with air brake and do it very slow and right, use this.
https://sampwiki.blast.hk/wiki/InterpolateCameraPos
+ Rep if I helped.
Reply
#3

sorry but thats not answering my question at all... (and i already posted that i would like to use that function ure telling me to check out...)
Reply
#4

As far as I know you can't do that with the InterpolateCamera functions as they don't have the option to rotate around a spot.
I'd try something under OnPlayerUpdate. Here's what I found on the German SA:MP board.

Код:
#include <a_samp>

enum COORD {
	Float:coord_x,
	Float:coord_y,
	Float:coord_z
}

enum CAMMOVEMENT {
	steps,
	currentstep,
	Float:amount_x,
	Float:amount_y,
	Float:amount_z,
	Float:look_x,
	Float:look_y,
	Float:look_z,
	CameraMoveTimerID
}

forward Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2);
forward CameraMoveTimer(playerid);

new Float:gPlayerCameraPos[MAX_PLAYERS][COORD];
new Float:gPlayerCamMovement[MAX_PLAYERS][CAMMOVEMENT];

main() {

}

//-------------------------------------------------------------------

public OnGameModeInit() {
	AddPlayerClass(0,2040.2158,1355.9232,10.6719,267.2625,0,0,0,0,0,0);
	return 1;
}

//-------------------------------------------------------------------

public OnPlayerSpawn(playerid) {
	SetPlayerCameraPosEx(playerid, 2052.1799,1384.5262,10.6719,2040.2158,1355.9232,10.6719);
	MoveCamera(playerid, 2053.9204,1348.7130,18.6719, 2040.2158,1355.9232,10.6719, 0.2);
	return 1;
}

//-------------------------------------------------------------------

stock MoveCamera(playerid, Float:dest_x, Float:dest_y, Float:dest_z, Float:lookat_x, Float:lookat_y, Float:lookat_z, Float:speed) {
	new Float:distance;
	
	distance = GetDistanceBetweenPoints(gPlayerCameraPos[playerid][coord_x],
                                    	gPlayerCameraPos[playerid][coord_y],
                                    	gPlayerCameraPos[playerid][coord_z],
                                    	dest_x,
                                    	dest_y,
                                    	dest_z);
                                    	
	gPlayerCamMovement[playerid][steps] = floatround(distance / speed);
	gPlayerCamMovement[playerid][currentstep] = 0;
	
	gPlayerCamMovement[playerid][amount_x] = (dest_x - gPlayerCameraPos[playerid][coord_x]) / gPlayerCamMovement[playerid][steps];
	gPlayerCamMovement[playerid][amount_y] = (dest_y - gPlayerCameraPos[playerid][coord_y]) / gPlayerCamMovement[playerid][steps];
	gPlayerCamMovement[playerid][amount_z] = (dest_z - gPlayerCameraPos[playerid][coord_z]) / gPlayerCamMovement[playerid][steps];
	gPlayerCamMovement[playerid][look_x] = lookat_x;
	gPlayerCamMovement[playerid][look_y] = lookat_y;
	gPlayerCamMovement[playerid][look_z] = lookat_z;
	
	gPlayerCamMovement[playerid][CameraMoveTimerID] = SetTimerEx("CameraMoveTimer", 50, 1, "i", playerid);
	return 1;
}

//-------------------------------------------------------------------

stock SetPlayerCameraPosEx(playerid, Float:cam_x, Float:cam_y, Float:cam_z, Float:lookat_x, Float:lookat_y, Float:lookat_z) {
	SetPlayerCameraPos(playerid, cam_x, cam_y, cam_z);
	SetPlayerCameraLookAt(playerid, lookat_x, lookat_y, lookat_z);
	
	gPlayerCameraPos[playerid][coord_x] = cam_x;
	gPlayerCameraPos[playerid][coord_y] = cam_y;
	gPlayerCameraPos[playerid][coord_z] = cam_z;
	
	return 1;
}

//-------------------------------------------------------------------

stock Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2) {
	return floatsqroot(floatpower(x1 - x2, 2) + floatpower(y1 - y2, 2) + floatpower(z1 - z2, 2));
}

//-------------------------------------------------------------------

public CameraMoveTimer(playerid) {
	if (gPlayerCamMovement[playerid][currentstep] <= gPlayerCamMovement[playerid][steps] - 1) {
    	gPlayerCameraPos[playerid][coord_x] = gPlayerCameraPos[playerid][coord_x] + gPlayerCamMovement[playerid][amount_x];
    	gPlayerCameraPos[playerid][coord_y] = gPlayerCameraPos[playerid][coord_y] + gPlayerCamMovement[playerid][amount_y];
    	gPlayerCameraPos[playerid][coord_z] = gPlayerCameraPos[playerid][coord_z] + gPlayerCamMovement[playerid][amount_z];
    	
    	SetPlayerCameraPos(playerid, gPlayerCameraPos[playerid][coord_x], gPlayerCameraPos[playerid][coord_y], gPlayerCameraPos[playerid][coord_z]);
    	SetPlayerCameraLookAt(playerid, gPlayerCamMovement[playerid][look_x], gPlayerCamMovement[playerid][look_y], gPlayerCamMovement[playerid][look_z]);
    	
    	gPlayerCamMovement[playerid][currentstep]++;
	} else {
    	KillTimer(gPlayerCamMovement[playerid][CameraMoveTimerID]);
	}
	
	return 1;
}
Reply
#5

hi,

the most important part is missing in that code but thanks for answering...

Well yes, there is no option to rotate around, thats why we have to play around with trigonometric functions...
Im just not sure if i can apply them using this natives atm so i wanted to ask if someone has an easy idea to get this job done.
If not i have to go back to my timer code...
Reply
#6

To rotate use trigonometric functions, But, You can use Timers with SetPlayerPos and SetPlayerLookAt, I've done once
Reply
#7

You need to work with the radius from the player, which is half the diameter of the circle you'd be making. You use the radius as the player is the central point of this circle.

You can then use this, with a timer or a loop to move the camera around the player. The difference being the timer will give you control over how fast the rotation is.

I found a tutorial, saves me writing one...

https://sampforum.blast.hk/showthread.php?tid=291910

EDIT: Also, if you instead get the 3 points of a triangle today atleast I think you'd be able to interpolate the camera around the player... although it wouldn't be a perfect circle.
Reply
#8

k thanks.
So what have u used?
Timers or trigonometry with the interpolate natives?
Please also tell me your reasons about ur decission

regards!
Reply
#9

Timers used to SetPlayerPos with the Camera, And trigonometry to rotate, I did that because it's the only way I found and easy way too.
Reply
#10

@IceCube! thanks a bunch!
This is the way i was trying to do this at first. (pretty simillar)

But as soon as i discovered the Interpolate functions i thought there must be an easier way doing this...
So i was pretty interested if someone has done smth. like that using the interpolate functions as i atm just cant think about a proper way to accomplish that using the interpolate natives.

thanks!

@Clad: ok, thank you
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)