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
@@ -64,21 +64,21 @@ function setModel.objectID ( model )
6464 local randomOffset = ((getTickCount () % 20 ) / 100 ) + 0.001
6565
6666 if not browser .mainElement then
67- browser .mainElement = createObject (model , tx , ty , tz , 0 , 0 , rz )
67+ browser .mainElement = createObject (model , tx , ty , tz , 0 , 0 , rz , true )
68+ setElementDoubleSided (browser .mainElement , true )
6869 setElementDimension ( browser .mainElement , BROWSER_DIMENSION )
6970 setElementInterior (browser .mainElement , 14 )
7071 else
7172 setElementModel (browser .mainElement , model )
7273 end
7374
74- setElementPosition (browser .mainElement , tx , ty , tz + randomOffset )
75+ setElementPosition (browser .mainElement , tx , ty , tz )
7576 setElementAlpha (browser .mainElement , 255 )
7677
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 )
78+ local radius = math.max (7 , getElementRadius (browser .mainElement )* 2.1 )
79+ browserElementLookOptions .distance = radius
80+ setCameraMatrix ( tx - radius - 1 , ty + 1 , tz + radius / 4 ,
81+ tx - 1 , ty + 1 , tz )
8282end
8383function setModel .skinID ( model )
8484 local randomOffset = (getTickCount () % 20 ) / 100
@@ -108,9 +108,28 @@ function rotateMesh ()
108108 if ( initiatedType ) == " vehicleID" then
109109 setElementRotation ( browser .mainElement ,0 ,0 ,newRotation )
110110 elseif ( initiatedType ) == " objectID" then
111- setElementRotation ( browser .mainElement , 0 , 0 ,newRotation )
111+ _previewRotate ( browser .mainElement ,newRotation )
112112 elseif ( initiatedType ) == " skinID" then
113- setPedRotation ( browser .mainElement ,newRotation )
113+ setPedRotation ( browser .mainElement ,newRotation )
114114 end
115115end
116116
117+
118+ function _previewRotate (object , rotation )
119+ -- https://github.com/multitheftauto/mtasa-resources/commit/117759a6df540c21515d2666794e05dcf9c76254
120+ local a ,b ,c ,d ,e ,f = getElementBoundingBox (object )
121+
122+ local halfCenterX = (a + d ) * 0.25
123+ local halfCenterY = (b + e ) * 0.25
124+ local halfCenterZ = (c + f ) * 0.25
125+
126+ local rad = math.rad (rotation )
127+ local cZ , sZ = math.cos (rad ), math.sin (rad )
128+
129+ local oX = halfCenterX * cZ - halfCenterY * sZ
130+ local oY = halfCenterX * sZ + halfCenterY * cZ
131+ local oZ = halfCenterZ
132+
133+ setElementPosition (object , tx - oX , ty - oY , tz - oZ )
134+ setElementRotation (object , 0 , 0 , rotation )
135+ end
0 commit comments