Re : Re : R: Sphere to rectangle

Benjamin Rouveyrol <[email protected]>
Newsgroups gmane.games.devel.algorithms
Message-ID <[email protected]>
Hi Diogo,

You pretty much spotted the problem with http://www.spellcasterstudios.com/sphere_problem.jpg

What I wanted to do is to keep the old direction (ie center of the sphere towards the red dots), but change the vector's magnitude so that the point is on the line made by the camera position and the pink dot.
So you compute first an angle (alpha = asin(R/D) ) on the triangle made by light center, camera position and pink dot.
Then you apply Thales (tan(alpha) = x / D <=> x = D * tan(alpha) )  to get your final point outside the circle, and which is on the pink line. And yes, I computed the right/up vectors the same way you did (with a normalize for Right ;-) )

When I look at my source code, I see that the 2D bounding rectangle checks all the xy coordinates of all the points to get the left/right/top/bottom.
I can't remember why I did that, but I believe this was to solve the problem you're showing.

Ben




________________________________
De : Diogo de Andrade <[email protected]>
À : Game Development Algorithms <[email protected]>; [email protected]
Envoyé le : Ven 8 Janvier 2010, 10 h 51 min 22 s
Objet : Re: [Algorithms] Re :  R:  Sphere to rectangle

 
Hi Benjamin,
 
Your solution almost works for me… 
 
It works when the camera is head on to the center of the sphere:
 
http://www.spellcasterstudios.com/sphere_rect_problem01.jpg
 
But when I turn left or right, I get:
 
http://www.spellcasterstudios.com/sphere_rect_problem02.jpg
http://www.spellcasterstudios.com/sphere_rect_problem03.jpg
 
This might be related to the projection part, I’ll look into it…
What do you mean by: “Up and right vectors based on
the camera and light positions (and the camera Up).”? I’m just accounting for
camera orientation to calculate the up and right vectors… Are you suggesting
something like:
 
View=LightPos-CameraPos
Right=cross(CameraUp,View)
Up=cross(View,Right)
 
?
 
From the more practical standpoint, from what I understand, you’re
applying a scale factor to the radius to account for distance… How did you came
about this formula?
 
You didn’t happen to need something similar for spotlights/cones?
 
Thanks,
Diogo
 
 
From:Benjamin Rouveyrol
[mailto:[email protected]] 
Sent: sexta-feira, 8 de Janeiro de 2010 15:03
To: Game Development Algorithms; [email protected]
Subject: [Algorithms] Re : R: Sphere to rectangle
 
Hi,

The way I solved this (but a bit math heavy):
If R is the light Radius and D the distance between the camera and the light:
NewR = D *
tan(asin(R/D))

Then you compute Up and right vectors based on the camera and light positions
(and the camera Up).
You end up with 4 corners: LightCenter
+|- Up * NewR  +|- Right * NewR


You can project them and this should give you your bounding rectangle.
If someone has a simpler solution, I'd be most interested ^_^

Ben
 

________________________________
 
De
:Diogo de Andrade <[email protected]>
À : [email protected]; Game Development Algorithms
<[email protected]>
Envoyé le : Ven 8 Janvier 2010, 9 h 28 min 54 s
Objet : Re: [Algorithms] R: Sphere to rectangle

Hi!

That's basically what I'm trying to do with the "wrong" solution,
although I don't tell it like that...
It was a good thought... I had to think about it for 2 mins before I understood
that was exactly what I was trying to do...

Visually, you can see the problem at http://www.spellcasterstudios.com/sphere_problem.jpg

With your solution (and my initial one), I'd get the red points (and their
projection, the yellow line), which is smaller than the correct solution (the
purple points/projection), which has the correct size...

Thanks!

Diogo


-----Original Message-----
From: [email protected] [mailto:[email protected]] 
Sent: sexta-feira, 8 de Janeiro de 2010 13:54
To: [email protected]
Subject: [Algorithms] R: Sphere to rectangle

----Messaggio originale----
Da: [email protected]
Data: 08/01/2010 13.45

> Hi all…
>  
> I’ve been wrestling with a problem for some days now, and I 
> honestly can’t seem to figure an elegant solution…
>  
> I want to find the rectangle that bounds a omni light source, 
> so the problem is: given a sphere with center C=(x0,y0,z0) and radius 
RADIUS, what is the bounding rectangle rect=(rx1,ry1,rx2,ry2) on screen?

Ok, I read this ML only for educational purpose, so...well, I'm sure I will 
suggest the wrong solution :-D

Arent'you simply trying to do screen-aligned billboarding?
I mean...the bounding rectangle around a sphere of a given radius, on 
screen...is not always the same rectangle simply billboarded?



------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
GDAlgorithms-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list


------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
GDAlgorithms-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev

_______________________________________________
GDAlgorithms-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.