Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Actualitzacions;
- import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
- import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
- import static org.lwjgl.opengl.GL11.GL_PROJECTION;
- import static org.lwjgl.opengl.GL11.GL_QUADS;
- import static org.lwjgl.opengl.GL11.glBegin;
- import static org.lwjgl.opengl.GL11.glClear;
- import static org.lwjgl.opengl.GL11.glClearColor;
- import static org.lwjgl.opengl.GL11.glColor3f;
- import static org.lwjgl.opengl.GL11.glEnd;
- import static org.lwjgl.opengl.GL11.glLoadIdentity;
- import static org.lwjgl.opengl.GL11.glMatrixMode;
- import static org.lwjgl.opengl.GL11.glOrtho;
- import static org.lwjgl.opengl.GL11.glPopMatrix;
- import static org.lwjgl.opengl.GL11.glPushMatrix;
- import static org.lwjgl.opengl.GL11.glRotatef;
- import static org.lwjgl.opengl.GL11.glTranslatef;
- import static org.lwjgl.opengl.GL11.glVertex2d;
- import org.lwjgl.LWJGLException;
- import org.lwjgl.Sys;
- import org.lwjgl.input.Keyboard;
- import org.lwjgl.opengl.Display;
- import org.lwjgl.opengl.DisplayMode;
- public class SenseLimit
- {
- private static long tempsUltimFrame;
- private static float rotacio,x = 300f,y = 200f;
- private static double passat = 0;
- public static void main(String args[])
- {
- try
- {
- Display.setDisplayMode(new DisplayMode(600,400));
- Display.setTitle("Actualitzacions");
- Display.create();
- }
- catch(LWJGLException e) {
- e.printStackTrace();
- }
- getDelta();
- iniciar();
- while(!Display.isCloseRequested())
- {
- double delta = getDelta();
- passat += delta;//nem afegin els segons que passen per cada frame
- System.out.println(passat);
- if(passat >= 1000.0/60.0)//si els segons que han passat son mes o iguals que els qe tenen qe
- //pasar perqe hi hagin 60 actualitzacions per segon, actualitzem
- {
- System.out.println("ya");
- actualitzar(passat);//actualitzem depenen dels segons qe hagin passat, per tindre velocitat constant
- passat = 0;
- }
- renderitzar();
- Display.update();
- }
- Display.destroy();
- }
- public static int getDelta()//obte quants milisegons han passat desde l'ultim frame
- {
- long tempsms = (Sys.getTime() * 1000) / Sys.getTimerResolution();//obté temps en milisegons
- int delta = (int) (tempsms - tempsUltimFrame);
- tempsUltimFrame = tempsms;
- return delta;
- }
- public static void iniciar()
- {
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0,600,0,400,1,-1);
- glMatrixMode(GL_MODELVIEW);
- glClearColor(0,0,0,0);
- }
- public static void actualitzar(double delta)
- {
- if(Keyboard.isKeyDown(Keyboard.KEY_UP))
- //rotacio += 0.1f * delta;
- y += 0.5f * delta;
- if(Keyboard.isKeyDown(Keyboard.KEY_DOWN))
- //rotacio -= 0.1f * delta;
- y -= 0.5f * delta;
- }
- public static void renderitzar()
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(0.f,0.5f,1.0f);
- glPushMatrix();
- glTranslatef(x,y,0);
- glRotatef(rotacio, 0f, 0f, 1f);
- glTranslatef(-x,-y,0);
- glBegin(GL_QUADS);
- glVertex2d(x-50,y-50);
- glVertex2d(x+50,y-50);
- glVertex2d(x+50,y+50);
- glVertex2d(x-50,y+50);
- glEnd();
- glPopMatrix();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement