Jump to content

Attaching dxText to vehicle component


FuriouZ

Recommended Posts

Posted (edited)

Hello all!

I have question that how i can attach dxText to vehicle component

Example(guieditor)

mta-screen_2014-04-13_14-25-43.png

If i move camera front of the car,then i get theese errors, otherwise debug doesn't show any errors, but text doesn't appear too

mta-screen_2014-04-13_14-42-25.png

addEventHandler("onClientRender",root,
   function()
    local vehicle = getPedOccupiedVehicle(localPlayer)
    local getComponent = getVehicleComponents(vehicle)
       if ( vehicle ) then
           for k in pairs (getComponent) do
	        local vcpX, vcpY, vcpZ = getVehicleComponentPosition(vehicle, "bump_rear_dummy")
			local vcpSP,vcpSP = getScreenFromWorldPosition ( vcpX, vcpY, vcpZ )
		    if ( vcpSP and vcpSP ) then
				dxDrawLine(vcpSP,vcpSP,796, 547, 871, 472, tocolor(255, 255, 255, 255), 2, true)
                   dxDrawLine(vcpSP,vcpSP,871, 472, 1010, 473, tocolor(255, 255, 255, 255), 2, true)
                   dxDrawText(vcpSP,vcpSP,"Damage: 100%", 871, 449, 1010, 473, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, true, false, false)
		    end
		end
    end
   end
)

Edited by Guest
Posted

How i get the vehicle matrix ?

something like this ?

        local vehicle = getPedOccupiedVehicle(localPlayer) 
        local vehX, vehY, vehZ, vehLX, vehLY, vehLZ = getCameraMatrix (vehicle) 
        local vcpSP,vcpSP = getScreenFromWorldPosition ( vehX, vehY, vehZ, vehLX, vehLY, vehLZ ) 

Posted
function getPositionFromElementOffset(element,offX,offY,offZ) 
  local m = getElementMatrix ( element )  -- Get the matrix 
  local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1]  -- Apply transform 
  local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] 
  local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] 
  return x, y, z                               -- Return the transformed point 
end 

Get the offset which equals to minX and minY of vehicle's bounding box and draw a line between the element position and that point.

Posted

This wont work with all components (like misc_c) and modified vehicles could make problems, too. getVehicleComponentPosition has issues and custom vehicles can cause a dummy misplacement. But the bumper should work.

Posted

why would you even want a custom component? If it's something like the roof / spoiler of the car, use the bounding box, it's rather precise. Of course you can get the component position, but some components might be missing for some cars.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...