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 4 of 4

Thread: Camera collision detection

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    4

    Camera collision detection

    Hello everybody, I need your help.

    I've made a 3d House, the only thing that I need is to make some camera based collision detection, but I really don't know how to do this, even after searching throw the internet.

    This the code for the camera:

    Code :
    if (freelook_flag)
    	{
          		Matrix4x4 m;
     
          		//Changing visualization with mouse
          		buildRotationMatrix(camera.frame.Yaxis, deg2rad(-yrot),  m);
          		transform(m, camera.frame.Xaxis);
          		transform(m, camera.frame.Yaxis);
          		transform(m, camera.frame.Zaxis);
     
    		//Keyboard moving
     
          		if (up_key)
    		{
    				camera.position.x += -camera.frame.Zaxis.x * speed;
    	  			camera.position.y += -camera.frame.Zaxis.y * speed;
    	  			camera.position.z += -camera.frame.Zaxis.z * speed;
    		}
     
          		if (down_key)
    		{
    	  		camera.position.x += camera.frame.Zaxis.x * speed;
    	  		camera.position.y += camera.frame.Zaxis.y * speed;
    	  		camera.position.z += camera.frame.Zaxis.z * speed;
    		}
     
          		if (left_key)
    		{
    	  		camera.position.x += -camera.frame.Xaxis.x * speed;
    	  		camera.position.y += -camera.frame.Xaxis.y * speed;
    	  		camera.position.z += -camera.frame.Xaxis.z * speed;
    		}
     
          		if (right_key)
    		{
    	  		camera.position.x += camera.frame.Xaxis.x * speed;
    	  		camera.position.y += camera.frame.Xaxis.y * speed;
    	  		camera.position.z += camera.frame.Xaxis.z * speed;
    		}
     
    		if (UPElevation_key)
    		{
    	  		camera.position.x += camera.frame.Yaxis.x * speed;
    	  		camera.position.y += camera.frame.Yaxis.y * speed;
    	  		camera.position.z += camera.frame.Yaxis.z * speed;
    		}
     
    		if (DownElevation_key)
    		{
    	  		camera.position.x += -camera.frame.Yaxis.x * speed;
    	  		camera.position.y += -camera.frame.Yaxis.y * speed;
    	  		camera.position.z += -camera.frame.Yaxis.z * speed;
    		}
        	}// fine if (freelook_flag)
     
      	pitch+=xrot;
      	if (pitch>90) pitch=90;
      	if (pitch<-90) pitch=-90;
     
      	Camera temp(camera);
      	Matrix4x4 m2;
      	buildRotationMatrix(temp.frame.Xaxis, deg2rad(pitch),  m2);
      	transform(m2, temp.frame.Xaxis);
      	transform(m2, temp.frame.Yaxis);
      	transform(m2, temp.frame.Zaxis);
     
      	Matrix4x4 c;
      	buildCameraMatrix(temp,c);
      	glMultMatrixf(c.GL_array());
     
      	if (freelook_flag)
        		if(mouse_moved)
          		{
    		// pointer at the center of the window
    			mouse_moved=false;
    			glutWarpPointer(width/2, height/2);
          		}

    And I have a method that changes the boolean for every key from true to false...

    Can you help me?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    Do you mean collision detection or camera movement? You don't seem to be moving anything.

  3. #3
    Intern Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    97
    hi,

    pls give us some more info.
    but basicly you camera has a position, so use this one to detect collission.
    Yoi may need to take care of you near clipping plane, so you do not get display errors.

    cu
    uwi
    uwi2k2 - OpenGL Trainer: www.opengl-trainer.com
    ---------------------------------------------------------
    Free Programming Helpline: www.programming-hotline.com
    ---------------------------------------------------------
    A Friday Night Programmer: www.uwiworld.net

  4. #4
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    4
    Yeah I mean the detection of the collision between the camera moviment and the environment

Posting Permissions

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