Inside object?
Blitz3D Forums/Blitz3D Programming/Inside object?
| ||
Hi all, I was looking into how I could play some music for each "zone" my character is in. I found this old code called CreateOBB. I've managed to modify it to not look horrible. Problem is, I think the math is off... The player won't stay green for the WHOLE inside of the object... Here's the code: Any help is greatly appreciated! :) Thanks! :) |
| ||
Bump :) |
| ||
Can I ask, did the code work before you modified it? |
| ||
Yes. Alls I did was reposition the camera and the objects and gave the player a correct camera :) |
| ||
What is it that doesn't work? The player moves around, with X and Z changing. When either value reaches +12 or -12 the color changes. Is that not the expected behavior based onGlobal G_obb = CreateOBB( 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 12.0, 12.0, 12.0 ) |
| ||
Well, when u look REAL closely at the player model inside of the cube model that has OBB, does it not look as though the player turns red in areas it should NOT turn red? |
| ||
. Last edited 2012 |
| ||
? |
| ||
It works fine: change the CreateOBB() function to: Function CreateOBB( x#, y#, z#, pitch#, yaw#, roll#, width#, height#, depth#, parent = 0 ) ; Creates an OBB and returns its entity handle. Note that an OBB is just a pivot entity. ; The position, rotation, and size of the OBB will be set using the supplied values. Note that these values are initially applied in global space, but will be relative to the parent space after the obb has been created. ; An optional parent entity can be specified. The obb will be attached to this parent, and its position, rotation, and size will update when the position, rotation, and\or size of the parent changes. Local obb_pivot = CreateCube( parent ) FlipMesh obb_pivot PositionEntity obb_pivot, x#, y#, z#, True RotateEntity obb_pivot, pitch#, yaw#, roll#, True ScaleEntity obb_pivot, width#, height#, depth#, True Return obb_pivot End Function That will show you a visual representation of what the OBB looks like. Did you ScaleEntity the G_display_cube: ScaleMesh G_display_cube, 12.0, 12.0, 12.0 Last edited 2012 |
| ||
![]() |
| ||
yes i did Ross. and leon drake, go bother someone else. i am ignoring ALL idiot ppl in ALL parts of this forum. |
| ||
Well, that's your problem then. That's not the bounding box, but a representation of it. Last edited 2012 |
| ||
i did as u said and replaced the function. its working but only til my object is HALF out of the G_display_cube |
| ||
It's only a maths check using the centrepoint of the object. Read the function description: Function PointInOBB( obb_pivot, x#, y#, z# ) ; Tests if the specified x, y, z, point is inside the space of the specified OBB pivot entity. ; If so, a true result is returned. If not, a false result is returned. If it's a cube, you could test all 8 corners of the cube and if all of them are outside, then turn it red. |
| ||
How do I get all 8 corners? |
| ||
To get the corners of a cube there are a number of ways of doing so. One way would be to loop through the vertices and check against the x/y/z coordinates of each vertex. Another way would be to use the tformpoint commands in combination with your knowledge of the basic properties of a cube. |
| ||
The original function can get the 8 corners. Even though the pivot is scaled in world coordinates, its local scale is always [1.0,1.0,1.0]. Since it compares the 3 axes, it's viewing pivot's scale as a cube and comparing with that. That's why Stevie G's PointInOBB function compares the position of the point relative to [-1.0, 1.0] values, because locally, for the pivot, that's what its scale is: normalized. He used the TFormPoint command to transform the XYZ coordinates of the point in question from world-space to zone-space so the comparison is easier to make: the zone (a box-like shape) can have any orientation in world-space the user wants, but when the function looks at it locally, the orientation is always identity\null, with the point in question being the one flying around, potentially inside\outside the zone. Last edited 2012 |
| ||
Ok. its still doing that object is half in and half out thing... Here's the code: |
| ||
You need to check the corners of the box. If you know the centre point and the width,height and depth of the box, it's just a case of halving the width depth and height to find the corners of the box. Test each of these points, as I said last time, and if all are inside, then it remains green. eg centre_x = 3 centre_y = 3 width# = 1 height# = 1 depth# = 1 corner_1_x = centre_x -(width/2) corner_1_y = centre_y -(height/2) corner_1_z = centre_z -(depth/2) |
| ||
ok. how do u get the center x and center y? |
| ||
EntityX()... EntityY()... EntityZ(). If your going by your created cube. |