私のプログラムには、ヒット テストを行う必要のある単純な四角形があります。私は openFrameworks を使用していますが、ここでの問題は OpenGL のトピックにも関連していると思います。
public class Shape : public class ofNode {
Shape() {
container.setFromCenter(getPosition(), 200,100);
setPosition(ofVec3f(365, 50, 0)); //set the position of the node
lookAt(ofVec3f(0,0,0));
}
virtual void draw() {
ofRect(container); //the 200/100 rectangle will be drawn as per the container position and dimensions
}
ofVec3f getTopLeft() const {
return getTopLeft() * ofNode::getGlobalTransformMatrix();
}
ofVec3f getTopRight() const {} //similar - getTopRight from container and multiply
ofVec3f getBottomLeft() const {} //similar
ofVec3f getBottomRight() const {} //similar
bool hitTest(int tx, int ty) {
// return true if mouse pointer is inside four vertices - hit test logic working fine
}
private:
ofRectagle container;
};
ここでの問題は、プログラム内で形状を回転および変換していることです。
void draw() {
ofPushMatrix();
ofTranslate(600,300,0);
ofRotateY(rotate);
shape->draw();
ofCircle(shape->getTopLeft(), 10); //circle is drawn at the rectangle top left vertex on the screen but the coordinates while rotating and drawing do not change (as seen on cout)
ofCircle(shape->getTopRight(), 10); //similar
ofCircle(shape->getBottomLeft(), 10); //similar
ofCircle(shape->getBottomRight(), 10); //similar
ofPopmatrix();
}
上記の関数のように回転が変更された場合draw
、ポイントは変更されません。したがって、ヒット テストでマウスが内部にあるかどうかを判断するための適切な 4 つの頂点がありません。ヒット テストのマウス位置に対してチェックできる画面内のポイントの位置を取得するにはどうすればよいですか?