Quantcast

Jump to content

» «
Photo

[IV] Draw Texture infront of car.

15 replies to this topic
stef538
  • stef538

    It's just me, going 88 MPH.

  • Members
  • Joined: 06 Oct 2012
  • Netherlands

#1

Posted 09 June 2014 - 11:54 AM

Hey, guys, so I was wondering how to draw a texture in front of a car.

Anyone has an idea ? I know that drawing a rectangle and such is possible, but i just don't understand how it works.


LetsPlayOrDy
  • LetsPlayOrDy

    Too fast for ya

  • Members
  • Joined: 24 Aug 2013
  • United-States

#2

Posted 09 June 2014 - 12:37 PM

Hey, guys, so I was wondering how to draw a texture in front of a car.

Anyone has an idea ? I know that drawing a rectangle and such is possible, but i just don't understand how it works.

 

Well I haven't exactly done this before, but I believe you should get the 3D coordinates of the front of the car, then convert those 3D coordinates to 2D, then use them for drawing.

Here's a post for 3D to 2D. http://gtaforums.com...entry1064521790


stef538
  • stef538

    It's just me, going 88 MPH.

  • Members
  • Joined: 06 Oct 2012
  • Netherlands

#3

Posted 09 June 2014 - 12:39 PM

I've seen that one, but it didn't really turn out the way i hoped :/


LetsPlayOrDy
  • LetsPlayOrDy

    Too fast for ya

  • Members
  • Joined: 24 Aug 2013
  • United-States

#4

Posted 09 June 2014 - 12:42 PM

I've seen that one, but it didn't really turn out the way i hoped :/

 

What do you mean?


stef538
  • stef538

    It's just me, going 88 MPH.

  • Members
  • Joined: 06 Oct 2012
  • Netherlands

#5

Posted 09 June 2014 - 01:44 PM

well, sometimes I couldn't see the white rectangle, and it would not go to the vector3 position i wanted it to be :p


LetsPlayOrDy
  • LetsPlayOrDy

    Too fast for ya

  • Members
  • Joined: 24 Aug 2013
  • United-States

#6

Posted 09 June 2014 - 03:44 PM

well, sometimes I couldn't see the white rectangle, and it would not go to the vector3 position i wanted it to be :p

 

Hmm, I'll try some things, and get back to you asap


stef538
  • stef538

    It's just me, going 88 MPH.

  • Members
  • Joined: 06 Oct 2012
  • Netherlands

#7

Posted 09 June 2014 - 04:34 PM

thanks! that's Great!!


LetsPlayOrDy
  • LetsPlayOrDy

    Too fast for ya

  • Members
  • Joined: 24 Aug 2013
  • United-States

#8

Posted 09 June 2014 - 04:38 PM

 

well, sometimes I couldn't see the white rectangle, and it would not go to the vector3 position i wanted it to be :p

 

Hmm, I'll try some things, and get back to you asap

 

 

I made my own... seems to work fine http://i.imgur.com/fiUYLiV.png


stef538
  • stef538

    It's just me, going 88 MPH.

  • Members
  • Joined: 06 Oct 2012
  • Netherlands

#9

Posted 09 June 2014 - 04:41 PM

and How did you do that ?


LetsPlayOrDy
  • LetsPlayOrDy

    Too fast for ya

  • Members
  • Joined: 24 Aug 2013
  • United-States

#10

Posted 09 June 2014 - 04:53 PM

and How did you do that ?

 

Copied the functions to my script

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

and then added the code to draw (in PerFrameDrawing)

if (Player.Character.CurrentVehicle != null && Player.Character.isInVehicle())
            {
                Vector3 WorldPosition = Player.Character.CurrentVehicle.GetOffsetPosition(new Vector3(0, 3, 0));
                if (isCoordVisible(WorldPosition))
                {
                    Vector2 ScreenPosition = CoordToScreen(WorldPosition);
                    e.Graphics.DrawRectangle(ScreenPosition.X, ScreenPosition.Y, 32, 32, System.Drawing.Color.White);
                }
            }
  • stef538 likes this

stef538
  • stef538

    It's just me, going 88 MPH.

  • Members
  • Joined: 06 Oct 2012
  • Netherlands

#11

Posted 09 June 2014 - 05:00 PM

hmm.. ok, well a really big thank you!!  :lol:  :lol:  :lol:


LetsPlayOrDy
  • LetsPlayOrDy

    Too fast for ya

  • Members
  • Joined: 24 Aug 2013
  • United-States

#12

Posted 09 June 2014 - 05:05 PM

hmm.. ok, well a really big thank you!!  :lol:  :lol:  :lol:

Lol np ;)


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#13

Posted 09 June 2014 - 06:41 PM

the only thing that sucks is the native CAM_IS_SPHERE_VISIBLE will always return false if u load your game... engine bug i guess


LetsPlayOrDy
  • LetsPlayOrDy

    Too fast for ya

  • Members
  • Joined: 24 Aug 2013
  • United-States

#14

Posted 09 June 2014 - 09:14 PM

the only thing that sucks is the native CAM_IS_SPHERE_VISIBLE will always return false if u load your game... engine bug i guess

 

The way to fix that is by replacing "isCoordVisible" with this code:

bool isCoordVisibleToCam(Vector3 vector)
        {
            float direction_to_that = Vector3.Subtract(Vector3.Normalize(Vector3.Subtract(vector, Game.CurrentCamera.Position)), Game.CurrentCamera.Direction).Length();
            if (direction_to_that > 0.6F)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
  • LordOfTheBongs likes this

InfamousSabre
  • InfamousSabre

    Harpocrates

  • Members
  • Joined: 03 Jan 2013

#15

Posted 10 June 2014 - 04:05 AM

the only thing that sucks is the native CAM_IS_SPHERE_VISIBLE will always return false if u load your game... engine bug i guess

 
The way to fix that is by replacing "isCoordVisible" with this code:
bool isCoordVisibleToCam(Vector3 vector)
        {
            float direction_to_that = Vector3.Subtract(Vector3.Normalize(Vector3.Subtract(vector, Game.CurrentCamera.Position)), Game.CurrentCamera.Direction).Length();
            if (direction_to_that > 0.6F)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

that assumes a certain FOV. could be modified to take FOV into account i suppose.

LetsPlayOrDy
  • LetsPlayOrDy

    Too fast for ya

  • Members
  • Joined: 24 Aug 2013
  • United-States

#16

Posted 10 June 2014 - 01:00 PM

 

 

the only thing that sucks is the native CAM_IS_SPHERE_VISIBLE will always return false if u load your game... engine bug i guess

 
The way to fix that is by replacing "isCoordVisible" with this code:
bool isCoordVisibleToCam(Vector3 vector)
        {
            float direction_to_that = Vector3.Subtract(Vector3.Normalize(Vector3.Subtract(vector, Game.CurrentCamera.Position)), Game.CurrentCamera.Direction).Length();
            if (direction_to_that > 0.6F)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
that assumes a certain FOV. could be modified to take FOV into account i suppose.

 

 

Well this is Michael Wojtanis's code not my lol





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users