Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is the Uber Camera.
- // Works just like Gameplay camera with added features of
- //
- // * Following any Entity
- // * No ground clamp
- // * Follow distance controlled by mouse wheel
- //
- // To exit demo press E
- //
- // You are free to use this code however you want, all I ask is
- // to be credited if you use it in a mod you have published
- // -- MoMadenU
- //
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using GTA;
- using GTA.Math;
- using GTA.Native;
- using Control = GTA.Control;
- namespace MoTools
- {
- public class UberCamera
- {
- private static float _polarAngleDeg = 0;
- private static float _azimuthAngleDeg = 90;
- private static float _radius = 3.5f;
- public static void Demo()
- {
- var playerPed = Game.Player.Character;
- var playerPedPos = playerPed.Position;
- var ped = World.CreatePed(new Model(42647445), new Vector3(playerPedPos.X, playerPedPos.Y, playerPedPos.Z + 100f));
- ped.FreezePosition = true;
- Start(ped);
- while (!Game.IsKeyPressed(Keys.E))
- {
- OnTick(ped);
- }
- Stop();
- ped.Delete();
- }
- public static void Start(Entity entity)
- {
- Stop();
- World.RenderingCamera = World.CreateCamera(entity.Position, Vector3.Zero, 60f);
- }
- public static void OnTick(Entity entity)
- {
- disableAllControls();
- if (Game.IsControlPressed(2, Control.CursorScrollDown) || Game.IsControlPressed(2, Control.MoveDownOnly))
- _radius += 0.5f;
- if (Game.IsControlPressed(2, Control.CursorScrollUp) || Game.IsControlPressed(2, Control.MoveUpOnly))
- _radius -= 0.5f;
- if (_radius < 1)
- _radius = 1;
- var xMagnitude = Function.Call<float>(Hash.GET_DISABLED_CONTROL_NORMAL, 0, (int)GTA.Control.LookLeftRight);
- var yMagnitude = Function.Call<float>(Hash.GET_DISABLED_CONTROL_NORMAL, 0, (int)GTA.Control.LookUpDown);
- _polarAngleDeg += (xMagnitude * 10);
- if (_polarAngleDeg >= 360)
- _polarAngleDeg = 0;
- _azimuthAngleDeg += (yMagnitude * 10);
- if (_azimuthAngleDeg >= 360)
- _azimuthAngleDeg = 0;
- var nextCamLocation = polar3DToWorld3D(entity.Position, _radius, _polarAngleDeg, _azimuthAngleDeg);
- World.RenderingCamera.Position = new Vector3(nextCamLocation.X, nextCamLocation.Y, nextCamLocation.Z);
- World.RenderingCamera.PointAt(entity);
- Script.Wait(0);
- }
- public static void Stop()
- {
- World.DestroyAllCameras();
- World.RenderingCamera = null;
- }
- private static Vector3 polar3DToWorld3D(Vector3 entityPosition, float radius, float polarAngleDeg, float azimuthAngleDeg)
- {
- // convert degrees to radians
- var polarAngleRad = polarAngleDeg * Math.PI / 180.0;
- var azimuthAngleRad = azimuthAngleDeg * Math.PI / 180.0;
- float x = entityPosition.X + radius * (float)(Math.Sin(azimuthAngleRad) * Math.Cos(polarAngleRad));
- float y = entityPosition.Y - radius * (float)(Math.Sin(azimuthAngleRad) * Math.Sin(polarAngleRad));
- float z = entityPosition.Z - radius * (float)(Math.Cos(azimuthAngleRad));
- return new Vector3(x, y, z);
- }
- private static void disableAllControls()
- {
- foreach (Control control in Enum.GetValues(typeof(Control)))
- {
- Function.Call(Hash.DISABLE_CONTROL_ACTION, 0, (int)control, 1);
- }
- }
- private static void enableAllControls()
- {
- foreach (Control control in Enum.GetValues(typeof(Control)))
- {
- Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, (int) control, 1);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement