我的自定义OpenGL显示器上有一个复杂的椭圆形,需要在鼠标进入其边界时修改它的状态(正射透视图永远不会改变,因为这是2D游戏)。我的椭圆是使用:
创建的public class RenderOval {
public static double r = 0.2;
public static double g = 0.3;
public static double b = 0.5;
public static void renderOval(double locX, double locY, double width, double height){
GL11.glPushMatrix();
//Set Drawing Color - Will Remain this color until otherwise specified
GL11.glColor3d(r,g,b);
//Draw Circle
GL11.glBegin(GL11.GL_POLYGON);
//Change the 6 to 12 to increase the steps (number of drawn points) for a smoother circle
//Note that anything above 24 will have little affect on the circles appearance
//Play with the numbers till you find the result you are looking for
//Value 1.5 - Draws Triangle
//Value 2 - Draws Square
//Value 3 - Draws Hexagon
//Value 4 - Draws Octagon
//Value 5 - Draws Decagon
//Notice the correlation between the value and the number of sides
//The number of sides is always twice the value given this range
for(double i = 0; i < 2 * Math.PI; i += Math.PI / 24) //<-- Change this Value
GL11.glVertex3d(Math.cos(i) * width+locX, Math.sin(i) * height+locY, 0.0);
GL11.glEnd();
//Draw Circle
GL11.glPopMatrix();
}
}
这是一个非常复杂的形状,有许多顶点。但对于常规方块,我会知道如何检查鼠标是否在盒子的边界:
if((Mouse.getX<(box.startX+box.width))&&((Mouse.getX>(box.startX)))){
mouse.isInXBounds = true;
}
然而,我完全失去了如何针对任何自定义形状进行检查。任何帮助将非常感激。谢谢。