Author Topic: Question of Ray Collision  (Read 162 times)

Jason Huang   «   on: May 31, 2012, 12:01:36 PM »
Hi, All.
   I created a lens flare effect using 2d bitmap. For the sun, it is hard to test if there is a object between  the camera and the sun. I tried to use ray collision. But I failed...
Could anyone give me a small example for this please? 
 
Best

Ivan Vodopiviz   «   Reply #1 on: May 31, 2012, 04:14:48 PM »
Hi,

You can see how to use rayCollision in the YellowPlanet tutorial. You can find it here. I know it's long, but if you search for "Creating a ray using the new RayCollision Method" you'll find the code. It's quite simple.

Cheers,

Jason Huang   «   Reply #2 on: May 31, 2012, 05:35:02 PM »
hi, Ivan
Thank you for your quick answer.  I found out ray collision is not probably suit for my case.
Here is what I need to solve:
 I have a sun, a forest and a player. To enhance the lighting effect, I built a fake lens flare using 8 bitmaps. It works fine, it is able to do this trick if the sun is in the stage range. 
Now, I need to do even more, that those trees would cover the fake light. So when the camera is facing the sun, if there would be something between them, the fake lens flare will change or disappear. So the major problem is how can I detect if there is something between sun and camera if the camera is facing to sun?

Jason Huang   «   Reply #3 on: June 01, 2012, 07:57:17 AM »
Haha, I finally get what I want, by subsctracting the cameraPos and Sunpos to get a correct direction that the ray may go through.
The poblem is that I have to use scene to be collide with. The performence would be too bad once the scene get more complex. Here are some questions:
 (1) How can I detect the sun has a corner showed up? Currently, I used the pivot center to detect if sun has been covered by an object, therefore, these fake volumic lights wont showed up until the pivot has not been colliding. I think I need something simillar to inView property of Pivot3D.
(2) For my understanding in mathematics, vector derection is calculated by subctracting SunPos with cameraPos. But in may case, I gotta use the oppsite way to get it work. Why?
(3) Can I do anything instead of directly collide with the scene to enhance the performence?

Cheers

Ivan Vodopiviz   «   Reply #4 on: June 05, 2012, 11:25:44 AM »
Hi Jason, sorry for the delay.

Truth be told, the best and more reliable way is to use raycollision. But yes, if you're targetting mobile or really big scenes, performance can be a problem. Now, most alternatives won't be much faster, so I'd suggest you just use raycollision, but avoid checking it every frame. You can check collisions every five frames for example, that will reduce CPU usage a lot and won't give you many delay problems.

By the way, are you really concerned about performance? Is this for mobile or are your scenes really that big?

Regards,

Jason Huang   «   Reply #5 on: June 05, 2012, 03:55:00 PM »
Thanks Ivan,
My scene has a ton of cloned trees....so I call them forest:) the original tree has more than 40000 polys... The reason of that is the alpha sorting dose not work in a complex tree...so every leaf I have to use real mesh. How do u suggest ?