MisterQuestions Posted February 26, 2017 Share Posted February 26, 2017 (edited) Hey there, is there anyway to get an element bounding box with its rotation? How to do it? Thanks for reading and hope you can awnser my question. Edit: Is posible to get it when an element is not streamed? Edited February 26, 2017 by XeroxMTA Link to comment
MTA Team botder Posted February 26, 2017 MTA Team Share Posted February 26, 2017 You need OOP enabled: function getElementRotatedBoundingBox(element) local elementMatrix = element:getMatrix() local minX, minY, minZ, maxX, maxY, maxZ = element:getBoundingBox() local minVector = elementMatrix:transformPosition(Vector3(minX, minY, minZ)) local maxVector = elementMatrix:transformPosition(Vector3(maxX, maxY, maxZ)) return minVector, maxVector end Link to comment
MisterQuestions Posted February 26, 2017 Author Share Posted February 26, 2017 (edited) Edit: Forget it, got the awnser, thanks for your help! (Was using bad positions) Edited February 26, 2017 by XeroxMTA Link to comment
MisterQuestions Posted February 26, 2017 Author Share Posted February 26, 2017 Well im here again! Thought was fixed but nope, there's some problem when calculating the boundingbox with "rotation" that way... You can see results here: http://imgur.com/a/nl5zd. It doesn't gets a good rectangle, only on certain "fixed" rotations as 0,90,180,270,360. Any idea of what to do then? Link to comment
Bonsai Posted February 27, 2017 Share Posted February 27, 2017 You could check the editor resource, it does this too. But depending on what you are trying to do, this matrix calculations might be too heavy, e.g. when doing it in a render function. Link to comment
MisterQuestions Posted February 27, 2017 Author Share Posted February 27, 2017 What im exactly searching for on it? Is there any other way to do something like it for a render function? (i mean without being to heavy). Link to comment
MTA Team botder Posted February 27, 2017 MTA Team Share Posted February 27, 2017 (edited) --[[ Draw a fancy bounding box: c-----d |\ /| | \ / | | x | | / \ | |/ \| a-----b ]] local minX, minY, minZ, maxX, maxY, maxZ = vehicle:getBoundingBox() local a = vehicleMatrix:transformPosition(Vector3(minX, minY, maxZ)) drawTextOnWorldPosition("a", a) local b = vehicleMatrix:transformPosition(Vector3(maxX, minY, maxZ)) drawTextOnWorldPosition("b", b) local c = vehicleMatrix:transformPosition(Vector3(minX, maxY, maxZ)) drawTextOnWorldPosition("c", c) local d = vehicleMatrix:transformPosition(Vector3(maxX, maxY, maxZ)) drawTextOnWorldPosition("d", d) dxDrawLine3D(c, d, 0xFFFF0000, 1.0) dxDrawLine3D(a, b, 0xFFFF0000, 1.0) dxDrawLine3D(c, a, 0xFFFF0000, 1.0) dxDrawLine3D(d, b, 0xFFFF0000, 1.0) dxDrawLine3D(a, d, 0xFFFF0000, 1.0) dxDrawLine3D(b, c, 0xFFFF0000, 1.0) function drawTextOnWorldPosition(text, vecPosition) local x, y = getScreenFromWorldPosition(vecPosition) if x and y then dxDrawText(text, x, y, nil, nil, 0xFFFFFFFF, 2.0, "default-bold", "center", "center") end end You didn't tell me what you want to do, my previous code segment only solved the question in the first post. Edited February 27, 2017 by Necktrox Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now