LWJGL 이동과 회전(LWJGL - Rotation and Picking)[LWJGL,이동,회전,Rotation and Picking,lwjgl.org,Lightweight Java Game Library]

이미지출처 : www.lwjgl.org

LWJGL 이동과 회전 그리고 픽킹(LWJGL - Rotation and Picking)

물체의 이동과 회전


Code:

GL11.glTranslatef(this.xoff, this.yoff, this.zoff-this.centerAvgXYZ);
        GL11.glRotatef(this.xrot, 1.0f, 0.0f, 0.0f);
        GL11.glRotatef(this.yrot, 0.0f, 1.0f, 0.0f);


Picking


Code:

public void SelectObjects(int x, int y) {
      int hits;
      int[] viewport = new int[4];
      int buffer[] = new int[256];
      IntBuffer selectBuff = ByteBuffer.allocateDirect(1024).order(ByteOrder.nativeOrder()).asIntBuffer();
        IntBuffer vpBuffer = ByteBuffer.allocateDirect(64).order(ByteOrder.nativeOrder()).asIntBuffer();
      GL11.glGetInteger(GL11.GL_VIEWPORT, vpBuffer);
      vpBuffer.get(viewport);
      GL11.glSelectBuffer(selectBuff);
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glPushMatrix();
      GL11.glRenderMode(GL11.GL_SELECT);
      GL11.glLoadIdentity();
      GLU.gluPickMatrix((float)x,(float)(viewport[3]-y), 5.0f, 5.0f, viewport);    
        GLU.gluPerspective(45.0f, ratio, 0.001f, 100.0f);
           //Rectangle rect = this.canvas.getClientArea();              
          // ratio = (float) rect.width / (float) rect.height;
     
      GL11.glMatrixMode(GL11.GL_MODELVIEW); // 물체를 그려줄때는 다시 모델뷰로..
      drawScatterPlot();                                  // 물체를 그려주고,
      GL11.glRotatef(this.xrot, 1.0f, 0.0f, 0.0f);  // 그 후에 회전을 해준다.
        GL11.glRotatef(this.yrot, 0.0f, 1.0f, 0.0f);
       
      hits = GL11.glRenderMode(GL11.GL_RENDER);
      System.out.println("Hits : "+hits);
      selectBuff.get(buffer);
      if(hits>0) {
        int selectedObjID = buffer[3];
      int depth = buffer[1];
                      for (int i = 1; i < hits; i++) {
                if (buffer[i * 4 + 1] < (int) depth) {
                  selectedObjID = buffer[i * 4 + 3];
                      depth = buffer[i * 4 + 1];
                }
          }
          ProcessSelect(selectedObjID);
      }
      GL11.glMatrixMode(GL11.GL_PROJECTION);            
      GL11.glPopMatrix();            
      GL11.glFlush();
      GL11.glMatrixMode(GL11.GL_MODELVIEW);              
  }



by


Tags : , , , , , , , , ,

  • 재미있게 읽으셨나요?
    광고를 클릭해주시면,
    블로그 운영에 큰 도움이 됩니다!

자주쓰는 OpenGL함수들 (favorite OpenGL Functions!!)[OpenGL,함수,funtion,favorite]

이미지출처 : techie-buzz.com

OpenGL함수들 (OpenGL Functions!!)







———-


Shape

———-

Shape.draw();

GLU.gluCylinder(QUADRIC, RADIUS, RADIUS, height, slices, stacks);

GLU.gluDisk(QUADRIC, Inner RADIUS, Outer RADIUS, slices,

stacks);



GLU.gluSphere(QUADRIC,RADIUS, slices, stacks);



#DISPLAY LIST With GL_COMPILE

GL.glNewList(this.getListIndex(), GL.GL_COMPILE);



GL.glEndList();



GL.glBegin(TYPE);

GL.glVertex3f(AxisX,AxisY,AxisZ);

GL.glEnd();



#TYPES

GL.GL_POINTS

GL.GL_LINE_LOOP

GL.GL_LINES

GL.GL_QUADS

GL.GL_LINE_STRIP (CURVE -> Multi Line)








———-

translate

———-

GL.glLoadIdentity();

GL.glPushMatrix();

GL.glPopMatrix();

GL.glTranslatef(AxisX,AxisY,AxisZ);

GL.glRotatef(Angle, AxisX,AxisY,AxisZ);



———-

size

———-

GL.glPointSize(float size);

GL.glLineWidth(float width);




———-

colors

———-

GL.glColor3f(float red,float green,float blue);

GL.glColor4f(float red,float green,float blue,float alpha);

GL.glColor4fv(float args[]);



———-

Effects

———-

GL.glBlendFunc() :

blend function’s source and destination rate setting.

EX)

GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);




GL.glLightfv() : light setting.

EX)

GL.glLightfv(GL.GL_LIGHT1,

GL.GL_DIFFUSE,

new float[] {1.0f, 1.0f, 1.0f, 1.0f});

GL.glLightfv(GL.GL_LIGHT1,

GL.GL_AMBIENT,

new float[] {0.5f, 0.5f, 0.5f, 1.0f});

GL.glLightfv(GL.GL_LIGHT1,

GL.GL_POSITION,

new float[] {-50.f, 50.0f, 100.0f, 1.0f});




GL.glEnable() : enable effects.

EX)

GL.glEnable(GL.GL_BLEND);

GL.glEnable(GL.GL_LIGHTING);

GL.glEnable(GL.GL_COLOR_MATERIAL);




Reference

————————-

Using OpenGL in SWT Applications :

http://www.eclipse.org/swt/opengl/

http://www.eclipse.org/articles/Article-SWT-OpenGL/opengl.html



NeHe : http://nehe.gamedev.net/



by


Tags : , , , ,

  • 재미있게 읽으셨나요?
    광고를 클릭해주시면,
    블로그 운영에 큰 도움이 됩니다!