Free Camera in VC-MP?

Started by ShaKur, Sep 02, 2020, 01:52 AM

Previous topic - Next topic

ShaKur

I have had a great doubt, I would like to know if ...

By creating a script, will it be possible to implement the free motion camera in some VC-MP server, such as in SA?

Either by car or on foot
Sorry for my bad English

SHy^

https://forum.vc-mp.org/?topic=918.msg27871#msg27871

Conceivably that's what you're seeking for. However, the link has been expired but it's given by KAKAN in the topic again if you scroll down. You can moreover take it from @DizzasTeR's map editor but you'll have to amend it.

NicusorN5

#2
Here's how to implement yourself:
1.) First of all, you should know that the camera's view matrix is made from 3 vectors: Camera position, camera look-at and camera's normal vector to the ground.

2.) VC:MP provides a function called SetCameraPosition (? something like that) (please edit, mods) that allows re-calculating the view matrix.

3.) To calculate the look at vector, take the camera position and a normalized vector defining the rotation:
--> CameraLookAt = CameraPos + N;
where N is an unit vector. (I'm repeating myself)

4.) To calculate the camera's direction, take 2 angles and then translate the unit vector.

//This example is supposed to work on XNA and Monogame
Vector3 Norm = Vector3.Translate(Vector3.UnitZ+Vector3.UnitY,Matrix.CreateYawPitchRoll(Theta1,0,Theta2));

Matrix MView = Matrix.CreateLookAt(CamPos,CamPos.Norm,Vector3.UnitY);

Where theta1 and theta2 are two angles determined from the mouse input multiplied by a sensitivity (a small float value)

This is the way I implemented a first person camera in my game engine. Not the best way, but it works.

Sources:
https://docs.microsoft.com/en-us/windows/win32/direct3d9/view-transform
--> 3DRadSpace's source code, https://github.com/3DRadSpace/3D_Rad_Space

habi

Quote from: Dominio on Sep 02, 2020, 01:52 AMI have had a great doubt, I would like to know if ...

By creating a script, will it be possible to implement the free motion camera in some VC-MP server, such as in SA?

Either by car or on foot

Yes it is possible.

angle<-0;
campos<-Vector(0,0,0);
UP_ARROW<-0x26;
up<-BindKey(false, UP_ARROW, 0, 0);

function onKeyDown(player, key)
{
       if(campos.x==0&&campos.y==0&&campos.z==0)
       {
             campos=move2(player.Pos,player.Angle,2,0);
             angle = player.Angle;
        }
       campos=move2(campos,angle,1,0);
       player.SetCameraPos(campos,move2(campos,angle,1,0));
}
function move(pos, distance, angle)
{
local newx = pos.x - sin(angle)*distance;
local newy = pos.y + cos(angle)*distance;
return Vector(newx,newy,pos.z);//assuming z more or less same.
}
function move2(pos,pangle,dis,angle)
{
return move(pos,dis,pangle+angle)
}

Press UP ARROW key.




ShaKur

Thank you all, really all the answers have been very helpful.
Sorry for my bad English