Separate some camera related functions, ref #43

This commit is contained in:
kaetemi 2013-06-27 04:11:09 +02:00
parent 8b761cc830
commit 4ef8b7c109
5 changed files with 116 additions and 60 deletions

View file

@ -0,0 +1,85 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <nel/misc/types_nl.h>
#include "camera.h"
#include <nel/3d/stereo_ovr.h>
#include "global.h"
#include "misc.h"
using namespace NLMISC;
using namespace NL3D;
//---------------------------------------------------
// update the camera perspective setup
//---------------------------------------------------
void updateCameraPerspective()
{
float fov, aspectRatio;
computeCurrentFovAspectRatio(fov, aspectRatio);
// change the perspective of the scene
if(!MainCam.empty())
MainCam.setPerspective(fov, aspectRatio, CameraSetupZNear, ClientCfg.Vision);
// change the perspective of the root scene
if(SceneRoot)
{
UCamera cam= SceneRoot->getCam();
cam.setPerspective(fov, aspectRatio, SceneRootCameraZNear, SceneRootCameraZFar);
}
}
void buildCameraClippingPyramid(std::vector<CPlane> &planes)
{
if (StereoDisplay) StereoDisplay->getClippingFrustum(0, &MainCam);
// Compute pyramid in view basis.
CVector pfoc(0,0,0);
const CFrustum &frustum = MainCam.getFrustum();
InvMainSceneViewMatrix = MainCam.getMatrix();
MainSceneViewMatrix = InvMainSceneViewMatrix;
MainSceneViewMatrix.invert();
CVector lb(frustum.Left, frustum.Near, frustum.Bottom );
CVector lt(frustum.Left, frustum.Near, frustum.Top );
CVector rb(frustum.Right, frustum.Near, frustum.Bottom );
CVector rt(frustum.Right, frustum.Near, frustum.Top );
CVector lbFar(frustum.Left, ClientCfg.CharacterFarClip, frustum.Bottom);
CVector ltFar(frustum.Left, ClientCfg.CharacterFarClip, frustum.Top );
CVector rtFar(frustum.Right, ClientCfg.CharacterFarClip, frustum.Top );
planes.resize (4);
// planes[0].make(lbFar, ltFar, rtFar);
planes[0].make(pfoc, lt, lb);
planes[1].make(pfoc, rt, lt);
planes[2].make(pfoc, rb, rt);
planes[3].make(pfoc, lb, rb);
// Compute pyramid in World basis.
// The vector transformation M of a plane p is computed as p*M-1.
// Here, ViewMatrix== CamMatrix-1. Hence the following formula.
uint i;
for (i = 0; i < 4; i++)
{
planes[i] = planes[i]*MainSceneViewMatrix;
}
}
/* end of file */

View file

@ -0,0 +1,29 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef CL_CAMERA_H
#define CL_CAMERA_H
#include <nel/misc/types_nl.h>
#include <nel/misc/plane.h>
void updateCameraPerspective();
void buildCameraClippingPyramid(std::vector<NLMISC::CPlane> &planes);
#endif // CL_CAMERA_H
/* end of file */

View file

@ -142,6 +142,7 @@
// pulled from main_loop.cpp // pulled from main_loop.cpp
#include "ping.h" #include "ping.h"
#include "profiling.h" #include "profiling.h"
#include "camera.h"
#include "main_loop_debug.h" #include "main_loop_debug.h"
#include "main_loop_temp.h" #include "main_loop_temp.h"
#include "main_loop_utilities.h" #include "main_loop_utilities.h"
@ -351,44 +352,6 @@ void displaySceneProfiles();
// validate current dialogs (end them if the player is too far from its interlocutor) // validate current dialogs (end them if the player is too far from its interlocutor)
void validateDialogs(const CGameContextMenu &gcm); void validateDialogs(const CGameContextMenu &gcm);
void buildCameraClippingPyramid (vector<CPlane> &planes)
{
if (StereoDisplay) StereoDisplay->getClippingFrustum(0, &MainCam);
// Compute pyramid in view basis.
CVector pfoc(0,0,0);
const CFrustum &frustum = MainCam.getFrustum();
InvMainSceneViewMatrix = MainCam.getMatrix();
MainSceneViewMatrix = InvMainSceneViewMatrix;
MainSceneViewMatrix.invert();
CVector lb(frustum.Left, frustum.Near, frustum.Bottom );
CVector lt(frustum.Left, frustum.Near, frustum.Top );
CVector rb(frustum.Right, frustum.Near, frustum.Bottom );
CVector rt(frustum.Right, frustum.Near, frustum.Top );
CVector lbFar(frustum.Left, ClientCfg.CharacterFarClip, frustum.Bottom);
CVector ltFar(frustum.Left, ClientCfg.CharacterFarClip, frustum.Top );
CVector rtFar(frustum.Right, ClientCfg.CharacterFarClip, frustum.Top );
planes.resize (4);
// planes[0].make(lbFar, ltFar, rtFar);
planes[0].make(pfoc, lt, lb);
planes[1].make(pfoc, rt, lt);
planes[2].make(pfoc, rb, rt);
planes[3].make(pfoc, lb, rb);
// Compute pyramid in World basis.
// The vector transformation M of a plane p is computed as p*M-1.
// Here, ViewMatrix== CamMatrix-1. Hence the following formula.
uint i;
for (i = 0; i < 4; i++)
{
planes[i] = planes[i]*MainSceneViewMatrix;
}
}
void preRenderNewSky () void preRenderNewSky ()
{ {
CSky &sky = ContinentMngr.cur()->CurrentSky; CSky &sky = ContinentMngr.cur()->CurrentSky;

View file

@ -33,29 +33,11 @@
#include "entities.h" #include "entities.h"
#include "input.h" #include "input.h"
#include "sound_manager.h" #include "sound_manager.h"
#include "camera.h"
using namespace NLMISC; using namespace NLMISC;
using namespace NL3D; using namespace NL3D;
//---------------------------------------------------
// update the camera perspective setup
//---------------------------------------------------
void updateCameraPerspective()
{
float fov, aspectRatio;
computeCurrentFovAspectRatio(fov, aspectRatio);
// change the perspective of the scene
if(!MainCam.empty())
MainCam.setPerspective(fov, aspectRatio, CameraSetupZNear, ClientCfg.Vision);
// change the perspective of the root scene
if(SceneRoot)
{
UCamera cam= SceneRoot->getCam();
cam.setPerspective(fov, aspectRatio, SceneRootCameraZNear, SceneRootCameraZFar);
}
}
//--------------------------------------------------- //---------------------------------------------------
// Compare ClientCfg and LastClientCfg to know what we must update // Compare ClientCfg and LastClientCfg to know what we must update
//--------------------------------------------------- //---------------------------------------------------

View file

@ -24,9 +24,6 @@
// This is mainly for system configuration related functions // This is mainly for system configuration related functions
// such as config file changes. // such as config file changes.
/// does not belong here
void updateCameraPerspective();
/// Compare ClientCfg and LastClientCfg to know what we must update /// Compare ClientCfg and LastClientCfg to know what we must update
void updateFromClientCfg(); void updateFromClientCfg();