1 #include "tux.h"
2
3
4 static float wtmaster [ 6 ][ 2 ] =
5 {
6 { -10000.0f/64.0f, -10000.0f/64.0f },
7 { 10000.0f/64.0f, -10000.0f/64.0f },
8 { -10000.0f/64.0f, 10000.0f/64.0f },
9 { 10000.0f/64.0f, 10000.0f/64.0f },
10 { -10000.0f/64.0f, -10000.0f/64.0f },
11 { 10000.0f/64.0f, -10000.0f/64.0f },
12 } ;
13
update()14 void Ocean::update ()
15 {
16 /* Moving texture for the water. */
17
18 static float e_offset = 0.0f ;
19 static float e_delta = 0.01f;
20 static float u_offset = 0.0f ;
21 static float v_offset = 0.0f ;
22
23 if ( type == OCEAN_WATER || type == OCEAN_LAVA )
24 {
25 e_offset += e_delta ;
26 u_offset += 0.0008 ;
27 v_offset += 0.0005 ;
28
29 if ( e_offset >= 0.2f ||
30 e_offset < -0.1f ) e_delta = -e_delta ;
31
32 if ( u_offset >= 1.0f ) u_offset -= 1.0f ;
33 if ( v_offset >= 1.0f ) v_offset -= 1.0f ;
34
35 for ( int i = 0 ; i < 6 ; i++ )
36 {
37 wtlist [ i ] [ 0 ] = wtmaster [ i ] [ 0 ] + u_offset ;
38 wtlist [ i ] [ 1 ] = wtmaster [ i ] [ 1 ] + u_offset ;
39 wvlist [ i ] [ 2 ] = e_offset ;
40 }
41 }
42 }
43
44
~Ocean()45 Ocean::~Ocean ()
46 {
47 ssgDeRefDelete ( ocean ) ;
48 }
49
Ocean(OceanType t)50 Ocean::Ocean ( OceanType t )
51 {
52 type = t ;
53 ocean = new ssgBranch () ;
54 ocean -> setName ( "Ocean" ) ;
55
56 wvlist = new sgVec3 [ 6 ] ;
57 wtlist = new sgVec2 [ 6 ] ;
58 wnlist = new sgVec3 [ 1 ] ;
59 wclist = new sgVec4 [ 1 ] ;
60
61 float elevation ;
62
63 switch ( type )
64 {
65 case OCEAN_WATER : elevation = 0.0f ; break ;
66 case OCEAN_LAVA : elevation = 0.1f ; break ;
67 case OCEAN_ICE : elevation = 0.1f ; break ;
68 case OCEAN_BLACKHOLE : elevation = -22.0f ; break ;
69 default : elevation = -1000000.0f ; break ;
70 }
71
72 sgSetVec3 ( wvlist [ 0 ], -10000.0f, -10000.0f, elevation ) ;
73 sgSetVec3 ( wvlist [ 1 ], 10000.0f, -10000.0f, elevation ) ;
74 sgSetVec3 ( wvlist [ 2 ], -10000.0f, 10000.0f, elevation ) ;
75 sgSetVec3 ( wvlist [ 3 ], 10000.0f, 10000.0f, elevation ) ;
76 sgSetVec3 ( wvlist [ 4 ], -10000.0f, -10000.0f, elevation ) ;
77 sgSetVec3 ( wvlist [ 5 ], 10000.0f, -10000.0f, elevation ) ;
78
79 sgSetVec3 ( wnlist [ 0 ], 0.0f, 0.0f, 1.0f ) ;
80
81 update () ; /* Computes initial texture position conveniently */
82
83 ssgVTable *wgs = new ssgVTable ( GL_TRIANGLE_STRIP,
84 6, wvlist, 1, wnlist, 6, wtlist, 1, wclist ) ;
85
86 switch ( type )
87 {
88 case OCEAN_WATER : wgs -> setState ( water_gst ) ;
89 sgSetVec4 ( wclist [ 0 ], 1.0f, 1.0f, 1.0f, 0.7f ) ;
90 fprintf(stderr,"Zapping traversal masks!\n" ) ;
91 ocean -> clrTraversalMaskBits ( SSGTRAV_ISECT|SSGTRAV_HOT ) ;
92 break ;
93 case OCEAN_LAVA : wgs -> setState ( lava_gst ) ;
94 sgSetVec4 ( wclist [ 0 ], 1.0f, 1.0f, 1.0f, 1.0f ) ;
95 break ;
96 case OCEAN_ICE : wgs -> setState ( clearice_gst ) ;
97 sgSetVec4 ( wclist [ 0 ], 0.5f, 0.5f, 1.0f, 0.7f ) ;
98 break ;
99 case OCEAN_BLACKHOLE : wgs -> setState ( solidblack_gst ) ;
100 sgSetVec4 ( wclist [ 0 ], 0.0f, 0.0f, 0.0f, 1.0f ) ;
101 break ;
102 }
103
104 ocean -> addKid ( wgs ) ;
105 ocean -> recalcBSphere () ;
106 ocean -> ref () ;
107 }
108
109
110