The problem seems to be corners[] being set wrong. It is supposed to be the corners of a rectangle, but for some akward reason the X coordinates almost won't change (when adding ca).
Target1 and Target2 are the middle points on two opposite edges of the rectangle. Width is the length of those two edges.
The length of the other two edges equals the distance between Target1 and Target2 (obviously, I hope).
Can someone point out what I'm wrong here?
Code: Select all
IPlaneSceneNode* createRectSceneNode(vector3df Target1, vector3df Target2, float width, SColor Colors[4])
{
// Deltas
float dx = Target1.X - Target2.X;
float dy = Target1.Y - Target2.Y;
double angle = atan2(dy,dx);
angle += M_PI/2;
cout << "Angle is: " << (angle * RAD_TO_DEG) << endl;
double ca = cos(angle) * width;
double sa = sin(angle) * width;
cout << "ca = " << ca << "\nsa = " << sa << "\n";
vector3df corners [4];
corners[0] = Target1;
corners[0].X += ca;
corners[0].Z += sa;
corners[1] = Target2;
corners[1].X += ca;
corners[1].Z += sa;
corners[2] = Target2;
corners[2].X -= ca;
corners[2].Z -= sa;
corners[3] = Target1;
corners[3].X -= ca;
corners[3].Z -= sa;
IPlaneSceneNode* node = new IPlaneSceneNode(corners, Colors);
node->drop();
return node;
}
Code: Select all
Correct rect: (It only makes this in some few situations)
------
| |
| |
| |
| |
| |
------
Bad rect: (It keeps making this...)
|\
| \
| \
| |
| |
| |
| |
\ |
\ |
\|