我想圍繞一個不是(0,0)的點旋轉一條線。在OpenGL中圍繞一個點旋轉一條線
對於此程序,我試圖不使用glRotatef()
並嘗試使用三角函數。但是線路的長度總是會改變的。
有什麼建議嗎?
這是我的代碼:
public class World implements GLEventListener, KeyListener
{
double xOne = 0.1;
double yOne = 0.1;
double xTwo = 0;
double yTwo = 0.01;
double i = 220.987;
public World()
{
}
public void init(GLAutoDrawable gld)
{
Animator theAnimator = new Animator(gld);
theAnimator.start();
}
public void display(GLAutoDrawable gld)
{
GL gl = gld.getGL();
gl.glEnable(gl.GL_BLEND);
gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glBegin(gl.GL_LINES);
gl.glColor3d(1,0,0);
gl.glVertex2d(xOne ,yOne);
gl.glColor3d(0,0,1);
gl.glVertex2d(xTwo, yTwo);
gl.glEnd();
gl.glFlush();
//UPDATE
}
public void reshape(GLAutoDrawable gLAutoDrawable, int _int, int _int2, int _int3, int _int4)
{
}
public void displayChanged(GLAutoDrawable gLAutoDrawable, boolean _boolean, boolean _boolean2)
{
}
public void keyTyped(KeyEvent ke)
{
}
public void keyPressed(KeyEvent ke)
{
if(ke.getKeyCode() == KeyEvent.VK_SPACE)
{
xTwo = (Math.cos(Math.toRadians(i))+xOne);
yTwo = (Math.sin(Math.toRadians(i))+yOne);
i++;
}
}
public void keyReleased(KeyEvent ke)
{
}
}
順便說一句,(xOne, yOne)
是駐點
對不起,我沒有得到 – kimchiboy03
@ kimchiboy03這不是很豐富。如果你想獲得幫助,告訴我們你不明白的是什麼。 – HolyBlackCat
@ kimchiboy03我回答了你的問題,但回頭看起來好像你會更喜歡我修正你的代碼。我已經修改了我的答案,也給了你一個建議。 –