DevMaster.net Forums
[[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]]

Go Back   DevMaster.net Forums > Site Discussions > Code & Snapshot Discussion
User Name
Password
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
Old 07-28-2003, 02:41 PM   #1
davepermen
Senior Member
 
davepermen's Avatar
 
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
Default

Code:
float intersectRaySphere(Ray ray,Sphere sphere) { Vec dst = ray.o - sphere.o; Real B = dot(dst,ray.d); Real C = dot(dst,dst) - sphere.r2; Real D = B*B - C; return D > 0 ? - B - sqrt(D) : std::numeric_limits<float>::infinity(); }

i bet there is a typo
___________________________________________
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
davepermen is offline   Reply With Quote
Old 07-28-2003, 02:46 PM   #2
davepermen
Senior Member
 
davepermen's Avatar
 
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
Default

btw, an ARB_fragment_program version of this function is actually used in this pic

here's the ARB_fragment_program implementing a ray-sphere test

Code:
!!ARBfp1.0 #rayTracer Sphere1 TEMP origin; TEMP direction; PARAM sphere = { 0.0,0.0,2.0,1.0 }; TEX origin, fragment.texcoord[0], texture[0], RECT; TEX direction, fragment.texcoord[0], texture[1], RECT; # intersectRaySphere TEMP distance; SUB distance,origin,sphere; # quadricEquation TEMP params; DP3 params.x,distance,direction; DP3 params.y,distance,distance; SUB params.y,params.y,sphere.w; MAD params.z,params.x,params.x,-params.y; KIL params.z; RSQ params.z,params.z; RCP params.z,params.z; ADD params.x,-params.x,-params.z; TEMP point; MAD point,params.x,direction,origin; TEMP normal; SUB normal,point,sphere; DP3 normal.w,normal,normal; RSQ normal.w,normal.w; MUL normal,normal,normal.w; TEMP diffuse; DP3 diffuse,normal,state.light[0].position; PARAM color = { 1.0,0.5,0.25,0 }; MUL result.depth,params.x,0.125; MUL result.color,color,diffuse; END
___________________________________________
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
davepermen is offline   Reply With Quote
Old 07-28-2003, 02:49 PM   #3
Dia Kharrat
DevMaster Staff
 
Join Date: Jan 2003
Posts: 1,201
Default

wow, very nice piece of code. very useful.
Dia Kharrat is offline   Reply With Quote
Old 07-28-2003, 02:54 PM   #4
Noor
Senior Member
 
Join Date: Jan 2003
Location: ON, Canada
Posts: 524
Default

Nice picture. Thank for the Code!
___________________________________________
"What ever happened to happily ever after?"
Noor is offline   Reply With Quote
Old 07-28-2003, 02:55 PM   #5
davepermen
Senior Member
 
davepermen's Avatar
 
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
Default

just be warned, it does only hit the outer hull (or so.., the near one)..

call it glEnable(GL_SPHERE_INSIDE_CULLING_RT);
___________________________________________
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
davepermen is offline   Reply With Quote
Old 07-28-2003, 03:59 PM   #6
donBerto
Senior Member
 
donBerto's Avatar
 
Join Date: Jan 2003
Location: East Coast, USA
Posts: 370
Default

wow... it's so majestic.

[star wars "the force" theme solo on horn plays in my head]

___________________________________________
Imagine.
donBerto is offline   Reply With Quote
Old 07-28-2003, 04:04 PM   #7
davepermen
Senior Member
 
davepermen's Avatar
 
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
Default

hehe, thanks..

the death star never looked that round, did it?
___________________________________________
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
davepermen is offline   Reply With Quote
Old 07-29-2003, 11:11 AM   #8
baldurk
DevMaster Staff
 
baldurk's Avatar
 
Join Date: Jan 2003
Location: Mars
Posts: 1,141
Default

could you resize the pic down? it's painfully large .

however, you do appreciate it's smoothness at this size...
___________________________________________
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.
baldurk is offline   Reply With Quote
Old 07-29-2003, 11:14 AM   #9
davepermen
Senior Member
 
davepermen's Avatar
 
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
Default

i could post the software version.. runs at the same speed as the hw version, but on 320x240
___________________________________________
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
davepermen is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump


All times are GMT -7. The time now is 09:27 AM.


Powered by vBulletin
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.