Archived

This topic is now archived and is closed to further replies.

Overload Operator Quick Help!!

This topic is 5672 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
Thanks to both of you for your quick responses. I like that second method of passing reference parameters. It worked well.

Again Thank you.

Share this post


Link to post
Share on other sites