source: OGRE/trunk/ogre_changes/Plugins/OctreeSceneManager/src/OgreOctreeCamera.cpp @ 61

Revision 61, 3.4 KB checked in by mattausch, 20 years ago (diff)
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25/***************************************************************************
26octreecamera.cpp  -  description
27-------------------
28begin                : Fri Sep 27 2002
29copyright            : (C) 2002 by Jon Anderson
30email                : janders@users.sf.net
31
32Enhancements 2003 - 2004 (C) The OGRE Team
33
34***************************************************************************/
35#include <OgreMath.h>
36#include <OgreAxisAlignedBox.h>
37#include <OgreRoot.h>
38
39#include <OgreOctreeCamera.h>
40
41namespace Ogre
42{
43OctreeCamera::OctreeCamera( const String& name, SceneManager* sm ) : Camera( name, sm )
44{
45                                                                     
46}
47
48OctreeCamera::~OctreeCamera()
49{
50}
51
52OctreeCamera::Visibility OctreeCamera::getVisibility( const AxisAlignedBox &bound )
53{
54
55    // Null boxes always invisible
56    if ( bound.isNull() )
57        return NONE;
58
59    // Make any pending updates to the calculated frustum
60    updateView();
61
62    // Get corners of the box
63    const Vector3* pCorners = bound.getAllCorners();
64
65    // For each plane, see if all points are on the negative side
66    // If so, object is not visible.
67    // If one or more are, it's partial.
68    // If all aren't, full
69
70    int corners[ 8 ] = {0, 4, 3, 5, 2, 6, 1, 7};
71
72    int planes[ 6 ] = {FRUSTUM_PLANE_TOP, FRUSTUM_PLANE_BOTTOM,
73                       FRUSTUM_PLANE_LEFT, FRUSTUM_PLANE_RIGHT,
74                       FRUSTUM_PLANE_FAR, FRUSTUM_PLANE_NEAR };
75
76    bool all_inside = true;
77
78    for ( int plane = 0; plane < 6; ++plane )
79    {
80
81        // Skip far plane if infinite view frustum
82        if (mFarDist == 0 && planes[ plane ] == FRUSTUM_PLANE_FAR)
83            continue;
84
85        bool all_outside = true;
86
87        float distance = 0;
88
89        for ( int corner = 0; corner < 8; ++corner )
90        {
91            distance = mFrustumPlanes[ planes[ plane ] ].getDistance( pCorners[ corners[ corner ] ] );
92            all_outside = all_outside && ( distance < 0 );
93            all_inside = all_inside && ( distance >= 0 );
94
95            if ( !all_outside && !all_inside )
96                break;
97        }
98
99        if ( all_outside )
100            return NONE;
101    }
102
103    if ( all_inside )
104        return FULL;
105    else
106        return PARTIAL;
107
108}
109
110}
111
112
113
114
Note: See TracBrowser for help on using the repository browser.