Overload Operator Quick Help!!

Started by
3 comments, last by Broni 21 years, 10 months ago
Hi. I''m currently developing a 3d engine, an i''m working on the collision dectection. For one piece of the test, i need to be able to return 2 points of intersection between a line segment and two planes. I have developed a CPlane and CVector3D class, but i want to be able to return a two CVector3D object from my function
  
CPlane::RayIntersection(CVector3D& vec, CVector3D& vec2,CPlane Plane)
{
.....blah;
//I calulate the dot product and find the points of intersection.

.....blah;
return (points)
  
At the moment I''am able to return one point but how would i return my next point without using "&&"?? Thanks Broni
Advertisement
i don''t know, but maybe you should use reference parameters to the function instead, and let them recieve the points

CPlane::RayIntersection(CVector3D& vec, CVector3D& vec2,CPlane Plane, CVector3D &point1, CVector3D &point2);

I guess you _could_ return an array of some sort, or a struct containing two points, but i can''t see the point of doing that, as you wouldn''t be able to use the return value directly.
AFAIK, there''s no quick and easy way to do it. One way would be to return a vector:

  std::vector <CVector3D> CPlane::RayIntersection (...){  std::vector <CVector3D> local;  //blabla  local.push_back (result1);  local.push_back (result2);  return local;}  


Of course, you should make a typedef for "std::vector <CVector3D>" and use that.

Another would be simply to have two reference parameters:


  void CPlane::RayIntersection (..., CVector3D &result1, CVector3D &result2){  //blabla  result1 = ...;  result2 = ...;}  


I think that for a constant number of results, the latter is preferable stylistically (not to mention performance-wise).

Kippesoep
Thanks to both of you for your quick responses. I like that second method of passing reference parameters. It worked well.

Again Thank you.
You could also return a pair: std:: Pair < CVector3D,CVector3D >


[edited by - archmiffo on June 5, 2002 3:58:52 PM]

This topic is closed to new replies.

Advertisement