# Relative position calculation

This topic is 3087 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi!

I'm pretty new to 3D programming, so my problem might be easy for you to solve, but I don't really have any more ideas how I can solve it.

I have a flat boxed object which I move around on a surface (bound to a environment collision). Now I want to add several raytests to the box model to check for collision with the environment.

I have access to the Object-translation (a 3x4 matrix). Now I thought a good idea would be to make ray-based collisiontests on each border of the object (so 8 tests in total)
I calculate these positions using the center of my box object and adding / subtracting length or depth from this position.

e.g.
v3CenterPos(0.0, 0.0, 0.0)
length = 10.0
depth = 5.0

testing positions:v3TopLeft = v3CenterPos.x - (length / 2.0), v3CenterPos.y, v3CenterPos.z - (depth / 2.0)v3TopCenter = v3CenterPos.x, v3CenterPos.y, v3CenterPos.z - (depth / 2.0)v3TopRight = v3CenterPos.x + (length / 2.0), v3CenterPos.y, v3CenterPos.z - (depth / 2.0)v3CenterLeft = v3CenterPos.x - (length / 2.0), v3CenterPos.y, v3CenterPos.zv3CenterRight = v3CenterPos.x + (length / 2.0), v3CenterPos.y, v3CenterPos.zv3BottomLeft = v3CenterPos.x - (length / 2.0), v3CenterPos.y, v3CenterPos.z + (depth / 2.0)v3BottomCenter = v3CenterPos.x, v3CenterPos.y, v3CenterPos.z + (depth / 2.0)v3BottomRight = v3CenterPos.x + (length / 2.0), v3CenterPos.y, v3CenterPos.z + (depth / 2.0)

In the image the red dots are the positions calculated the way described above. This works fine when the box object is not rotated (here is my problem)

How do I calculate the test positions (marked as blue dots in the image) when the object itself is rotated by an unknown angle? (I know this angle should be accessable from the 3x4 matrix, but I don't know how to use it to calculate the proper vector positions.

I hope my writing does make any sence ;)
-Zerd

##### Share on other sites
You can use the matrix to transform the unrotated points and get the rotated points.

Also not sure if you know about this, but there is such thing as "swept shape collision tests".

For instance, instead of having to do multiple ray casts to detect for collisions (which can miss small objects), you can actually do a "swept OBB" test to find what collides with your moving OBB (oriented bounding box).

##### Share on other sites
To echo Atrix256, performing multiple raycasts is rarely (if ever) the best way to perform complex collision queries such as this.

The easiest option overall would probably be to use an existing collision detection or physics library, but if you want to code it yourself, you'll probably want to look into the 'SAT' (separating axis test).

##### Share on other sites

I'd like to finish the raytest-attempt before trying another collision test method, but than you for your tips!!

I allready asumed that I can use the matrix to transform the initial positions to the rotated positions, but I can't figure out how... Would I use the the rotation values of the matrix and perform a multiplication with the initial positions?

Which calculation do I need to perform (and why)?
I read a couple of articles in several books about vector and matrix calculations, but I just can't apply it to my problem.. :(

##### Share on other sites
Quote:
 I'd like to finish the raytest-attempt before trying another collision test method, but than you for your tips!!
This is just my personal opinion, but honestly I wouldn't bother with that.

If the goal is to learn about raycasting, you can easily learn about it in a context in which it's more useful, such as line-of-sight testing or moving-point intersection testing.

For shapes like boxes though, multiple ray intersection tests is just not the way to do it (IMO, at least). Although this depends somewhat on the environment, the test is likely to miss intersections entirely, or to return information that is inaccurate and/or not particular helpful for resolving the intersection.

In any case, this sort of intersection test is largely a solved problem, so there's really no reason not to use the working solutions that already exist.

That's just my view on it though, which you can take or leave.
Quote:
 I allready asumed that I can use the matrix to transform the initial positions to the rotated positions, but I can't figure out how... Would I use the the rotation values of the matrix and perform a multiplication with the initial positions?Which calculation do I need to perform (and why)?I read a couple of articles in several books about vector and matrix calculations, but I just can't apply it to my problem.. :(
Typically you would multiply each local-space point on the box by the transform matrix to yield the corresponding world-space points. The details depend, more or less, on the math library being used (in particular, whether row vectors or column vectors are being used, and how homogenous transforms are handled).

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
A4L
14
5. 5

• 9
• 13
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013662
×