Vice City: Multiplayer

VC:MP Discussion => General Discussion => Topic started by: ShaKur on Sep 02, 2020, 01:52 AM

Title: Free Camera in VC-MP?
Post by: ShaKur on Sep 02, 2020, 01:52 AM
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
Title: Re: Free Camera in VC-MP?
Post by: SHy^ on Sep 02, 2020, 04:07 AM
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.
Title: Re: Free Camera in VC-MP?
Post by: NicusorN5 on Sep 02, 2020, 01:44 PM
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
Title: Re: Free Camera in VC-MP?
Post by: habi on Sep 02, 2020, 02:37 PM
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.

(https://i.imgur.com/mqlh0sa.png)

(https://i.imgur.com/EQtk2Ar.png)
Title: Re: Free Camera in VC-MP?
Post by: ShaKur on Sep 02, 2020, 06:05 PM
Thank you all, really all the answers have been very helpful.