Jump to content
  • Advertisement
Sign in to follow this  
Rajveer

Simple collision detection

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi guys. does anybody have a link to an article (or advice) for a relevant collision detection method for my problem below? ive read alot about collision detection but the majority was for two moving objects e.t.c. i have an object, and i have a (non-flat) level. i need the object to be able to see what angle the ground beneath it is at, so it can be rotated to match the ground (i.e. edit its local axis). cheers

Share this post


Link to post
Share on other sites
Advertisement
One solution is to fire a ray downward from the object, and record the normal of the intersected surface. Then, apply a relative rotation to align the up vector of the object with this normal. Presumably you would also want to adjust the position of the object to keep it a fixed distance above the surface.

Also, if the surface is discontinuous you will probably want to interpolate to the new orientation (rather than snapping to it directly).

Share this post


Link to post
Share on other sites
great, exactly the type of thing i was thinking :)

so this would mean for every polygon i would store its associated normal? i think im up to speed with code for ray intersection. when you say "interpolate to the new orientation", do you mean keeping the orientation that the object had before it came to the "gap"?

one more thing, if im to adjust the objects local y-axis to the surfaces, what would you suggest the best method for this?

Share this post


Link to post
Share on other sites
Quote:
Original post by Rajveer
great, exactly the type of thing i was thinking :)

so this would mean for every polygon i would store its associated normal?
You could store the normals, or you could calculate them on the fly - whichever you prefer.
Quote:
i think im up to speed with code for ray intersection. when you say "interpolate to the new orientation", do you mean keeping the orientation that the object had before it came to the "gap"?
When your object comes to a discontinuity (i.e. an edge where two polygons meet), if you don't interpolate, the object will 'snap' to the new orientation, which won't look natural. Basically, instead of rotating 'all the way' to alignment with the surface normal, just rotate part of the way.
Quote:
one more thing, if im to adjust the objects local y-axis to the surfaces, what would you suggest the best method for this?
Find the 'shortest' axis-angle rotation that will rotate the up vector onto the surface normal (using the dot and cross products) and apply it (or part of it) to the object's orientation.

Share this post


Link to post
Share on other sites
interpolate to the new orientation means to smoothly adjust the angle to match the new one.
calcualting the normal on creation usefull for a wide array of subjects , so i would advice it.
if this mesh is loaded from a file , it should have all the normals calculated.
you can calculate the angle between that surface , and the horizontal surface , by
calcualting the angle between the two normals,then rotate your object (smoothly) to that angle

Share this post


Link to post
Share on other sites
great, cheers for the help guys. ill try to start the coding for it tomorrow morning (nearly 4am!). im pretty sure ill need to post again because its the first time im doing this and (for me) its pretty complex. either way ill post how its going :)

Share this post


Link to post
Share on other sites
one question: when calculating the polygon that the ray from the objects ship intersects, how would i do this? as in would i intersect with the normal to the whole plane, or would i limit to the area of the polygon? if the former, would this not allow the ship to always intersect with it (except for when parallel and upside down) or would i calculate the closest plane?

Share this post


Link to post
Share on other sites
If your using DirectX check out D3DXIntersect not sure about an OpenGl alternative but im sure there is one.

Share this post


Link to post
Share on other sites
the problem is that im using an implementation of opengl for the nintendo ds, which doesnt have code for collisions.

so would i define the plane (by using the normal and a random point in the plane) and then limit the plane to the coordinates of the polygon?

[Edited by - Rajveer on August 13, 2006 6:10:17 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by treeway
If your using DirectX check out D3DXIntersect not sure about an OpenGl alternative but im sure there is one.
There is not. OpenGL and DirectX are not directly comparable; DirectX is a collection of APIs, while OpenGL is exclusively (more or less) a graphics API.

@The OP: You'll need to perform the intersection test yourself. I'd start by googling 'ray triangle intersection', 'raytrace triangle', and similar phrases; you should be able to find an example implementation online somewhere.

The algorithms you're most likely to find online aren't always the most robust, but I'd get things working first and worry about improving performance and/or stability later.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!