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.

Dark Physics & Dark A.I. & Dark Dynamix / Easier ray cast function (using angles instead of a unit vector)

Author
Message
Trowbee
21
Years of Service
User Offline
Joined: 12th Apr 2003
Location: United Kingdom
Posted: 19th Mar 2007 21:40 Edited at: 20th Mar 2007 10:22
Only recently have I started messing about with the physics commands.

Anyway, I came across phy ray cast all shapes. "Great", I thought, until I found it took vectors instead of angles.
Not a problem, just move the camera 1, take the position, move it back. Not the prettiest method, but it works, and its fast.

Anyway, I seem to have come across a few times (infact, hundreds recently) where manipulating the camera to return vectors does not work - and the program quits complaining I've not provided a unit vector.

So, 3 things.

First:
Anyone reading this, who is unsure what a unit vector is:
A unit vector is just a combined x/y/z distance equal to 1.0 exactly.

Second:
I wrote a little bit of error checking, to fix this. Its only 6 lines, but will handle the errors you might otherwise get.
root, xvec, yvec and zvec are all floats (VERY important).

You can then adapt this to your own code just before you ray cast.

Third, and finally:
I got annoyed having to provide vectors, so to make it easier for myself (and others), here is the function I use to supply angles instead of vectors



It may need adapting to suit other situations, but thats what the community is for, right?
I don't really know what the return value of the ray cast command is, but I store and return it in case it is used elsewhere in a program.

I repositioned and rerotated the camera in this, since I couldn't get the newxvalue, newyvalue and newzvalue commands to return the right coordinate in 3D space first time around. If anyone else can, it might prove faster to use those than manipulating the camera.
And just so it doesn't mess up other programs, I move the camera back to where it was

EDIT 1: Fixed the ray cast call command, cheers codger
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 19th Mar 2007 21:53
I admire the angle based solution although note that using vectors is computationally much more efficient than using angles.

Incidentally, if you really want to normalise a 3 dimension vector its generally better to avoid the sqrt command, which is slow. This code will also do the trick:

null = make vector3(1)
set vector3 1, x#, y#, z#
normalize vector3 1, 1
x# = x vector3(1)
y# = y vector3(1)
z# = z vector3(1)
null = delete vector3(1)

Cheer if you like bears! Cheer if you like jam sandwiches!
"I highly recommend Philip" (Philip)
Trowbee
21
Years of Service
User Offline
Joined: 12th Apr 2003
Location: United Kingdom
Posted: 19th Mar 2007 21:59
haha, it seems you're going around following my posts

True enough the vector is faster. I literally just wrote that function a few minutes prior to posting, didn't think optimisation through.

Still, for people newer to the concept, angles are much easier to work with . Anyway, I'll adapt that to the original code if noone else has beaten me to it later.
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 19th Mar 2007 22:09
I definitely agree that people think more naturally in angles rather than vectors.

I recommend my world famous vector guide as a good intro to anyone who wants to learn about vectors and how to use them in DBPro. Do a search on the forums to find my guide.

Cheer if you like bears! Cheer if you like jam sandwiches!
"I highly recommend Philip" (Philip)
Codger
22
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 20th Mar 2007 02:46
I could not find
Quote: "phy ray cast all objects."
did you mean
phy ray cast all shapes?

System
PIV 2.8 MZ 512 Mem
FX 5600 256 mem
Trowbee
21
Years of Service
User Offline
Joined: 12th Apr 2003
Location: United Kingdom
Posted: 20th Mar 2007 10:22
I believe I did, haha. Correction made.

Cheers

Login to post a reply

Server time is: 2024-11-24 16:22:12
Your offset time is: 2024-11-24 16:22:12