Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Ray tracing problem; *changed the name when changing the subject*
Topic Started: Apr 18 2009, 03:04 PM (887 Views)
Ogeon
Member Avatar
Member
[ *  * ]
Hello 3D-friends!

I have tried to find this out by both searching the forum and reading the documentation: how do I get the direction of the normal?
I know how to get the x, y, z of the normal, but not the longitude and latitude. The reason is that I want to make a ray shoot out from the camera and be randomly reflected by the face of the object and move on to an other object and so on...

There may be a simple explanation, but I can't find it.
Do you expect a signature? Forget it!
Offline Profile Quote Post Goto Top
 
Gandalf20000
Member Avatar
Geek
[ *  *  *  *  *  * ]
In the manual, look up these two functions:

CalculateVectorLongitude();
CalculateVectorLatitude();
Offline Profile Quote Post Goto Top
 
skarik
Member Avatar
kitten eating scum
[ *  *  *  *  *  * ]
Ogeon
Apr 18 2009, 03:04 PM
The reason is that I want to make a ray shoot out from the camera and be randomly reflected by the face of the object and move on to an other object and so on...
My goodness, that's awesome. Like infinite combine balls in a room.
Blog|EHS
Offline Profile Quote Post Goto Top
 
Ogeon
Member Avatar
Member
[ *  * ]
@Gandalf20000: Thanks. Even if one reads the manual, one can allways miss things... Now let's see if I will manage to do this.

@skarik: Allmost what I thougt, but at the same time not. I'm trying to make a path tracer for GM. I know it will be slower than a "real" one, but it's cool to say that it's possible and it's just for fun.
Do you expect a signature? Forget it!
Offline Profile Quote Post Goto Top
 
Bazza
Member Avatar
Forum God
[ *  *  *  *  *  * ]
er do you want it to be an accurate bounce or just an random bounce to infinity?
My instinct is to hide in this barrel, like the wily fish.
Offline Profile Quote Post Goto Top
 
Ogeon
Member Avatar
Member
[ *  * ]
bazza games
Apr 19 2009, 12:21 PM
er do you want it to be an accurate bounce or just an random bounce to infinity?
I want it to be a "difuse" bounce, so I need the normal to make the ray go in a random direction from the surface. Then it will check if it hits an other object and so on until it reaches max depth or hit nothing.

I would like to know if ray tracing work with the plane primitives or just models.
Do you expect a signature? Forget it!
Offline Profile Quote Post Goto Top
 
Bazza
Member Avatar
Forum God
[ *  *  *  *  *  * ]
to my knowledge it works with both primitives and models
My instinct is to hide in this barrel, like the wily fish.
Offline Profile Quote Post Goto Top
 
Ogeon
Member Avatar
Member
[ *  * ]
The reason I ask is that it doesn't seem to find a hit. I made it return white if it hits an object and the resulting image is all black. I even tried to make it respond by ending the game when it detected a hit, but no...
Do you expect a signature? Forget it!
Offline Profile Quote Post Goto Top
 
Ogeon
Member Avatar
Member
[ *  * ]
(I changed the name of the topic to make it fit the subject)

If i run the game and check the variables it allways reurn 0 on the x, y and z of the normals. That's reasonable when it doesn't find any collition at all. May it be because the function ScreenCoordToVector(n,xx,yy,camera) return a vector with id=0, but with x, y and z at (0, 0, 0) and longitude=0 and latitude=0?

Does anyone know why?
Do you expect a signature? Forget it!
Offline Profile Quote Post Goto Top
 
Bazza
Member Avatar
Forum God
[ *  *  *  *  *  * ]
oh so your not using CheckRayIntersection(object id,x,y,z,rotx,roty,room index)
but ScreenCoordToVector(); may i ask what your passing for the xx and yy vars?
My instinct is to hide in this barrel, like the wily fish.
Offline Profile Quote Post Goto Top
 
Ogeon
Member Avatar
Member
[ *  * ]
I think I might have got it all wrong (appearently). Here is my code for checking from camera:
Code:
 

n=ScreenCoordToVector(n,xx,yy,camera);
NormalizeVector(n);
raylo=CalculateVectorLongitude(n);
rayla=CalculateVectorLatitude(n);
rayx=GetVector(n,1);
rayy=GetVector(n,2);
rayz=GetVector(n,3);


dist=CheckRayIntersection(all,camera.x,camera.y,camera.z,raylo,rayla,0);
if dist<100000
{
cr+=1; //adding colors to pixel
cg+=1;
cb+=1;
l+=1;//adding light

GetRayTracingNormal(n);
//getting the values for normal
rayx=GetVector(n,1);
rayy=GetVector(n,2);
rayz=GetVector(n,3);
raylo=CalculateVectorLongitude(n);
rayla=CalculateVectorLatitude(n);

succes=1;
}
else
{
succes=0;
}


I have never used ray tracing before. I hope that you or someone else can help me.
Do you expect a signature? Forget it!
Offline Profile Quote Post Goto Top
 
Bazza
Member Avatar
Forum God
[ *  *  *  *  *  * ]
whats the first call to ScreenCoord to vector supposed to accomplish
My instinct is to hide in this barrel, like the wily fish.
Offline Profile Quote Post Goto Top
 
skarik
Member Avatar
kitten eating scum
[ *  *  *  *  *  * ]
Your code and maths are fine, but your logic is not. I don't have any logic to give at the moment, so I can't help.
Blog|EHS
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
A couple of mistakes here:
Code:
 
n=ScreenCoordToVector(n,xx,yy,camera);
A VectorID parameter is either -1 (when you wish to create a new vector and have its id returned), or the id of a previously created vector, which is then filled with new data.
So let's say you already initialized vector n in some Create Event like this:
Code:
 
n=CreateVector(-1,0,0,0);
then you should write:
Code:
 
ScreenCoordToVector(n,xx,yy,camera.number);
(As you see, I also added ".number" to "camera", since that's what the CameraIndex parameter needs to be.)
After normalizing that vector and getting its direction, you can immediately trace a ray from the camera (no need to get the components of n).
And then you are forgetting something important: you need to scale n by dist, and add its components to the camera coordinates. This will give you the location of the point where the ray has intersected your level.

Then you can trace a ray from that location, in the direction of the normal vector (you don't need its components, only longitude & latitude), and repeat the above procedure. Ad nauseam :P .

Do the ray tracing in the direction of a normal recursively (in a script that calls itself) after the first trace from the camera. The recursion stops when the ray intersects nothing.

I may post some code later if you need it.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
ashrat3000
Member Avatar
u3d raytracer
[ *  *  *  *  *  * ]
A couple things you need to double check:

Make sure that n in ScreenCoordToVector(..) has been initialized as a vector with
n = CreateVector(...)


Also, make sure all your models have SetObjectSoliditiy(1,0) called.


As for the logic, I dont really see much of a problem...
hmm..


EDIT: damn, mystery beat me to it.

Edited by ashrat3000, Apr 19 2009, 09:36 PM.
그대를 사랑해


Offline Profile Quote Post Goto Top
 
Go to Next Page
« Previous Topic · Questions about Ultimate 3D · Next Topic »
Add Reply