const R3Point R3Box:: ClosestPoint(const R3Point& point) const { // Return closest point in box R3Point closest(point); if (closest.X() < XMin()) closest[RN_X] = XMin(); else if (closest.X() > XMax()) closest[RN_X] = XMax(); if (closest.Y() < YMin()) closest[RN_Y] = YMin(); else if (closest.Y() > YMax()) closest[RN_Y] = YMax(); if (closest.Z() < ZMin()) closest[RN_Z] = ZMin(); else if (closest.Z() > ZMax()) closest[RN_Z] = ZMax(); return closest; }
bool Box::Contains( Box const& other ) const { return ( XMin() <= other.XMin() && XMax() >= other.XMax() && YMin() <= other.YMin() && YMax() >= other.YMax() ); }
void ProcessKeyboardInputs(VxVector* RotationAngles, CKBehavior* beh, CKInputManager *input, float delta, CKBOOL &Returns, CKBOOL &stopping) { // Is the move limited ? CKBOOL Limited = TRUE; beh->GetLocalParameterValue(LOCAL_LIMITS,&Limited); // Gets the keys settings int key_left=0; beh->GetLocalParameterValue(LOCAL_KEY_LEFT,&key_left); if(!key_left) key_left=CKKEY_LEFT; int key_right=0; beh->GetLocalParameterValue(LOCAL_KEY_RIGHT,&key_right); if(!key_right) key_right=CKKEY_RIGHT; int key_up=0; beh->GetLocalParameterValue(LOCAL_KEY_UP,&key_up); if(!key_up) key_up=CKKEY_UP; int key_down=0; beh->GetLocalParameterValue(LOCAL_KEY_DOWN,&key_down); if(!key_down) key_down=CKKEY_DOWN; int key_Zin=0; beh->GetLocalParameterValue(LOCAL_KEY_ZIN,&key_Zin); if(!key_Zin) key_Zin=CKKEY_PRIOR; int key_Zout=0; beh->GetLocalParameterValue(LOCAL_KEY_ZOUT,&key_Zout); if(!key_Zout) key_Zout=CKKEY_NEXT; //////////////////// // Position Update //////////////////// // If the users is moving the camera if (((input->IsKeyDown(key_left)) || (input->IsKeyDown(key_right)) || (input->IsKeyDown(key_up)) || (input->IsKeyDown(key_down))) && !stopping) { float SpeedAngle = 0.87f; beh->GetInputParameterValue(IN_SPEED_MOVE,&SpeedAngle); SpeedAngle *= delta / 1000; if (Limited) { float MinH = -PI/2; beh->GetInputParameterValue(IN_MIN_H, &MinH); float MaxH = PI/2; beh->GetInputParameterValue(IN_MAX_H, &MaxH); float MinV = -PI/2; beh->GetInputParameterValue(IN_MIN_V, &MinV); float MaxV = PI/2; beh->GetInputParameterValue(IN_MAX_V, &MaxV); if( input->IsKeyDown(key_right) ) RotationAngles->x += XMin(SpeedAngle, MaxH - RotationAngles->x); if( input->IsKeyDown(key_left) ) RotationAngles->x -= XMin(SpeedAngle, RotationAngles->x - MinH); if( input->IsKeyDown(key_down) ) RotationAngles->y += XMin(SpeedAngle, MaxV - RotationAngles->y); if( input->IsKeyDown(key_up) ) RotationAngles->y -= XMin(SpeedAngle, RotationAngles->y - MinV); } else { if( input->IsKeyDown(key_right) ) RotationAngles->x += SpeedAngle; if( input->IsKeyDown(key_left) ) RotationAngles->x -= SpeedAngle; if( input->IsKeyDown(key_down) ) RotationAngles->y += SpeedAngle; if( input->IsKeyDown(key_up) ) RotationAngles->y -= SpeedAngle; } } else if ((Returns) && ((RotationAngles->x != 0) || (RotationAngles->y != 0))) { float ReturnSpeedAngle = 1.75f; beh->GetInputParameterValue(IN_SPEED_RETURN, &ReturnSpeedAngle); ReturnSpeedAngle *= delta / 1000; if( RotationAngles->x < 0 ) RotationAngles->x += XMin(ReturnSpeedAngle, -RotationAngles->x); if( RotationAngles->x > 0 ) RotationAngles->x -= XMin(ReturnSpeedAngle, RotationAngles->x); if( RotationAngles->y < 0 ) RotationAngles->y += XMin(ReturnSpeedAngle, -RotationAngles->y); if( RotationAngles->y > 0 ) RotationAngles->y -= XMin(ReturnSpeedAngle, RotationAngles->y); } //////////////// // Zoom Update //////////////// if ( (input->IsKeyDown(key_Zin)) || (input->IsKeyDown(key_Zout)) && !stopping ) { float ZoomSpeed = 40.0f; beh->GetInputParameterValue(IN_SPEED_ZOOM, &ZoomSpeed); ZoomSpeed *= delta / 1000; if (Limited) { float MinZoom = -40.0f; beh->GetInputParameterValue(IN_MIN_ZOOM, &MinZoom); float MaxZoom = 10.0f; beh->GetInputParameterValue(IN_MAX_ZOOM, &MaxZoom); if( input->IsKeyDown(key_Zin) ) RotationAngles->z -= XMin(ZoomSpeed, RotationAngles->z + MaxZoom ); if( input->IsKeyDown(key_Zout) ) RotationAngles->z += XMin(ZoomSpeed, - MinZoom - RotationAngles->z); } else { if( input->IsKeyDown(key_Zin) ) RotationAngles->z -= ZoomSpeed; if( input->IsKeyDown(key_Zout) ) RotationAngles->z += ZoomSpeed; } } }