Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    2. News

    1. Red Dead Redemption 2

    1. GTA Online

      1. After Hours
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
    2. Crews

      1. Events
      2. Recruitment
    1. Grand Theft Auto Series

    2. GTA Next

    3. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    4. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    12. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Forum Support

    2. Site Suggestions

santtuz112

Draw text inside world?

Recommended Posts

santtuz112

EDIT: I know a method now.

 

Hey I'm newbie here just started trying to do some random sh*t for gta iv after I heard you can code in .net, anyways I'm trying to draw text to the 3D gta world instead on the screen is this easy or hard? If its hard then is it easy to find ped/vehicle location ON screen? If no on both then nvm :(, What you think?

Here's what I got so far but its on the
'screen' not in the world, If you can get text on the world would be cool but just detecting the ped/vehicles location On screen is good enough for now. (Version that's better than on the video below by me)

EDIT: As you can see the detection is f*cked up in the start of the video, I'm looking way to fix it, Its kinda reason able sometimes like in the end, But if you just rotate the camera and watch somewhere else the info panel is away from the vehicle, I want it to stick next to the vehicle




Here's my code so far,
ye it's not best but I started like 2 days ago

 

 

Imports SystemImports GTAPublic Class Scripts    Inherits Script    Dim lasttargettime As Integer = 0    Dim toggled As Boolean = False    Public Sub New()        Me.Interval = 1    End Sub    Sub toggler(sender As Object, ByVal e As GTA.KeyEventArgs) Handles Me.KeyDown 'I use this to toggle the script on/off '        If e.Key = Windows.Forms.Keys.K And e.Alt Then            toggled = Not toggled            Game.DisplayText("SteadyAim: " + toggled.ToString) ' With this I know the current status. '        End If    End Sub    Sub aim() Handles MyBase.Tick ' This code here has nothing to do with the thread but i just added it on my class to test SteadyAiming '        If toggled Then            If Game.LocalPlayer.GetTargetedPed = Nothing Then                If Environment.TickCount > lasttargettime + 1000 Then Game.TimeScale = 1            Else                Game.TimeScale = 0.4                lasttargettime = Environment.TickCount            End If        End If    End Sub    Function hpcolor(ByVal hp As Integer) As System.Drawing.Color 'This one generates the color of hp, not useful for vehicles yet though.'        If hp > 99 Then            Return Drawing.Color.LimeGreen        ElseIf hp < 100 And hp > 90 Then            Return Drawing.Color.Lime        ElseIf hp < 91 And hp > 70 Then            Return Drawing.Color.GreenYellow        ElseIf hp < 71 And hp > 60 Then            Return Drawing.Color.Yellow        ElseIf hp < 61 And hp > 40 Then            Return Drawing.Color.Orange        ElseIf hp < 41 And hp > 30 Then            Return Drawing.Color.OrangeRed        ElseIf hp < 31 Then            Return Drawing.Color.Red        End If    End Function    Sub framedrawn(sender As Object, e As GTA.GraphicsEventArgs) Handles Me.PerFrameDrawing        If toggled Then            For Each Ped As GTA.Ped In World.GetPeds(Player.Character.Position, 50) 'Here I am going to draw the info of the peds on the radius '                If Ped.Exists Then                    Dim i As Integer = Game.LocalPlayer.Character.Heading                    If Not Ped = Game.LocalPlayer.Character And Ped.isAlive Then                        If i > 0 And i < 90 Then                            e.Graphics.DrawRectangle(New System.Drawing.RectangleF((Game.Resolution.Width / 2) + ((Ped.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((Ped.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100), 100, 20), Drawing.Color.Gray)                            e.Graphics.DrawRectangle(New System.Drawing.RectangleF((Game.Resolution.Width / 2) + ((Ped.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((Ped.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100), Ped.Health, 20), hpcolor(Ped.Health))                            e.Graphics.DrawText(Ped.PedType.ToString + Environment.NewLine + "HP: " + Ped.Health.ToString + Environment.NewLine + "Armor: " + Ped.Armor.ToString, (Game.Resolution.Width / 2) + ((Ped.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((Ped.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100))                        ElseIf i < 300 Then                            e.Graphics.DrawRectangle(New System.Drawing.RectangleF((Game.Resolution.Width / 2) - ((Ped.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((Ped.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100), 100, 20), Drawing.Color.Gray)                            e.Graphics.DrawRectangle(New System.Drawing.RectangleF((Game.Resolution.Width / 2) - ((Ped.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((Ped.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100), Ped.Health, 20), hpcolor(Ped.Health))                            e.Graphics.DrawText(Ped.PedType.ToString + Environment.NewLine + "HP: " + Ped.Health.ToString + Environment.NewLine + "Armor: " + Ped.Armor.ToString, (Game.Resolution.Width / 2) - ((Ped.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((Ped.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100))                        Else                            e.Graphics.DrawRectangle(New System.Drawing.RectangleF((Game.Resolution.Width / 2) + ((Ped.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((Ped.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100), 100, 20), Drawing.Color.Gray)                            e.Graphics.DrawRectangle(New System.Drawing.RectangleF((Game.Resolution.Width / 2) + ((Ped.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((Ped.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100), Ped.Health, 20), hpcolor(Ped.Health))                            e.Graphics.DrawText(Ped.PedType.ToString + Environment.NewLine + "HP: " + Ped.Health.ToString + Environment.NewLine + "Armor: " + Ped.Armor.ToString, (Game.Resolution.Width / 2) + ((Ped.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((Ped.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100))                        End If                    End If                End If            Next            For Each vehicle1 As GTA.Vehicle In World.GetVehicles(Player.Character.Position, 50) 'And here the vehicles '                Try                    If vehicle1.Exists Then                        Dim i As Integer = Game.LocalPlayer.Character.Heading                        If i > 0 And i < 90 Then                            e.Graphics.DrawRectangle(New System.Drawing.RectangleF((Game.Resolution.Width / 2) + ((vehicle1.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((vehicle1.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100), 100, 20), Drawing.Color.Gray)                            e.Graphics.DrawRectangle(New System.Drawing.RectangleF((Game.Resolution.Width / 2) + ((vehicle1.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((vehicle1.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100), vehicle1.Health / 10, 20), hpcolor(vehicle1.Health))                            e.Graphics.DrawText(vehicle1.Name + Environment.NewLine + "HP: " + vehicle1.Health.ToString + Environment.NewLine + "Speed: " + vehicle1.Speed.ToString, (Game.Resolution.Width / 2) + ((vehicle1.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((vehicle1.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100))                        ElseIf i < 300 Then                            e.Graphics.DrawRectangle(New System.Drawing.RectangleF((Game.Resolution.Width / 2) - ((vehicle1.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((vehicle1.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100), 100, 20), Drawing.Color.Gray)                            e.Graphics.DrawRectangle(New System.Drawing.RectangleF((Game.Resolution.Width / 2) - ((vehicle1.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((vehicle1.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100), vehicle1.Health / 10, 20), hpcolor(vehicle1.Health))                            e.Graphics.DrawText(vehicle1.Name + Environment.NewLine + "HP: " + vehicle1.Health.ToString + Environment.NewLine + "Speed: " + vehicle1.Speed.ToString, (Game.Resolution.Width / 2) - ((vehicle1.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((vehicle1.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100))                        Else                            e.Graphics.DrawRectangle(New System.Drawing.RectangleF((Game.Resolution.Width / 2) + ((vehicle1.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((vehicle1.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100), 100, 20), Drawing.Color.Gray)                            e.Graphics.DrawRectangle(New System.Drawing.RectangleF((Game.Resolution.Width / 2) + ((vehicle1.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((vehicle1.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100), vehicle1.Health / 10, 20), hpcolor(vehicle1.Health))                            e.Graphics.DrawText(vehicle1.Name + Environment.NewLine + "HP: " + vehicle1.Health.ToString + Environment.NewLine + "Speed: " + vehicle1.Speed.ToString, (Game.Resolution.Width / 2) + ((vehicle1.Position.X - Game.LocalPlayer.Character.Position.X) * 100), (Game.Resolution.Height / 2) - ((vehicle1.Position.Y - Game.LocalPlayer.Character.Position.Y) * 100))                        End If                    End If                Catch ex As Exception                End Try            Next        End If    End SubEnd Class

 

 

 

Help is always appreciated :)!

Edited by santtuz112

Share this post


Link to post
Share on other sites
zielarz119

I don't know much about scripting, but couldn't you use the script that shows you names of players in online?

Share this post


Link to post
Share on other sites
santtuz112

I don't know much about scripting, but couldn't you use the script that shows you names of players in online?

If you mean the way you see player names online normally in gta iv, not really because that's how it's done in gta it self, not in scripthook, now if you mean someone else written script who's you mean?

Share this post


Link to post
Share on other sites
santtuz112

ah man, i tryed make this happen too, but my math and logic knowledge are not good enough to understand the calcs required to convert 3d position into 2d screen position, there are some posts that talk about this:

 

http://www.codeincodeblock.com/2012/03/projecting-3d-world-co-ordinates-into.html

Yeah, I have trouble with it too, but thanks for the link, I would still see the info through walls and objects tho, Also that's too much for my brain to understand D:

But hey, let me know if you are going to try again and having better luck then!

Share this post


Link to post
Share on other sites
julionib

my tests resulted in something similar that you have in video, when object is close to center the precision is increased, now im going to create a jet aim system like we have in gta V and my actual solution will be create a square that will represent the targeted vehicle, would be much easier and precise with the projection from 3d to 2d but ^^

Share this post


Link to post
Share on other sites
AgentWD40

deleted

Edited by hardsty1e

Share this post


Link to post
Share on other sites
santtuz112

found this old script that displays enemies who injure you into a 2d vector of the 3d world on screen. this isn't my code & I don't know his name so lets not credit ourselves fully. :p

 

 

 

#region using

using System;

using System.Windows.Forms;

using System.Drawing;

using System.IO;

using System.Text;

using System.Collections.Generic;

using GTA;

#endregion

 

public class injured_vector : Script

{

#region

const double TO_RADIAN = 0.017453292519943295;

const float radius = 4.0f;

const int the_time = 10000;

Vector3 vec1, vec2, pos_temp_1, pos_temp_2, rot_temp_1;

int int_temp_1, int_temp_2;

double float_temp_1;

Boolean NGorOK;

Ped[] hito;

Ped[] targeted_ped = new Ped[10];

int[] timer = new int[10];

GTA.Font screenFont;

GTA.GraphicsEventArgs gura;

 

const int RRR = 255;

#endregion

 

#region

public injured_vector()

{

int_temp_2 = Game.GameTime;

Interval = 0;

this.Tick += new EventHandler(this.injured_vector_Tick);

}

#endregion

 

#region Tick

void injured_vector_Tick(object sender, EventArgs e)

{

//Game.DisplayText("" + (int)(Game.CurrentCamera.Rotation.Z), 1000);

#region lƒQƒbƒgB

if (Game.GameTime - int_temp_2 > 500)

{

int_temp_2 = Game.GameTime;

if (Exists(Player.Character) == true)

{

hito = World.GetPeds(Player.Character.Position, 200.0f);

for (int i = 0; i < hito.Length; i++)

{

NGorOK = true;

if (Exists(hito) == true && hito.isAlive == true && hito != Player.Character && GTA.Native.Function.Call<bool>("HAS_CHAR_BEEN_DAMAGED_BY_CHAR", Player.Character, hito) == true)

//_GTA.Native.Function.Call<bool>("IS_CHAR_SHOOTING", hito) == true &&

{

GTA.Native.Function.Call("CLEAR_CHAR_LAST_DAMAGE_ENTITY", Player.Character);

/////////////////////////////////////////////

#region all_check

for (int j = 0; j < targeted_ped.Length; j++)

{

if (Exists(targeted_ped[j]) == true)

{

if (targeted_ped[j].isAlive == true)

{

if (targeted_ped[j] == hito)

{

timer[j] = Game.GameTime;

NGorOK = false;

break;

}

}

}

}

if (NGorOK == false) { continue; }

#endregion

/////////////////////////////////////////////

#region store_hito

for (int j = 0; j < targeted_ped.Length; j++)

{

if (Exists(targeted_ped[j]) == true)

{

}

else

{

targeted_ped[j] = hito;

timer[j] = Game.GameTime;

NGorOK = false;

break;

}

}

#endregion

/////////////////////////////////////////////

}

}

}

}

#endregion

///////////////////////////////////////////////

#region

//int_temp_1 = 0;

for (int i = 0; i < targeted_ped.Length; i++)

{

if (Exists(targeted_ped) == true)

{

if (targeted_ped.isAlive == true)

{

if (Game.GameTime - timer < the_time)

{

//int_temp_1++;

float_temp_1 = Math.Atan2((targeted_ped.Position.Y - Player.Character.Position.Y) , (targeted_ped.Position.X - Player.Character.Position.X));

float_temp_1 = float_temp_1 - Game.CurrentCamera.Rotation.Z * TO_RADIAN;

float_temp_1 += 1.570796;

//Game.DisplayText("" + (int)(float_temp_1), 1000);

//•\Ž¦ŠÖ”

//int_temp_1 = (int)(Player.Character.Position.DistanceTo(targeted_ped.Position));

GTA.Native.Function.Call("DRAW_RECT", 0.5f, 0.5f, 0.0075f, 0.01f, 255, 255, 255, (int)(200.0f - 200.0f * (float)(Game.GameTime - timer) / (float)(the_time)));

GTA.Native.Function.Call("DRAW_RECT", 0.5f + 0.15f * (float)(Math.Sin(float_temp_1)), 0.5f + 0.15f * (float)(Math.Cos(float_temp_1)), 0.0075f, 0.01f, RRR, 0, 0, (int)(200.0f - 200.0f * (float)(Game.GameTime - timer) / (float)(the_time)));

}

else

{

timer = the_time;

targeted_ped = null;

}

}

else

{

timer = the_time;

targeted_ped = null;

}

}

else

{

timer = the_time;

targeted_ped = null;

}

}

//Game.DisplayText("" + int_temp_1, 1000);

#endregion

///////////////////////////////////////////////

}

#endregion

}

 

 

Thanks man it works, too bad you don't know who made the script :(

Share this post


Link to post
Share on other sites
julionib

in what screen resolution you tested this code?

Share this post


Link to post
Share on other sites
santtuz112

in what screen resolution you tested this code?

1920x1080

First tested it as original, worked as intended to show player giving you damage, Didn't test much but it did work, Edited the code then to do my purpose and still works fine.

Share this post


Link to post
Share on other sites
InfamousSabre

Id really like to see how it works with this new code. really been trying to convert 3d game position to 2d screen position also

Share this post


Link to post
Share on other sites
santtuz112

Id really like to see how it works with this new code. really been trying to convert 3d game position to 2d screen position also

Rendering the video now :)

Share this post


Link to post
Share on other sites
santtuz112

Id really like to see how it works with this new code. really been trying to convert 3d game position to 2d screen position also

 

there, But first half of the video is only about the 3d to 2d, Rest of the video is other thing I just wanted to show my friend, script that lets you remote control vehicles by me, but it's not that great and I made it in c# even tho I don't code c# usually when I code. Also watch it on fullscreen to see the text

Edited by santtuz112

Share this post


Link to post
Share on other sites
InfamousSabre

That does get it pretty close to the proper position lol. If i ever find out how to get proper precise 3d to 2d positions, Ill post it here.
Have you seen Vector3.Project()?

Share this post


Link to post
Share on other sites
santtuz112

That does get it pretty close to the proper position lol. If i ever find out how to get proper precise 3d to 2d positions, Ill post it here.

Have you seen Vector3.Project()?

Nope

Share this post


Link to post
Share on other sites
InfamousSabre

from its description in the scripthookdotnet chm file, it does exactly what we are looking for. we just have to give it the proper World-View-Projection matrix.

I've been through tons of world-view-projection matrix guides on the web trying to learn about them so I can figure out how to get this from GTA, but so far, no luck

If anyone knows how to get this matrix, please, educate us!

Share this post


Link to post
Share on other sites
iriedreadlock23

I wanted to include this in MobilePhone SDK, but for some reason it didn't happen. Clues for this were found in IV:MP source code. You can also display text in 3D world by attaching a custom object with screen to other in-game objects, and then rendering text to attached object's screen.

 Sub GetScreenPositionFromWorldCoordinate()        Dim Screen As Integer = 0        Dim ViewWidth As Integer = 1280        Dim ViewHeight As Integer = 1024        Dim Viewx As Single = 0.0F        Dim Viewy As Single = 0.0F        Dim x As New GTA.Native.Pointer(GetType(Single))        Dim y As New GTA.Native.Pointer(GetType(Single))        Dim xpos As Vector3 = Game.LocalPlayer.Character.GetBonePosition(Bone.Head)        Dim ViewportId As New GTA.Native.Pointer(GetType(Integer))        Native.Function.Call("GET_GAME_VIEWPORT_ID", ViewportId)        Screen = ViewportId.Value        Native.Function.Call("GET_VIEWPORT_POSITION_OF_COORD", xpos.X, xpos.Y, xpos.Z, Screen, x, y)        Viewx = Math.Round(x.Value / ViewWidth, 3) + 0.1        Viewy = Math.Round(y.Value / ViewHeight, 3)        Native.Function.Call("DRAW_RECT", Viewx, Viewy, 0.1, 0.1, 255, 0, 0, 255)        Game.DisplayText(Viewx & " : " & Viewy)    End Sub

Share this post


Link to post
Share on other sites
InfamousSabre

I'm not understanding why you divided x and y by ViewWidth and ViewHeight.

I had to use x and y as the return values for this to work, but it does work great. There is one issue though. It seems to display one coordinate in the proper location, and another, 180 degrees on the other side of you.

Edited by InfamousSabre

Share this post


Link to post
Share on other sites
iriedreadlock23

You have to divide viewport coordinates (X and Y) with your screen resolution (ViewWidth and ViewHeight), in order to convert pixels to percents. This is required if you want to use native functions to display text/draw textures and objects on screen. Also, whatever 3D coordinate you use, make sure that position is actually visible to camera.

Function isCoordVisible(ByVal WorldCoord As Vector3, Optional ByVal AreaSize As Single = 1.0F) As Boolean   Return Native.Function.Call(Of Boolean)("CAM_IS_SPHERE_VISIBLE", Game.CurrentCamera, WorldCoord.X, WorldCoord.Y, WorldCoord.Z, AreaSize)End Function
Edited by iriedreadlock23

Share this post


Link to post
Share on other sites
InfamousSabre

When I had looked up that native, it said that if something broke the line-of-sight, like a building, it would return false.

After testing, that proved to be false. CAM_IS_SPHERE_VISIBLE does not take into account line-of-sight. This is good for what I need it for.

Thanks man you're a huge help! :)

Share this post


Link to post
Share on other sites
Michael Wojtanis

Lol.

Mayby You want my source of Waypoint 3D mod?

 

It is beta [still need work for fov in higher positions] but works good.

 

I tried to Vector3.Project() but after a week of trying different values... i give up and made something like Vector3.Project from basic [FOV, X, Y of screen, x, y of point... etc]

 

here video:

 

Edited by Michael Wojtanis

Share this post


Link to post
Share on other sites
InfamousSabre

These two methods work fine for anyone developing in C#

    public Vector2 CoordToScreen(Vector3 vect)    {        int Screen = 0;        GTA.Native.Pointer x = new GTA.Native.Pointer(typeof(float));        GTA.Native.Pointer y = new GTA.Native.Pointer(typeof(float));        Vector3 xpos = vect;        GTA.Native.Pointer ViewportId = new GTA.Native.Pointer(typeof(int));        GTA.Native.Function.Call("GET_GAME_VIEWPORT_ID", ViewportId);        Screen = ViewportId;        GTA.Native.Function.Call("GET_VIEWPORT_POSITION_OF_COORD", xpos.X, xpos.Y, xpos.Z, Screen, x, y);                return new Vector2(x,y);    }        public bool isCoordVisible(Vector3 WorldCoord, float AreaSize = 1f)    {        if(Game.Exists(Game.CurrentCamera))        {                return GTA.Native.Function.Call<bool>("CAM_IS_SPHERE_VISIBLE", Game.CurrentCamera, WorldCoord.X, WorldCoord.Y, WorldCoord.Z, AreaSize);        }        else{return false;}    }

use this way

(in PerFrameDrawing event)

Vector3 WorldPosition = //insert Vector3 you want shown here (eg: Game.LocalPlayer.Character.Position)if( isCoordVisible( WorldPosition ) ){    Vector2 ScreenPosition = CoordToScreen( WorldPosition );    e.Graphics.DrawRect( ScreenPosition.X, ScreenPosition.Y, 32, 32, System.Drawing.Color.White )}

that last bit is just off the top of my head, but should draw a 32x32 white rectangle at your specified coordinate

Edited by InfamousSabre

Share this post


Link to post
Share on other sites
Michael Wojtanis
using GTA;using System;using System.Drawing;namespace drawing3D{    public class drawing3D_R : Script    {        GTA.Native.Pointer x,y,ViewportId;        public drawing3D_R()        {        x = new GTA.Native.Pointer(typeof(float));        y = new GTA.Native.Pointer(typeof(float));        ViewportId = new GTA.Native.Pointer(typeof(int));            this.PerFrameDrawing+= new GraphicsEventHandler(DRAW_POINT);        }        public Vector2 CoordToScreen(Vector3 vect)    {        int Screen = 0;                Vector3 xpos = vect;                GTA.Native.Function.Call("GET_GAME_VIEWPORT_ID", ViewportId);        Screen = ViewportId;        GTA.Native.Function.Call("GET_VIEWPORT_POSITION_OF_COORD", xpos.X, xpos.Y, xpos.Z, Screen, x, y);                return new Vector2(x,y);    }        public bool isCoordVisible(Vector3 WorldCoord, float AreaSize = 1f)    {        if(Game.Exists(Game.CurrentCamera))        {                return GTA.Native.Function.Call<bool>("CAM_IS_SPHERE_VISIBLE", Game.CurrentCamera, WorldCoord.X, WorldCoord.Y, WorldCoord.Z, AreaSize);        }        else{return false;}    }    public void DRAW_POINT(object sender, GraphicsEventArgs g)    {        Vector3 WorldPosition = Player.Character.GetBonePosition(Bone.Head);//insert Vector3 you want shown here (eg: Game.LocalPlayer.Character.Position)        float distance = Game.CurrentCamera.Position.DistanceTo(Player.Character.GetBonePosition(Bone.Head)) * 8;        if (distance < 20)            distance = Game.CurrentCamera.Position.DistanceTo(Player.Character.GetBonePosition(Bone.Head));        if( isCoordVisible( WorldPosition ) )        {            Vector2 ScreenPosition = CoordToScreen( WorldPosition );            g.Graphics.DrawRectangle(ScreenPosition.X, ScreenPosition.Y, 100 - distance, 100 - distance, System.Drawing.Color.White);        }    }    }}

Okey, here You go.

This works fine.

 

Draw rectangle on player head. Of course this should need some fix (distance to head from camera) to cover all head but works.

 

My Waypoint3D need rebuild. Thanks people and I hope this give us many new beautiful mods. :)

Share this post


Link to post
Share on other sites
julionib

nice nice nice, i wil check this codes, the results in videos seems very good

Share this post


Link to post
Share on other sites
InfamousSabre

Here is the CoordToScreen in action.
The Icons with arrows on them are representing off-screen peds and are not part of CoordToScreen, but are part of another Method I put together that works alongside CoordToScreen.

 

Icons above ped heads are placed with CoordToScreen.
The ? are alerted peds.

The ! is an alerted ped calling the police. (I killed him to avoid a wanted level)

This is part of a new feature in "Silence!"

 

Edited by InfamousSabre

Share this post


Link to post
Share on other sites
julionib

guys this GET_VIEWPORT_POSITION_OF_COORD is perfect, thx for all who shared solutions :)

 

now my codes can have more appropriate target HUD :)

 

af859651b5cc33ea75aac2db05ca0a3c.png

Share this post


Link to post
Share on other sites
InfamousSabre

guys this GET_VIEWPORT_POSITION_OF_COORD is perfect, thx for all who shared solutions :)

 

now my codes can have more appropriate target HUD :)

And to think, it was a native this whole time, lol..

Looks like you've got some depth detection going on in that pic, albeit a bit reversed for your application, no? :p

Share this post


Link to post
Share on other sites
julionib

yeah, i never knew right what was a viewport, never really understood how to use the native methods related to viewport ^^

and yes, the rectangles should be bigger close to player ^^, i was just testing with a fast code to see if works


this one here was my last try to identify the targets using this same code just with different coeficient calc:

 

https://fbcdn-sphotos-e-a.akamaihd.net/hphotos-ak-ash3/t31/1524134_678417632224948_565585398_o.jpg

Share this post


Link to post
Share on other sites
InfamousSabre

yeah, i never knew right what was a viewport, never really understood how to use the native methods related to viewport ^^

and yes, the rectangles should be bigger close to player ^^, i was just testing with a fast code to see if works


this one here was my last try to identify the targets using this same code just with different coeficient calc:

 

https://fbcdn-sphotos-e-a.akamaihd.net/hphotos-ak-ash3/t31/1524134_678417632224948_565585398_o.jpg

Looks good. Each vehicle is lined up pretty well. so well in fact, the rectangles kinda look like photos of the cars. lol

 

================================================================================================================

 

just found this when reading up on SlimDX. May help anyone who would still rather do things the manual way. Actual Matrix multiplication and whatnot.
Will have to be converted for use with Scripthook of course.

private void Setup_Matrices()        {                View_Matrix = Matrix.LookAtRH(Create_Vertex(Camera_Position.X, Camera_Position.Y, Camera_Position.Z), Create_Vertex(0, 0, 0), Create_Vertex(0, 1, 0));                Device.Transform.View = View_Matrix;                Projection_Matrix = Matrix.PerspectiveFovRH(FOV, ASPECT_RATIO, NEAR_Z, FAR_Z);                Device.Transform.Projection = Projection_Matrix;        }
private void Camera_Control()        {                Matrix Camera_Translation_Matrix;                Matrix Camera_Angle_Matrix_X;                Matrix Camera_Angle_Matrix_Y;                View_Matrix = Matrix.Identity;                Camera_Translation_Matrix = Matrix.Identity;    Camera_Translation_Matrix = Matrix.Translation(Camera_Position.X, Camera_Position.Y, -Camera_Position.Z);        View_Matrix = Matrix.Multiply(View_Matrix, Camera_Translation_Matrix);    Camera_Angle_Matrix_Y = Matrix.RotationY((Convert.ToSingle(Math.PI) * Camera_Angle.Y) / 180);                View_Matrix = Matrix.Multiply(View_Matrix, Camera_Angle_Matrix_Y);    Camera_Angle_Matrix_X = Matrix.RotationX((Convert.ToSingle(Math.PI) * Camera_Angle.X) / 180);                View_Matrix = Matrix.Multiply(View_Matrix, Camera_Angle_Matrix_X);    Device.Transform.View = View_Matrix;        }
Edited by InfamousSabre

Share this post


Link to post
Share on other sites
julionib

today i made a test with this native call, its just perfect:

 

 

 

its possible create some cool effects like "x ray vision" or something like that

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.