Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cg3d.e11scene3d;
- import java.awt.Font;
- import javax.media.opengl.GL;
- import com.sun.opengl.util.j2d.TextRenderer;
- import cgex.jogl.base.Color4f;
- import cgex.jogl.base.JoglFrame;
- import cgex.jogl.base.Vector3f;
- @SuppressWarnings({ "serial", "unused" })
- public class Zad3Template extends JoglFrame {
- private TextRenderer tr;
- private Vector3f[] vertices = {
- new Vector3f(-3f, -2f, 0f),
- new Vector3f(3f, -2f, 0f),
- new Vector3f(3f, -2f, -4f),
- new Vector3f(-3f, -2f, -4f),
- new Vector3f(-2f, 2f, -1f),
- new Vector3f(2f, 2f, -1f),
- new Vector3f(2f, 2f, -3f),
- new Vector3f(-2f, 2f, -3f)
- };
- private int indices[] = { 0, 1, 2, 0, 2, 3, 0, 5, 1, 0, 5, 4, 1, 6, 2, 1, 6, 5,
- 2, 6, 7, 2, 3, 7, 0, 4, 7, 0, 3, 7, 4, 5, 6, 4, 6, 7 };
- private static final Color4f[] colors = {
- new Color4f(1.0f, 0.0f, 0.0f),
- new Color4f(0.0f, 1.0f, 0.0f),
- new Color4f(1.0f, 1.0f, 0.0f),
- new Color4f(1.0f, 1.0f, 1.0f),
- new Color4f(0.0f, 0.0f, 1.0f),
- new Color4f(1.0f, 0.0f, 1.0f),
- new Color4f(0.0f, 1.0f, 1.0f),
- new Color4f(0.4f, 1.2f, 0.9f)
- };
- @Override
- protected void initialize(GL gl, Color4f backColor, Vector3f cameraPos,
- Vector3f cameraDir) {
- cameraPos.assign(6.32f, 8.56f, 13.27f);
- cameraDir.assign(-0.35f, -0.53f, -0.77f);
- Font font = new Font("Tahoma", Font.BOLD, 12);
- tr = new TextRenderer(font);
- }
- @Override
- protected void render(GL gl, double elapsedTime) {
- gl.glBegin(GL.GL_TRIANGLES);
- for (int i = 0; i < indices.length; i++) {
- int index = indices[i];
- Vector3f vertex = vertices[index];
- Color4f boje = colors[index];
- gl.glColor3f(boje.getRed(), boje.getGreen(), boje.getBlue());
- gl.glVertex3f(vertex.getX(), vertex.getY(), vertex.getZ());
- }
- gl.glEnd();
- int w = getWidth();
- int h = getHeight();
- tr.beginRendering(w, h);
- {
- tr.setColor(1.0f, 1.0f, 0.0f, 1.0f);
- // trenutni FPS
- tr.draw("FPS: " + getFps(), 8, h - 48);
- // trenutna pozicija i orijentacija kamere
- tr.draw("Position: " + camera.getPosition(), 8, h - 64);
- tr.draw("Direction: " + camera.getLookDirection(), 8, h - 80);
- }
- tr.endRendering(); // kraj renderovanja
- }
- public static void main(String[] args)
- {
- new Zad3Template().start("Zad3", 800, 600, false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement