Jump to content
  • Advertisement
Sign in to follow this  
HermanssoN

D3DXVec4Cross function

This topic is 3692 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

Hello I', writing my own math library. I wrote my own cross product function for 4D vectors, like this: ECVector4 ECVector4::Cross( const ECVector4& CrossVec )const { Real32 X = (m_X * CrossVec.m_Y - m_Y*CrossVec.m_X) + (m_X * CrossVec.m_Z - m_Z*CrossVec.m_X) + (m_Y * CrossVec.m_Z - m_Z*CrossVec.m_Y); Real32 Y = (m_Z * CrossVec.m_Y - m_Y*CrossVec.m_Z) + (m_Y * CrossVec.m_W - m_W*CrossVec.m_Y) + (m_Z * CrossVec.m_W - m_W*CrossVec.m_Z); Real32 Z = (m_X * CrossVec.m_Z - m_Z*CrossVec.m_X) + (m_W * CrossVec.m_X - m_X*CrossVec.m_W) + (m_Z * CrossVec.m_W - m_W*CrossVec.m_Z); Real32 W = (m_Y * CrossVec.m_X - m_X*CrossVec.m_Y) + (m_W * CrossVec.m_X - m_X*CrossVec.m_W) + (m_W * CrossVec.m_Y - m_Y*CrossVec.m_W); return ECVector4( X, Y, Z, W ); } when I was about to find out if my calculations where correct using the D3DXVec4Cross function i found out that it had 3 vectors as in parameters. Isn't cross product just used like V1 cross V2?? I admit that my knowledge about 4D vectors is very limited.

Share this post


Link to post
Share on other sites
Advertisement
They are 3 points, from which two vectors are created with which the cross product is calculated.

Share this post


Link to post
Share on other sites
For a cross product in n dimensions you need (n-1) vectors. For a 2D cross product you need 1 vector. For a 3D cross product, 2 vectors. In 4D, 3 vectors, and so on. A cross product finds you a vector that is perpendicular to all the other vectors, that's why 2 vectors are not enough in 4D. The cross product is calculated by taking the sub-determinants for the first column of a matrix where the first column is the vector you're looking for and the other columns are the given vectors.

Share this post


Link to post
Share on other sites
Thnx.. I had to to a litle googleing how to get the sub determinants but here is the result:

void
ECVector4::Cross( const ECVector4& CrossVec1, const ECVector4& CrossVec2, const ECVector4& CrossVec3 )
{

//Create som determinants using CrossVec2 & CrossVec3
Real32 XY = CrossVec2.m_X*CrossVec3.m_Y - CrossVec3.m_X*CrossVec2.m_Y;
Real32 XZ = CrossVec2.m_X*CrossVec3.m_Z - CrossVec3.m_X*CrossVec2.m_Z;
Real32 XW = CrossVec2.m_X*CrossVec3.m_W - CrossVec3.m_X*CrossVec2.m_W;
Real32 YZ = CrossVec2.m_Y*CrossVec3.m_Z - CrossVec3.m_Y*CrossVec2.m_Z;
Real32 YW = CrossVec2.m_Y*CrossVec3.m_W - CrossVec3.m_Y*CrossVec2.m_W;
Real32 ZW = CrossVec2.m_Z*CrossVec3.m_W - CrossVec3.m_Z*CrossVec2.m_W;

m_X = CrossVec1.m_Y * ZW - CrossVec1.m_Z * YW + CrossVec1.m_W * YZ;
m_Y = CrossVec1.m_Z * XW - CrossVec1.m_X * ZW - CrossVec1.m_W * XZ;
m_Z = CrossVec1.m_X* YW - CrossVec1.m_Y * XW + CrossVec1.m_W * XY;
m_W = CrossVec1.m_Y * XZ - CrossVec1.m_X * YZ - CrossVec1.m_Z * XY;

}

nice doing codeing with you ^^

Share this post


Link to post
Share on other sites
Quote:
Original post by 84r
For a cross product in n dimensions you need (n-1) vectors.


The crossproduct, by definition, is a binary operation. It is only defined in three and seven dimensions.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!