Advertisement
letsplayordy

GTA IV C# Draw inside world

Sep 2nd, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. //copy these functions to your script
  2. private Vector2 CoordToScreen(Vector3 vect)
  3.     {
  4.         int Screen = 0;
  5.         GTA.Native.Pointer x = new GTA.Native.Pointer(typeof(float));
  6.         GTA.Native.Pointer y = new GTA.Native.Pointer(typeof(float));
  7.         Vector3 xpos = vect;
  8.         GTA.Native.Pointer ViewportId = new GTA.Native.Pointer(typeof(int));
  9.         GTA.Native.Function.Call("GET_GAME_VIEWPORT_ID", ViewportId);
  10.         Screen = ViewportId;
  11.         GTA.Native.Function.Call("GET_VIEWPORT_POSITION_OF_COORD", xpos.X, xpos.Y, xpos.Z, Screen, x, y);
  12.        
  13.         return new Vector2(x,y);
  14.     }
  15.    
  16.     private bool isCoordVisibleStopsAfterLoad(Vector3 WorldCoord, float AreaSize = 1f) //stops working after you load a save game
  17.     {
  18.         if(Game.Exists(Game.CurrentCamera))
  19.         {    
  20.             return GTA.Native.Function.Call<bool>("CAM_IS_SPHERE_VISIBLE", Game.CurrentCamera, WorldCoord.X, WorldCoord.Y, WorldCoord.Z, AreaSize);
  21.         }
  22.         else{return false;}
  23.     }
  24.  
  25. private bool isCoordVisible(Vector3 WorldCoord)
  26. {
  27.     if (Vector3.Subtract(Vector3.Normalize(Vector3.Subtract(myPed, Game.CurrentCamera.Position)),Game.CurrentCamera.Direction).Length() > 0.6f) return false;
  28.     return true;
  29. }
  30.  
  31. //put this in PerFrameDrawing
  32. Vector3 WorldPosition = //insert Vector3 you want shown here (eg: Game.LocalPlayer.Character.Position)
  33. if(isCoordVisible(WorldPosition))
  34. {
  35.     Vector2 ScreenPosition = CoordToScreen(WorldPosition);
  36.     e.Graphics.DrawRect(ScreenPosition.X, ScreenPosition.Y, 32, 32, System.Drawing.Color.White);
  37.     //or e.Graphics.DrawSprite
  38.     //or e.Graphics.DrawText
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement