[Webinar] Streamline your web hosting managementRegister Today


C Function to Calculate Surface Normals

Posted on 2003-03-19
Medium Priority
Last Modified: 2013-12-26

I'm trying to write a function in C++ to calculate a surface normal and return the normal as a 3 element array.  The function takes 9 arguments- the coords of the point at which the normal is to be calculated and the coords of two points on the vectors of the sides.  I have the maths to do this, the trouble is I can't find a neat way to return the results...  I just need a 3 element array!

Question by:mrpink123

Accepted Solution

TGGC earned 200 total points
ID: 8168519
a fast way

void cross( float x1, float y1, float z1,
            float x2, float y2, float z2,
            float x3, float y3, float z3,
            float& x, float& y, float& z );
  x= ...
  y= ...
  z= ...

a nice way (i would prefer this!)

struct Vec3
  float x;
  float y;
  float z;

void cross( Vec3 V1, Vec3 V2, Vec3 V3, Vec3& Result);
  Result.x= V2.y - V1.y * V3.z -...
  Result.y= ...
  Result.z= ...

Expert Comment

ID: 8172542

D3DXVECTOR3* myFunction()

D3DXVECTOR3* vecs = new D3DXVECTOR3[3];

  return vecs;

Or ?

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Suggested Courses

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question