Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Raycast perpendicular to object

Author
Message
Madscientist
14
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 11th Feb 2010 01:05
How would I go about raycasing perpendicular to an object? That may seem simple but my problem is more complicated. I have an object (A shell from a gun) that gets rotated and moved all over the place. I need to raycast from that object's top and bottom points. The bottom is already the orgin of the object. Here is what I already have to calculate where that top point would start.

So how would I raycast perpendicular from ShellTopPosX#, ShellTopPosY# and ShellTopPosZ#?

If it hasn't exploded yet, I haven't touched it.
Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 11th Feb 2010 08:39 Edited at: 11th Feb 2010 23:52
So let me get this straight - You have a bullet shell object. It's center of rotation is at <0,0,0>, and it's rotated some arbitrary amount. right?


As you can see here:

your positioning is off. Trig+euler angles math needs ta be done.

So... Normals vectors and rotation matrices is how I'd do it.

Say "forward" is defined as the object with a direction <0,0,1> (1 forward on the z axis). Then say "perpendicular" is any direction on the unit circle on the xy plane. Basically, This:





HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 11th Feb 2010 11:20
@Neuro Fuzzy

Can I use your code to report and error with 7.5 beta 4, as it seem that rotate x matrix4 command are broken.

cheers

Dark Physics makes any hot drink go cold.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 11th Feb 2010 15:02
You already have a direction that the shell is traveling. Simply use that vector; you don't need any perpendicular vector. If it's falling straight down, the vector would be close to 0,-1,0. At any point on it's curved trajectory, you would know the direction vector--use it.

Furthermore, you only NEED to be specific when the shell is moving slowly. Use a radius for collisions at high speeds and use the two point method as it's coming to a rest on the ground.

The fastest code is the code never written.
Madscientist
14
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 11th Feb 2010 21:35 Edited at: 11th Feb 2010 21:44
@Neuro Fuzzy
Could you please explain you code.
Also, I need the position of that sphere only perpendicular on the X and Y axis not the Z axis

If it hasn't exploded yet, I haven't touched it.
Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 12th Feb 2010 00:03
Rofl, I just realized I posted a bunch of other unrelated code underneath that. I was programming something else and just seperated the two programs with a remstart, but apparently I copied everything

If you don't know anything about matrices and vector math, then it'd be too repetitive to explain the code. info about them is all over the web. If you don't want to give yourself a math lecture, then I would just accept the code for what it is . If you already know what rotation matrices and stuff are...

"*0.0174532925" converts the 360 degree angles to radians (used by the matrix4 commands)
rotate x matrix4 builds the rotation matrix rotated on the x axis
rotation y and z do the same, but around their respective axes
multiply matrix "args matrix4, A, B" actually multiplies B*A so that's why the numbers are switched around (I'm pretty sure... though I could be being a retard about that)
since all the points perpendicular to <0,0,1> lie on the xy plain, I just make the vector <sin(ang),cos(ang),0>
rotating <0,0,1> and <sin(ang),cos(ang,0> by the same matrix leaves the two points with the same relative position.

Also... I don't really think this is what you want to do...

I'm guessing you want to detect when the bullet shell is close to a wall or something, then delete it? I would think bounding box collision would be a lot better. If you're worried about speed updating a bunch of different objects, a good solution would be to create a single collision sphere, and in a for loop or something, move that to all the bullet shell's positions and check for collision that way.


Madscientist
14
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 12th Feb 2010 00:18
I want to detect if the shell is parallel to the ground or not. Then rotate it accordingly. I just need help with the math of finding the position of the top point and the two points that are perpendicular to the object.
(I attached a pic to show what I mean)

If it hasn't exploded yet, I haven't touched it.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-04-25 01:06:02
Your offset time is: 2024-04-25 01:06:02