# Pls help -openGL boundary checking in skybox

• 06-01-2012
evildotaing
Pls help -openGL boundary checking in skybox
I am doing a boundary checking in skybox where the camera cannot move out of skybox. But using this code:
Code:

`        if (((Position.z <= 0 && Position.z >= -380) && (Position.y >= 0 && Position.y <= 20)) && (Position.x <= 195 && Position.x >= -195))`
Seems there is a problem in (Position.x <= 195 && Position.x >= -195)) where I still can get out of the skybox. What is the right way of coding such as all of them would not moved out of the skybox. It seemed my codes only the Position.y and Position.z managed to stop the camera from moving out of the skybox. How to compare 3 different position using &&.
• 06-02-2012
whiteflags
When you hit the edge of the box you actually can't keep moving in the same direction if you want to stay inside of it. All of the equals signs in your condition include edge cases, or so I assume, because you didn't actually give the dimensions of the box. So to correct the condition try removing the equals first.

edit: Well technically you can "fly around the world" so to speak, and so continue to move in the same direction, if you start again from the opposite side when you hit an edge, so that is a minor correction I should make but don't let it distract you.
• 06-02-2012
evildotaing
All of the codes have no problem expect the last part where I still can move out of the skybox by pressing button ''a' or 'd'. Is my && wrong. I not really good in comparing 6 position using &&.
• 06-02-2012
rogster001
Quote:

if (((Position.z <= 0 && Position.z >= -380) && (Position.y >= 0 && Position.y <= 20)) && (Position.x <= 195 && Position.x >= -195))
You will have a nightmare if you continue to use magic numbers like this.
Define your limits - BLAH_BLAH = < a_known_value> whatever. You simply cannot scale up what you are doing now without this.
• 06-02-2012
evildotaing
My codes have no problem staying in skybox except the x-value. I have already check the values, it is definitely right. What is the correct way to use && when I had to make sure the 6 positions is correct before I allow the camera to move.
• 06-02-2012
rogster001
You might want to ((bracket)..(off)) your expressions when using more complex conditions and see if that helps
• 06-02-2012
VirtualAce
Um...I'm lost. Technically the camera should NEVER hit the skybox b/c the skybox is always centered around the camera. You should be translating your skybox with the camera so the two will never intersect. If this is not happening it is a serious flaw in your system and needs to be corrected. However if you want to know the algorithm to use to keep your 3rd person camera from clipping through other objects in the world you need to look into swept sphere. Alternatively you can use the open source Bullet physics API that offers functionality that calculates this for you and tells you the new position of the object in question so it does not clip.

If the skybox is centered around your camera then the world positions of the center of it's planes can be calculated easily. Please note these calculations are for a left-handed system right: +x, up: +y, into screen: +z and skyBoxScale is expressed in world coordinates.

Left = cameraWorldPos.x - Vector3(1.0f,0.0f,0.0f) * (skyBoxScale.x * 0.5f);
Top = cameraWorldPos.y + Vector3(0.0f,1.0f,0.0f) * (skyBoxScale.y * 0.5f);
Right = Left + skyBoxScale.x;
Bottom = Top + skyBoxScale.y;
Front = cameraWorldPos.x + Vector3(0.0f,0.0f,1.0f) * (skyBoxScale.z * 0.5f);
Back = Front - skyBoxScale.z;

Given those centers and the scale of the skybox you can easily calculate the planes.
• 06-02-2012
evildotaing
The skybox is a piece of walls and I am inside a house. So I am using boundary checking for preventing camera to move outside of the skybox. Just that I got problem and the camera can still moved out of the skybox in the left and right direction when I pressed button 'a' or 'd' which keys in to move sideways. Other no problem.
• 06-03-2012
manasij7479
Quote:

Originally Posted by evildotaing
The skybox is a piece of walls and I am inside a house. So I am using boundary checking for preventing camera to move outside of the skybox. Just that I got problem and the camera can still moved out of the skybox in the left and right direction when I pressed button 'a' or 'd' which keys in to move sideways. Other no problem.

Err... walls are not 'usually' skyboxes, I think.
In this case, just restrict the x-y-z coordinates of the camera to not go beyond the room, in local coordinates.
(That eliminates the need of any complicated polygon algorithms )

A skybox, otoh, is 'sort' of attached to the camera.
It has to be translated or rotated exactly opposite in magnitude with the camera.
• 06-03-2012
evildotaing
So, if my code for if (((Position.z <= 0 && Position.z >= -380) && (Position.y >= 0 && Position.y <= 20)) && (Position.x <= 195 && Position.x >= -195)) is wrong? A bit weird that Position.z and Position.y worked but not the Position.x.
• 06-05-2012
VirtualAce
A bit weird you are still trying to test against the skybox when it should never collide with the camera.