我有一点麻烦白衣试图比较旋转的2D四边形坐标旋转x和y坐标。我试图确定鼠标是否在四边形内被点击。比较旋转的坐标
1)腐的是这个类的对象:(注:操作者< <重载为使用旋转COORDS FUNC的)
class Vector{
private:
std::vector <float> Vertices;
public:
Vector(float, float);
float GetVertice(unsigned int);
void SetVertice(unsigned int, float);
std::vector<float> operator <<(double);
};
Vector::Vector(float X,float Y){
Vertices.push_back(X);
Vertices.push_back(Y);
}
float Vector::GetVertice(unsigned int Index){
return Vertices.at(Index);
}
void Vector::SetVertice(unsigned int Index,float NewVertice){
Vertices.at(Index) = NewVertice;
}
//Return rotated coords:D
std::vector <float> Vector::operator <<(double Angle){
std::vector<float> Temp;
Temp.push_back(Vertices.at(0) * cos(Angle) - Vertices.at(1) * sin(Angle));
Temp.push_back(Vertices.at(0) * sin(Angle) + Vertices.at(1) * cos(Angle));
return Temp;
}
2)比较讨论和坐标的旋转THE NEW VERSION
Vector Rot1(x,y),Rot3(x,y);
double Angle;
std::vector <float> result1,result3;
Rot3.SetVertice(0,NewQuads.at(Index).GetXpos() + NewQuads.at(Index).GetWidth());
Rot3.SetVertice(1,NewQuads.at(Index).GetYpos() + NewQuads.at(Index).GetHeight());
Angle = NewQuads.at(Index).GetRotation();
result1 = Rot1 << Angle; // Rotate the mouse x and y
result3 = Rot3 << Angle; // Rotate the Quad x and y
//.at(0) = x and .at(1)=y
if(result1.at(0) >= result3.at(0) - NewQuads.at(Index).GetWidth() && result1.at(0) <= result3.at(0) ){
if(result1.at(1) >= result3.at(1) - NewQuads.at(Index).GetHeight() && result1.at(1) <= result3.at(1)){
当我运行这个它完美的作品在0角度,但是当你旋转四,它失败。 和失败我的意思是激活区域似乎只是消失。
am我正确地旋转坐标吗?还是比较? 如果是你会怎么做正确的比较,我试图改变的,如果的,但丝毫任何运气...
编辑 四边形的绘制(在测试之前发生):
void Quad::Render()
{
if(!CheckIfOutOfScreen()){
glPushMatrix();
glLoadIdentity();
glTranslatef(Xpos ,Ypos ,0.f);
glRotatef(Rotation,0.f,0.f,1.f); // same rotation is used for the testing later...
glBegin(GL_QUADS);
glVertex2f(Zwidth,Zheight);
glVertex2f(Width,Zheight);
glVertex2f(Width,Height);
glVertex2f(Zwidth,Height);
glEnd();
if(State != NOT_ACTIVE)
RenderShapeTools();
glPopMatrix();
}
}
basicly我想要测试是否点击鼠标在这四里: Image
为什么“Rot1 <<角度”?你不打算在那里转移,是吗? – Philip
不,我只是超载它得到旋转coords(问题提出的旋转func),我quess我可以选择不同的运营商,使其更清晰:) – ceri
我不清楚你在做什么类但你不能旋转的宽度和高度 - 你应该旋转一个点,所以你应该设置顶点(假设初始四舍五入不旋转)GetXPos +宽度,GetYPos +高度 –