我的繪畫再次聚集了我在各種天使身上旋轉的小線條或圓圈(主要是線條)。 現在我想旋轉整個繪圖到某個天使。如何旋轉旋轉單個零件的聚合形狀?
你可以看到我想要實現。 所以我的問題是關於如何旋轉整個繪圖。
@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