简体   繁体   中英

3D model wont translate

I am trying to make a model get very close to the camera so that it can be seen better, but it is drawn so far away and I have no idea how to move it closer. I tried using GL11.glTranslatef(0,0,1); to get it to move closer, but for some odd reason the object just stays the same distance away and never gets closer. Then it dissapears outside of the near/far plane view. Any ideas on how I can fix this issue? There is a copy of the class below.

package engine;

import model.Face;
import model.Model;
import model.ObjLoader;

import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector3f;

public class Render {

    Model m = null;

    public Render() {

    }

    public void draw(){
        GL11.glClearColor(0, 0, 0, 1);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
        GL11.glBegin(GL11.GL_TRIANGLES);
            for (Face f : m.faces){
                //This code draws the model.
                Vector3f n1 = m.normals.get((int)f.normalIndicies.x - 1);
                GL11.glNormal3f(n1.x, n1.y, n1.z);
                Vector3f v1 = m.vertecies.get((int)f.indicies.x - 1);
                GL11.glVertex3f(v1.x, v1.y, v1.z); //First vertex


                Vector3f n2 = m.normals.get((int)f.normalIndicies.y - 1);
                GL11.glNormal3f(n2.x, n2.y, n2.z);
                Vector3f v2 = m.vertecies.get((int)f.indicies.y - 1);
                GL11.glVertex3f(v2.x, v2.y, v2.z); //second vertex

                Vector3f n3 = m.normals.get((int)f.normalIndicies.z - 1);
                GL11.glNormal3f(n3.x, n3.y, n3.z);
                Vector3f v3 = m.vertecies.get((int)f.indicies.z - 1);
                GL11.glVertex3f(v3.x, v3.y, v3.z); // third vertex
            }
        GL11.glEnd();

        GL11.glTranslatef(0, 0, 1); // <---- Here is the issue!!!

    }

    public void initOpenGL(){
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
        GL11.glOrtho(0, 800, 600, 0, 1, -100);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);


        try{
            m = ObjLoader.loadModel("bunnyWithNormals.obj");
        }catch (Exception e){
            e.printStackTrace();
        }
        GL11.glTranslatef(400f, 300f, 0); // moves it onto the screen
    }

}

使用glFrustum() / glPerspective()代替glOrtho()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM