Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/lib/graphics/importer/terrain/terrain_quad.cc @ 8321

Last change on this file since 8321 was 8319, checked in by ponder, 18 years ago

I know this is a big commit. I'm sorry about that. Anyway…

  • Added the Terrain / TerrainQuad TerrainPage and Frustum classes to the project. The rendering frustum culling is working.
  • The types.h is here only temporary. It should be removed afterwards.
File size: 1.5 KB
Line 
1/*
2        orxonox - the future of 3D-vertical-scrollers
3 
4        Copyright (C) 2006 orx
5 
6        This program is free software; you can redistribute it and/or modify
7        it under the terms of the GNU General Public License as published by
8        the Free Software Foundation; either version 2, or (at your option)
9        any later version.
10 
11        ### File Specific:
12        main programmer: Marco Biasini
13 
14 */
15#include "terrain_quad.h"
16#include "terrain.h"
17#include <math.h>
18
19TerrainQuad::TerrainQuad( Terrain *_owner, int _xOffset, int _zOffset )
20: owner( _owner ), xOffset( _xOffset ), zOffset( _zOffset ), width( 1 ), height( 1 )
21{
22        scale = owner->getScale();
23}
24
25TerrainQuad::TerrainQuad( Terrain *_owner, int _x0, int _z0, int _x1, int _z1 )
26:       owner( _owner ), xOffset( _x0 ), zOffset( _z0 ), 
27width( _x1-_x0 ), height( _z1-_z0 )
28{
29        //printf( "%d, %d, %d, %d\n", xOffset, zOffset, width, height );
30        scale = owner->getScale();
31}
32
33int TerrainQuad::cull()
34{
35        return owner->getViewingFrustum()->boxInFrustum( bounds );
36}
37
38/**
39 * Recalculate the bounds of this TerrainQuad. It could be optimized, but how
40 * often is this method really used?
41 */
42void TerrainQuad::calculateBounds()
43{
44        if ( isChildless() ) {
45                printf( "Cannot calculate bounds for a childless terrain quad.\n" );
46                exit( 0 );
47        }       
48        Triple min = Triple( children[BL_CHILD]->getBounds().min() );
49        Triple max = Triple( children[TR_CHILD]->getBounds().max() );
50        for ( int i = 1; i < 4; ++i ) {
51                pTerrainQuad child = children[i];
52                min.y = fmin( child->bounds.min().y, min.y );
53                max.y = fmax( child->bounds.max().y, max.y );           
54        }
55        bounds.set( min, max );
56}
Note: See TracBrowser for help on using the repository browser.