Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: 3D Collision problems

  1. #1
    Newbie Newbie
    Join Date
    Mar 2013
    Posts
    1

    Question 3D Collision problems

    i have 2 3D cubes one which is moving and the other is stands in the Map.
    But if the Camera cube is touching the other cube, the cube gets stuck in some positions

    Collision Class:
    Code :
    	public static boolean Checkfront(float camx, float camy, float camz)
    	{
    		float x = 0.0f;
    		float y = 0.0f;
    		float z = 0.0f;
     
    		if (x - 1.03 < camx && x + 1 > camx || x == camx){
    			if (y < camy && y + 1 > camy || y == camy){
    				if (z < camz && z + 1 > camz || z == camz){
    					return true;	
    				}else{
    					return false;
    				}				
    			}else{
    				return false;
    			}			
    		}else{
    			return false;
    		}						
    	}
     
    	public static boolean Checkleft (float camx, float camy, float camz)
    	{
    		float x = 0.0f;
    		float y = 0.0f;
    		float z = 0.0f;
     
    		if (x - 1.03 < camx && x > camx || x - 1 == camx){
    			if (y < camy && y + 1 > camy || y == camy){
    				if (z - 1 < camz && z + 1 > camz || z == camz){
    					return true;	
    				}else{
    					return false;
    				}				
    			}else{
    				return false;
    			}			
    		}else{
    			return false;
    		}			
    	}
     
    	public static boolean Checkback (float camx, float camy, float camz)
    	{
    		float x = 0.0f;
    		float y = 0.0f;
    		float z = 0.0f;
     
    		if (x - 1.03  < camx && x + 1 > camx || x == camx){
    			if (y < camy && y + 1 > camy || y == camy){
    				if (z - 1 < camz && z + 1 > camz || z == camz){
    					return true;	
    				}else{
    					return false;
    				}				
    			}else{
    				return false;
    			}			
    		}else{
    			return false;
    		}
    	}
     
    	public static boolean Checkright (float camx, float camy, float camz)
    	{
    		float x = 0.0f;
    		float y = 0.0f;
    		float z = 0.0f;
     
    		if (x + 1.03 > camx || x == camx){
    			if (y < camy && y + 1 > camy || y == camy){
    				if (z - 1.03 < camz && z + 1 > camz || z == camz){
    					return true;	
    				}else{
    					return false;
    				}				
    			}else{
    				return false;
    			}			
    		}else{
    			return false;
    		}	
    	}

    Move Class:
    Code :
    public static void PlayerControle()
    	{
    		    if(Keyboard.isKeyDown(Keyboard.KEY_W) && physic.Checkforne(x, y, z) == false){
    	        	z -= speed * Math.sin(Math.toRadians(ry +90 * 1)); 
    	        	x -= speed * Math.cos(Math.toRadians(ry -90 * 1)); 
    	        	Player1Cam.posz = -z - 5;
    		    }
    		    if(Keyboard.isKeyDown(Keyboard.KEY_S) && physic.Checkhinten(x, y, z) == false){
    	        	z += speed * Math.sin(Math.toRadians(ry +90 * 1));
    	        	x += speed * Math.cos(Math.toRadians(ry -90 * 1));      
    	        	Player1Cam.posz = -z - 5;
    	        }
    		    if(Keyboard.isKeyDown(Keyboard.KEY_A) && physic.Checkrechts(x,y,z) == false){
    	        	z -= speed * Math.sin(Math.toRadians(ry +90 * 0));
    	        	x -= speed * Math.cos(Math.toRadians(ry -90 * 0));   
                    Player1Cam.posx = -x - 0.5f;
                }
    		    if(Keyboard.isKeyDown(Keyboard.KEY_D) && physic.Checkleft(x,y,z) == false){
    	        z += speed * Math.sin(Math.toRadians(ry +90 * 0)); 
    	        x += speed * Math.cos(Math.toRadians(ry -90 * 0));  
    	            Player1Cam.posx = -x - 0.5f;
    		    }
     
    	}

  2. #2
    Junior Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    134
    this forum is about OpenGL - API for rendering. your question is about processing physics. ask it on gamedev.net or somewhere else.
    I am a star's ray through billions of years
    Piercing through the weakness of optic nerve
    I am the blade of sparkling "no"
    Ripping up the pregnancy of joy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •