Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file was 9418, checked in by bensch, 18 years ago

newlines

File size: 1.6 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        children[0] = children[1] = children[2] = children[3] = NULL;
24}
25
26TerrainQuad::TerrainQuad( Terrain *_owner, int _x0, int _z0, int _x1, int _z1 )
27:       owner( _owner ), xOffset( _x0 ), zOffset( _z0 ),
28width( _x1-_x0 ), height( _z1-_z0 )
29{
30        //printf( "%d, %d, %d, %d\n", xOffset, zOffset, width, height );
31        scale = owner->getScale();
32}
33
34int TerrainQuad::cull()
35{
36        return owner->getViewingFrustum()->boxInFrustum( bounds );
37}
38
39/**
40 * Recalculate the bounds of this TerrainQuad. It could be optimized, but how
41 * often is this method really used?
42 */
43void TerrainQuad::calculateBounds()
44{
45        if ( isChildless() ) {
46                printf( "Cannot calculate bounds for a childless terrain quad.\n" );
47                exit( 0 );
48        }
49        Vector min = Vector( children[BL_CHILD]->getBounds().min() );
50        Vector max = Vector( children[TR_CHILD]->getBounds().max() );
51        for ( int i = 1; i < 4; ++i ) {
52                pTerrainQuad child = children[i];
53                min.y = fmin( child->bounds.min().y, min.y );
54                max.y = fmax( child->bounds.max().y, max.y );
55        }
56        bounds.set( min, max );
57}
Note: See TracBrowser for help on using the repository browser.