私の LWJGL は、マウスとテクスチャのペイントに対して異なる座標系を持っているように見えると言う以外に、これを拡張する方法がよくわかりません。テクスチャは Java2D の通常の方法で (0, 0) を左上隅に置き、マウスは原点を左下隅に置くというより賢明な方法を使用しているようです。私は自分のコードをたくさんチェックしましたが、コードを読んだ場所と使用した場所の間で値を変更するものは何も見当たりません。それはループのために私を投げました、そして私はそれを完全に理解することができません.
皆さんが見られるように、マウス入力とテクスチャ ペインティングに関連するすべてのコードを投稿します。
private static void pollHelpers()
{
while(Mouse.next())
{
InputHelper.acceptMouseInput(Mouse.getEventButton(),
Mouse.getEventX(), Mouse.getEventY());
}
while (Keyboard.next()) {
if (Keyboard.getEventKeyState()) {
InputHelper.acceptKeyboardInput(Keyboard.getEventKey(), true);
} else {
InputHelper.acceptKeyboardInput(Keyboard.getEventKey(), false);
}
}
}
public static void acceptMouseInput(int mouseButton, int x, int y)
{
for(InputHelper ie: InputHelper.instances)
{
if(ie.checkRectangle(x, y))
{
ie.sendMouseInputToParent(mouseButton);
}
}
}
private void sendMouseInputToParent(int mouseButton)
{
parent.onClick(mouseButton);
}
public boolean checkRectangle(int x, int y)
{
//y = InputManager.HEIGHT - y; See below for explanation
return x > parent.getX() && x < parent.getX() + parent.getWidth() &&
y > parent.getY() && y < parent.getY() + parent.getHeight();
}
このコード行を挿入したのは、座標系の問題を一時的に修正したからです。ただし、コードをできるだけ独立させたいので、他のクラスへの依存をできるだけ取り除きたいと考えています。
これらはマウス入力に触れる唯一のメソッドであり、私が知る限り、それらのどれも何も変更しないので、ここではすべて問題ありません。次に、テクスチャ メソッドについて説明します。
public void draw()
{
if(!clicked || deactivatedImage == null)
{
activatedImage.bind();
glBegin(GL_QUADS);
{
DrawHelper.drawGLQuad(activatedImage, x, y, width, height);
}
glEnd();
} else {
deactivatedImage.bind();
glBegin(GL_QUADS);
{
DrawHelper.drawGLQuad(deactivatedImage, x, y, width,
height);
}
glEnd();
}
}
public static void drawGLQuad(Texture texture, float x, float y, float width, float
height)
{
glTexCoord2f(x, y);
glVertex2f(x, y);
glTexCoord2f(x, y + texture.getHeight());
glVertex2f(x, y + height);
glTexCoord2f(x + texture.getWidth(), y + texture.getHeight());
glVertex2f(x + width, y +height);
glTexCoord2f(x + texture.getWidth(), y);
glVertex2f(x + width, y);
}
正直なところ、この方法で実際に何が起こっているのかについては、まったくわかりませんが、自分で組み立てて機能させることができました. 私の推測では、ここに問題があると思います。
助けてくれてありがとう!