我的绘画再次聚集了我在各种天使身上旋转的小线条或圆圈(主要是线条)。 现在我想旋转整个绘图到某个天使。如何旋转旋转单个零件的聚合形状?
你可以看到我想要实现。 所以我的问题是关于如何旋转整个绘图。
@Override
public void display(GLAutoDrawable arg0) {
final GL2 gl = arg0.getGL().getGL2();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
drwaMan(gl);
gl.glFlush();
}
private void drwaMan(GL2 gl) {
// this line is not working i was hoping by doing something like this entire shape will rotate
//gl.glRotatef(15, 0f, 0f, 1.0f);
float radius = 50;
float cx = 100, cy = 400; // center of circle
int bodyAngel = 180; // draw line at angel
float bodyLineLength = 150;
int lineAngel = 270;
// calculate first point of line
float px = (float) (radius * Math.sin(Math.toRadians(bodyAngel))) + cx;
float py = (float) (radius * Math.cos(Math.toRadians(bodyAngel))) + cy;
// draw head
drawCircle(gl,radius,cx,cy);
// draw line
drawBoadyLine(gl,px,py,bodyLineLength,lineAngel);
// drawhands 50 distance from starting point
drawHands(gl,px,py-50,225,315,100);
// lags at end of line
drawHands(gl,px,py-150,225,315,100);
}
void drawCircle(GL2 gl,float radius,float cx,float cy)
{
gl.glLoadIdentity();
gl.glColor3f(1.0f, 1.0f, 1.0f);
gl.glBegin(GL.GL_LINE_LOOP);
for (int i = 0; i <= 360; i++) {
float x1, y1;
x1 = (float) (radius * Math.sin(Math.toRadians(i))) + cx;
y1 = (float) (radius * Math.cos(Math.toRadians(i))) + cy;
gl.glVertex2d(x1,y1);
}
gl.glEnd();
}
private void drawHands(GL2 gl, float x, float y, int a1, int a2,int l) {
gl.glLoadIdentity();
gl.glTranslatef(x, y, 0);
gl.glRotatef(a1, 0, 0, 1);
gl.glBegin(GL.GL_LINE_LOOP);
gl.glVertex2f(0, 0);
gl.glVertex2f(l, 0);
gl.glEnd();
gl.glLoadIdentity();
gl.glTranslatef(x, y, 0);
gl.glRotatef(a2, 0, 0, 1);
gl.glBegin(GL.GL_LINE_LOOP);
gl.glVertex2f(0, 0);
gl.glVertex2f(l, 0);
gl.glEnd();
}
private void drawBoadyLine(GL2 gl, float x, float y, float bodyLineLength, int bodyAngel) {
gl.glLoadIdentity();
gl.glTranslatef(x, y, 0);
gl.glRotatef(bodyAngel, 0f, 0f, 1.0f);
gl.glBegin(GL.GL_LINE_LOOP);
gl.glVertex2f(0, 0);
gl.glVertex2f(bodyLineLength, 0);
gl.glEnd();
}
我很感激,如果你们提供了一些解决方案或任何帮助指出相关的武术,解决这个问题的一些例子是有帮助的。
注:我已经使用OpenGL-JOGL绑定来编写代码。
预先感谢您。
听起来像是一个2D转换给我。我发现[这个页面很有帮助](http://www.willamette.edu/~gorr/classes/GeneralGraphics/Transforms/transforms2d.htm)作为一种转换的备忘单。 – dbrown93
@ dbrown93这篇文章仅仅是关于理论知识,没有关于如何通过任何API实现的实例。 – JBaba
是的,但它只是应用关于一个点的旋转的部分。所以你会把男人的“中心”翻译成原点,旋转坐标,然后翻译男人回来 – dbrown93