2011-12-07 5 views
0

나는 C#으로 OpenGL을 사용하고 있습니다. 다음과 같은 다른 라이브러리를 사용할 수 없습니다.이미지 회전?

using System; 
using OpenGL; 
using System.Windows.Forms; 
using System.Collections.Generic; 
using System.Drawing; 

나는 움직이지 않는 방식으로 내 이미지를 회전시키는 것처럼 보이지 않습니다.

foreach (Bug bug in m_Bugs) 
      { 
       double radians = Math.Atan2(bug.getPos().X + bug.getVel().X, bug.getPos().Y + bug.getVel().Y); 
       double angle = radians * (180/Math.PI); 

       GL.glRotated(angle, 0, 0, 1); 
       bug.Draw(); 
      } 

내 그리기 방법은 여기에 메인 쓰레드에서 호출됩니다 :

나의 세계 그리기 방법이라고

form.RegisterDraw(myWorld.Draw); 

내 bug.draw이 perefectly 작동이 표시하고 혼합 텍스처 괜찮아.

내 world.draw 메서드의 foreach 루프에있는 코드는 벨로 시티 (getVel)와 위치 (getPos)를 2 차원 벡터로 반환합니다.

도움이 되시면 감사하겠습니다.

private void Load(uint[] array, int index, string filepath) 
    { 
     Bitmap image = new Bitmap(filepath); 
     image.RotateFlip(RotateFlipType.RotateNoneFlipY); 
     System.Drawing.Imaging.BitmapData bitmapdata; 
     Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); 
     bitmapdata = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); 

     /* Set the correct ID, then load the texture for that ID * from RAM onto the Graphics card */ 
     GL.glBindTexture(GL.GL_TEXTURE_2D, array[index]); 
     GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, image.Width, image.Height, 0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_byte, bitmapdata.Scan0); 
     GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR); 
     GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR); 

     /* This code releases the data that we loaded to RAM * but the texture is still on the Graphics Card */ 
     image.UnlockBits(bitmapdata); 
     image.Dispose(); 
    } 

답변

0

왜 Pos + Vel인가?

Pos 만 필요할 것 같습니다. 그래서 :

Math.Atan2(bug.getVel().X, bug.getVel().Y); 
0

내가 그대로에 인용 https://stackoverflow.com/a/7288931/524368 이미이 대답


이 개체가 방향 D로 이동 말, 당신이해야 할 그 방향에 수직 인 벡터를 찾는 것입니다. 경우에 당신의 운동은 정상적인 비행기 N.이 그 정상화 후 3 개 벡터 D, E 및 N. 당신을 얻을 수

E = D × N 

와 D의 십자가 제품을 복용하여 벡터 E를 찾을 수있는 단 하나 개의면에 회전 된 좌표계의 기초를 형성한다. 당신은

D_x E_x N_x 
D_y E_y N_y 
D_z E_z N_z 

는 4 × 4 균일 한

D_x E_x N_x 0 
D_y E_y N_y 0 
D_z E_z N_z 0 
    0 0 0 1 

에이 행렬을 확장 3 × 3 행렬의 열로 넣을 수 있습니다 그리고 당신은에 적용 할 glMultMatrix로하는 OpenGL을 전달할 수 있습니다 행렬 스택

+0

답장을 보내 주셔서 감사합니다. 코드에서 좌표계와 속도 사이의 각도로 어떻게 버그를 회전시킬 수 있습니까? – rx432