Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Ray Sphere intersection


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 GameGeezer   Members   -  Reputation: 787

Like
0Likes
Like

Posted 20 November 2012 - 12:48 PM

Using this tutorial:http://wiki.cgsociety.org/index.php/Ray_Sphere_Intersection. I wrote a method to test ray,sphere intersections:
However I'm unsure as to what the direction vector will consist of. It's apparent that the direction vector isn't angles so I'm assuming it's the slope of the line in each direction?

float RaySphere::intersects(Ray* ray){
Vector3f dist = this->position.x_sub(&(ray->startpos));

float a = ray->angle.dotProd(&(ray->angle));
float b = 2 * ray->angle.dotProd(&(ray->startpos));
float c = ray->startpos.dotProd(&(ray->startpos)) - this->radius_squared;

float disk = b * b - 4 * a * c;

//no roots
if(disk <0)
  return -1;

float distsqrt = sqrt(disk);
float q;

if(b < 0)
  q = (-b-distsqrt)/2.0;
else
  q = (-b+distsqrt)/2.0;

float t0 = q / a;
float t1 = c / q;

//if t0 > t1 then swap them.
if(t0 > t1)
{
  float temp = t0;
  t0 = t1;
  t1 = temp;
}
//the ray missed the sphere
if(t1 < 0)
  return -1;
//if t0<0 intersection is at t1
if(t0<0)
  return t1;
//else its at t0
return t0;
}

Edited by GameGeazer, 20 November 2012 - 12:50 PM.


Sponsor:

#2 Bacterius   Crossbones+   -  Reputation: 9298

Like
1Likes
Like

Posted 20 November 2012 - 04:59 PM

The (unit) direction vector describes the direction of the ray, in 3D space. So, yes, in a sense, it does represent the "slope" of the ray in each dimension (normalized so that the total ray length is 1, to simplify calculations).

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS