1- tx ,ty ,tz = 91 ,100 ,502 -- The position of the element
1+ tx ,ty ,tz = 100 ,100 ,15000 -- The position of the element
22local hideX ,hideY ,hideZ = 0 ,0 ,0 -- where to hide the local player
33local rz = 0 -- The current rotation
44local maxRadius = 5
@@ -23,6 +23,7 @@ function browserSetElementModel ( elemID, model )
2323 setModel [elemID ](model )
2424 end
2525end
26+
2627function setModel .vehicleID ( model )
2728 local randomOffset = ((getTickCount () % 20 ) / 100 ) + 0.001
2829
@@ -60,26 +61,31 @@ function setModel.vehicleID ( model )
6061 setCameraMatrix ( tx - realDistance , ty , tz + elevation + randomOffset ,
6162 tx , ty + moveLeft , tz + randomOffset )
6263end
64+
6365function setModel .objectID ( model )
6466 local randomOffset = ((getTickCount () % 20 ) / 100 ) + 0.001
6567
6668 if not browser .mainElement then
67- browser .mainElement = createObject (model , tx , ty , tz , 0 , 0 , rz )
69+ browser .mainElement = createObject (model , tx , ty , tz , 0 , 0 , rz , true )
70+ setElementDoubleSided (browser .mainElement , guiCheckBoxGetSelected (browserGUI .doubleside ))
6871 setElementDimension ( browser .mainElement , BROWSER_DIMENSION )
6972 setElementInterior (browser .mainElement , 14 )
7073 else
7174 setElementModel (browser .mainElement , model )
7275 end
7376
74- setElementPosition (browser .mainElement , tx , ty , tz + randomOffset )
77+ setElementPosition (browser .mainElement , tx , ty , tz )
7578 setElementAlpha (browser .mainElement , 255 )
7679
77- local radius = getElementRadius (browser .mainElement )
78- browserElementLookOptions .distance = 14
79- setObjectScale ( browser .mainElement , maxRadius / radius )
80- setCameraMatrix ( tx - 17 , ty , tz + 3 + randomOffset ,
81- tx , ty + 2 , tz + randomOffset )
80+ local a ,b ,c ,d ,e ,f = getElementBoundingBox (browser .mainElement )
81+ local radius = math.max (7 , getElementRadius (browser .mainElement )* 2.1 )
82+ radius = math.max (radius , math.sqrt ((c * c )+ (f * f ))* 2 )
83+ browserElementLookOptions .distance = radius
84+ local offset = radius * 0.2
85+ setCameraMatrix ( tx - radius - offset , ty + offset , tz + radius * 0.25 ,
86+ tx - offset , ty + offset , tz )
8287end
88+
8389function setModel .skinID ( model )
8490 local randomOffset = (getTickCount () % 20 ) / 100
8591
@@ -108,9 +114,27 @@ function rotateMesh ()
108114 if ( initiatedType ) == " vehicleID" then
109115 setElementRotation ( browser .mainElement ,0 ,0 ,newRotation )
110116 elseif ( initiatedType ) == " objectID" then
111- setElementRotation ( browser .mainElement , 0 , 0 ,newRotation )
117+ _previewRotate ( browser .mainElement ,newRotation )
112118 elseif ( initiatedType ) == " skinID" then
113- setPedRotation ( browser .mainElement ,newRotation )
119+ setPedRotation ( browser .mainElement ,newRotation )
114120 end
115121end
116122
123+ function _previewRotate (object , rotation )
124+ -- https://github.com/multitheftauto/mtasa-resources/commit/117759a6df540c21515d2666794e05dcf9c76254
125+ local a ,b ,c ,d ,e ,f = getElementBoundingBox (object )
126+
127+ local halfCenterX = (a + d ) * 0.25
128+ local halfCenterY = (b + e ) * 0.25
129+ local halfCenterZ = (c + f ) * 0.25
130+
131+ local rad = math.rad (rotation )
132+ local cZ , sZ = math.cos (rad ), math.sin (rad )
133+
134+ local oX = halfCenterX * cZ - halfCenterY * sZ
135+ local oY = halfCenterX * sZ + halfCenterY * cZ
136+ local oZ = halfCenterZ
137+
138+ setElementPosition (object , tx - oX , ty - oY , tz - oZ )
139+ setElementRotation (object , 0 , 0 , rotation )
140+ end
0 commit comments