Quantcast

Jump to content

» «
Photo

Draw text inside world?

47 replies to this topic
santtuz112
  • santtuz112

    Player Hater

  • Members
  • Joined: 24 Dec 2013

#1

Posted 24 December 2013 - 01:35 PM Edited by santtuz112, 31 December 2013 - 04:44 PM.

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

Spoiler

 

Help is always appreciated :)!


zielarz119
  • zielarz119

    Peon

  • Members
  • Joined: 04 Jul 2013

#2

Posted 29 December 2013 - 10:44 PM

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


julionib
  • julionib

    Coder

  • Feroci Racing
  • Joined: 13 Sep 2012
  • Brazil

#3

Posted 29 December 2013 - 11:39 PM

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.codeincod...nates-into.html

  • Deadly Target likes this

santtuz112
  • santtuz112

    Player Hater

  • Members
  • Joined: 24 Dec 2013

#4

Posted 29 December 2013 - 11:40 PM

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?


santtuz112
  • santtuz112

    Player Hater

  • Members
  • Joined: 24 Dec 2013

#5

Posted 29 December 2013 - 11:51 PM

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.codeincod...nates-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!


julionib
  • julionib

    Coder

  • Feroci Racing
  • Joined: 13 Sep 2012
  • Brazil

#6

Posted 30 December 2013 - 08:51 PM

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 ^^


hardsty1e
  • hardsty1e

    RIP Yeardley Diamond

  • Members
  • Joined: 02 May 2009
  • Philippines

#7

Posted 30 December 2013 - 09:59 PM Edited by hardsty1e, 28 August 2014 - 07:33 PM.

deleted


santtuz112
  • santtuz112

    Player Hater

  • Members
  • Joined: 24 Dec 2013

#8

Posted 31 December 2013 - 04:44 PM

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

 

Spoiler

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


julionib
  • julionib

    Coder

  • Feroci Racing
  • Joined: 13 Sep 2012
  • Brazil

#9

Posted 02 January 2014 - 12:29 AM

in what  screen resolution you tested this code?


santtuz112
  • santtuz112

    Player Hater

  • Members
  • Joined: 24 Dec 2013

#10

Posted 02 January 2014 - 02:46 AM

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.


InfamousSabre
  • InfamousSabre

    Harpocrates

  • Members
  • Joined: 03 Jan 2013

#11

Posted 04 January 2014 - 02:36 PM

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


santtuz112
  • santtuz112

    Player Hater

  • Members
  • Joined: 24 Dec 2013

#12

Posted 04 January 2014 - 04:40 PM

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 :)


santtuz112
  • santtuz112

    Player Hater

  • Members
  • Joined: 24 Dec 2013

#13

Posted 04 January 2014 - 05:57 PM Edited by santtuz112, 04 January 2014 - 06:04 PM.

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


InfamousSabre
  • InfamousSabre

    Harpocrates

  • Members
  • Joined: 03 Jan 2013

#14

Posted 04 January 2014 - 07:43 PM

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()?


santtuz112
  • santtuz112

    Player Hater

  • Members
  • Joined: 24 Dec 2013

#15

Posted 04 January 2014 - 08:37 PM

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


InfamousSabre
  • InfamousSabre

    Harpocrates

  • Members
  • Joined: 03 Jan 2013

#16

Posted 04 January 2014 - 08:46 PM

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!


iriedreadlock23
  • iriedreadlock23

    Dr. Frankenstein

  • Members
  • Joined: 14 Jan 2009

#17

Posted 08 January 2014 - 03:29 AM

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

InfamousSabre
  • InfamousSabre

    Harpocrates

  • Members
  • Joined: 03 Jan 2013

#18

Posted 08 January 2014 - 08:21 AM Edited by InfamousSabre, 08 January 2014 - 08:41 AM.

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.


iriedreadlock23
  • iriedreadlock23

    Dr. Frankenstein

  • Members
  • Joined: 14 Jan 2009

#19

Posted 08 January 2014 - 05:21 PM Edited by iriedreadlock23, 08 January 2014 - 05:27 PM.

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

InfamousSabre
  • InfamousSabre

    Harpocrates

  • Members
  • Joined: 03 Jan 2013

#20

Posted 09 January 2014 - 01:54 AM

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! :)


Michael Wojtanis
  • Michael Wojtanis

    Rinepim

  • Members
  • Joined: 17 Jul 2013

#21

Posted 14 January 2014 - 01:06 PM Edited by Michael Wojtanis, 14 January 2014 - 01:10 PM.

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:


InfamousSabre
  • InfamousSabre

    Harpocrates

  • Members
  • Joined: 03 Jan 2013

#22

Posted 14 January 2014 - 11:29 PM Edited by InfamousSabre, 15 January 2014 - 12:32 AM.

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

  • julionib and Michael Wojtanis like this

Michael Wojtanis
  • Michael Wojtanis

    Rinepim

  • Members
  • Joined: 17 Jul 2013

#23

Posted 16 January 2014 - 08:51 AM

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. :)

  • julionib likes this

julionib
  • julionib

    Coder

  • Feroci Racing
  • Joined: 13 Sep 2012
  • Brazil

#24

Posted 16 January 2014 - 12:49 PM

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


InfamousSabre
  • InfamousSabre

    Harpocrates

  • Members
  • Joined: 03 Jan 2013

#25

Posted 16 January 2014 - 01:33 PM Edited by InfamousSabre, 16 January 2014 - 01:41 PM.

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!"

 

  • hardsty1e likes this

julionib
  • julionib

    Coder

  • Feroci Racing
  • Joined: 13 Sep 2012
  • Brazil

#26

Posted 16 January 2014 - 04:07 PM

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


InfamousSabre
  • InfamousSabre

    Harpocrates

  • Members
  • Joined: 03 Jan 2013

#27

Posted 16 January 2014 - 10:13 PM

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


julionib
  • julionib

    Coder

  • Feroci Racing
  • Joined: 13 Sep 2012
  • Brazil

#28

Posted 17 January 2014 - 10:18 AM

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-sphoto...565585398_o.jpg

  • InfamousSabre likes this

InfamousSabre
  • InfamousSabre

    Harpocrates

  • Members
  • Joined: 03 Jan 2013

#29

Posted 17 January 2014 - 12:19 PM Edited by InfamousSabre, 17 January 2014 - 12:27 PM.

 

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-sphoto...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;        
}

julionib
  • julionib

    Coder

  • Feroci Racing
  • Joined: 13 Sep 2012
  • Brazil

#30

Posted 21 January 2014 - 12:08 AM

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

  • hardsty1e likes this




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users