<commit_before>
package PV112;

import com.jogamp.opengl.util.FPSAnimator;
import com.jogamp.opengl.util.gl2.GLUT;
import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureData;
import com.jogamp.opengl.util.texture.TextureIO;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import javax.media.j3d.Transform3D;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
import javax.vecmath.Vector3f;


public class OpenGlListener implements GLEventListener {
    
    private GLUT glut = new GLUT();
    private GLU glu = new GLU();
    
    // key and mouse buffer
    public KeyBuffer keyBuffer = new KeyBuffer();
    public MouseBuffer mouseBuffer = new MouseBuffer();
    
    // models
    private int craneBottom;
    private int craneCabin;
    private int craneConsole;
    private int craneHook;
    private int skybox;
    private int surface;
    
    // textures
    private Texture craneTexture;
    private Texture asphaltTexture;
    private Texture skyboxTexture;
    
    // status
    private float craneRotation = 0.0f; // in degrees
    private float hookDistance = -20.0f; // from -60 to 30
    private float hookHeight = -100.0f; // -100 to 10
    private boolean on = false;
    private int grabbedItems = 0;
    
    // boxes
    public static final int BOX_COUNT = 20;
    public static final float MAGNET_TOLERANCY = 10.0f;
    public Set<Box> boxes = new HashSet<Box>();
    
    // camera
    public static final float CAMERA_STEP = 2.0f;
    public Camera cam = Camera.FREE_CAM;
    public float[] cabinCamPosition = {0, 0, 0}; // rx, ry, rz
    public Vector3f cameraRotation = new Vector3f(0, 0, 1);
    public Vector3f cameraPosition = new Vector3f(0, 80, -200);
    
    // fog
    public boolean fog = true;
    private float[] fogColor = { 0.5f, 0.5f, 0.5f, 1.0f};
    
    // change positions
    public void rotateCrane(float amount)
    {
        craneRotation += amount;
        if(craneRotation < 0.0f)
        {
            craneRotation = 360.0f + craneRotation;
        }
        if(craneRotation > 360.0f)
        {
            craneRotation = craneRotation % 360.0f;
        }
        
    }
    
    public void moveHook(float amount)
    {
        hookDistance += amount;
        if(hookDistance > 30)
        {
            hookDistance = 30;
        }
        if(hookDistance < -60)
        {
            hookDistance = -60;
        }
    }
    
    public void pullHook(float amount)
    {
        hookHeight += amount;
        if(hookHeight > 10)
        {
            hookHeight = 10;
        }
        if(hookHeight < -100)
        {
            hookHeight = -100;
        } 
    }
    
    public void magnet()
    {
        if(on == false)
        {
            Set<Box> indexes = new HashSet<Box>();
            for(Box box: boxes)
            {
                if(Math.abs(box.rotation - craneRotation) < MAGNET_TOLERANCY
                        && Math.abs(Math.abs(box.position) - Math.abs(-64.0 + hookDistance)) < MAGNET_TOLERANCY
                        && hookHeight < -90)
                {
                    indexes.add(box);
                }
            }
            boolean success = boxes.removeAll(indexes);
            grabbedItems = indexes.size();
        }
        else
        {
            for(int i = 0; i < grabbedItems; i++)
            {
                Box box = new Box((int)(craneRotation - 5.0 + Math.random() * 10.0), (int)(-64.0 + hookDistance - 5.0 + Math.random() * 10.0));
                boxes.add(box);
            }
            grabbedItems = 0;
        }
        on = !on;
    }
    
    public void changeCamera()
    {
        switch(cam)
        {
            case FREE_CAM:
                cam = Camera.CABIN_CAM;
                break;
            case CABIN_CAM:
                cam = Camera.HOOK_CAM;<commit_msg>only one box can now be magneted<commit_after>
package PV112;

import com.jogamp.opengl.util.FPSAnimator;
import com.jogamp.opengl.util.gl2.GLUT;
import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureData;
import com.jogamp.opengl.util.texture.TextureIO;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import javax.media.j3d.Transform3D;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
import javax.vecmath.Vector3f;


public class OpenGlListener implements GLEventListener {
    
    private GLUT glut = new GLUT();
    private GLU glu = new GLU();
    
    // key and mouse buffer
    public KeyBuffer keyBuffer = new KeyBuffer();
    public MouseBuffer mouseBuffer = new MouseBuffer();
    
    // models
    private int craneBottom;
    private int craneCabin;
    private int craneConsole;
    private int craneHook;
    private int skybox;
    private int surface;
    
    // textures
    private Texture craneTexture;
    private Texture asphaltTexture;
    private Texture skyboxTexture;
    
    // status
    private float craneRotation = 0.0f; // in degrees
    private float hookDistance = -20.0f; // from -60 to 30
    private float hookHeight = -100.0f; // -100 to 10
    private boolean on = false;
    private int grabbedItems = 0;
    
    // boxes
    public static final int BOX_COUNT = 20;
    public static final float MAGNET_TOLERANCY = 10.0f;
    public Set<Box> boxes = new HashSet<Box>();
    
    // camera
    public static final float CAMERA_STEP = 2.0f;
    public Camera cam = Camera.FREE_CAM;
    public float[] cabinCamPosition = {0, 0, 0}; // rx, ry, rz
    public Vector3f cameraRotation = new Vector3f(0, 0, 1);
    public Vector3f cameraPosition = new Vector3f(0, 80, -200);
    
    // fog
    public boolean fog = true;
    private float[] fogColor = { 0.5f, 0.5f, 0.5f, 1.0f};
    
    // change positions
    public void rotateCrane(float amount)
    {
        craneRotation += amount;
        if(craneRotation < 0.0f)
        {
            craneRotation = 360.0f + craneRotation;
        }
        if(craneRotation > 360.0f)
        {
            craneRotation = craneRotation % 360.0f;
        }
        
    }
    
    public void moveHook(float amount)
    {
        hookDistance += amount;
        if(hookDistance > 30)
        {
            hookDistance = 30;
        }
        if(hookDistance < -60)
        {
            hookDistance = -60;
        }
    }
    
    public void pullHook(float amount)
    {
        hookHeight += amount;
        if(hookHeight > 10)
        {
            hookHeight = 10;
        }
        if(hookHeight < -100)
        {
            hookHeight = -100;
        } 
    }
    
    public void magnet()
    {
        if(on == false)
        {
            //Box b;
            //Set<Box> indexes = new HashSet<Box>();
            for(Box box: boxes)
            {
                if(Math.abs(box.rotation - craneRotation) < MAGNET_TOLERANCY
                        && Math.abs(Math.abs(box.position) - Math.abs(-64.0 + hookDistance)) < MAGNET_TOLERANCY
                        && hookHeight < -90)
                {
                    boxes.remove(box);
                    grabbedItems = 1;
                    //b = box; //indexes.add(box);
                    break;
                }
            }
            //boxes.remove(b);
            //boolean success = boxes.removeAll(indexes);
            //grabbedItems = 1;
            //grabbedItems = indexes.size();
        }
        else
        {
            for(int i = 0; i < grabbedItems; i++)
            {
                Box box = new Box((int)(craneRotation /*- 5.0 + Math.random() * 10.0*/), (int)(-64.0 + hookDistance /*- 5.0 + Math.random() * 10.0*/));
                boxes.add(box);
            }
            grabbedItems = 0;
        }
        on = !on;
    }
    
    public void changeCamera()
    {
        switch(cam)
        {
            case FREE_CAM:
                cam = Camera.CABIN_CAM;
                break;
            case CABIN_CAM:
                cam = Camera.HOOK_CAM;
{'fraction_non_alphanumeric': 0.10307802433786686, 'fraction_numerical': 0.026485325697924122, 'mean_word_length': 1.7244068898277543, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2109299', 'n_tokens_mistral': 2770, 'n_tokens_neox': 2587, 'n_words': 618}