Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/dave/core/environment.cc @ 2624

Last change on this file since 2624 was 2242, checked in by dave, 20 years ago

orxonox/branches/dave: habe wieder mal was gemacht:)

File size: 4.3 KB
Line 
1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer: ...
15   co-programmer: ...
16*/
17
18
19#include "environment.h"
20#include <ostream>
21#include <iostream>
22
23
24using namespace std;
25
26//Sorry Bensch
27#define LEVEL_LENGTH 500
28dVector V1V2,V1V3,Kreuz;
29dVector V1,V2,V3;
30
31Environment::Environment () 
32{
33
34 //Sorry Bensch: x,y = 10
35  for (int x = 0; x < 50; x++)
36    {
37      for (int y = 0; y < 50; y++)
38        {
39          mountainTest[x][y] =0;
40                                                 
41        }
42    }
43  //Sorry Bensch: x,y = 9
44  for (int x = 1; x < LEVEL_LENGTH; x++)
45    {
46      for (int y = 1; y < LEVEL_LENGTH; y++)
47        {
48         //mountainTest[x][y] = (float)random() / 900000000;
49         mountainTest[x][y] = (float)(random() % 2);                                       
50        }
51       
52    }
53}
54
55
56
57Environment::~Environment () {}
58
59
60
61void Environment::drawEnvironment() 
62{
63  glPushMatrix();
64  glEnable(GL_DEPTH_TEST);
65  glEnable(GL_LIGHTING);
66 
67  //glScalef(0.5, 0.5, 1.0);
68  //glTranslatef(xCor, yCor, zCor);
69  glTranslatef( -25.0, -10.0, 0.0);
70 
71  glColor3f(0.6, 0.6, 0.4);
72  glNormal3d(0,0,1);
73  glBegin(GL_TRIANGLES);
74 
75  for (int x=0;x<60;x+=1)
76  {
77    for(int y=-30+DataTank::yOffset;y<40+DataTank::yOffset;y+=1)
78    { 
79     if((int)DataTank::yOffset%2==1)
80      {
81      V1.x=x;V1.y=y;V1.z=mountainTest[x][y];
82      V2.x=x;V2.y=y+1;V2.z=mountainTest[x][y+1];
83      V3.x=x+1;V3.y=y;V3.z=mountainTest[x+1][y];
84      glNormal3d(-(Environment::CalcNormale(&V1,&V2,&V3)).x,-(Environment::CalcNormale(&V1,&V2,&V3)).y,-(Environment::CalcNormale(&V1,&V2,&V3).z));
85     
86      glVertex3f((float)(x),(float)(y),mountainTest[x][y]);
87      glVertex3f((float)(x),(float)(y+1),mountainTest[x][y+1]);
88      glVertex3f((float)(x+1),(float)(y),mountainTest[x+1][y]);
89     
90      V1.x=x;V1.y=y+1;V1.z=mountainTest[x][y+1];
91      V2.x=x+1;V2.y=y+1;V2.z=mountainTest[x+1][y+1];
92      V3.x=x+1;V3.y=y;V3.z=mountainTest[x+1][y];
93      glNormal3d(-(Environment::CalcNormale(&V1,&V2,&V3)).x,-(Environment::CalcNormale(&V1,&V2,&V3)).y,-(Environment::CalcNormale(&V1,&V2,&V3).z));
94     
95      glVertex3f((float)(x),(float)(y+1),mountainTest[x][y+1]);
96      glVertex3f((float)(x+1),(float)(y+1),mountainTest[x+1][y+1]);
97      glVertex3f((float)(x+1),(float)(y),mountainTest[x+1][y]);
98      }
99     else
100     {
101     V1.x=x;V1.y=y+1;V1.z=mountainTest[x][y+1];
102     V2.x=x;V2.y=y+2;V2.z=mountainTest[x][y+2];
103     V3.x=x+1;V3.y=y+1;V3.z=mountainTest[x+1][y+1];
104     glNormal3d(-(Environment::CalcNormale(&V1,&V2,&V3).x),-(Environment::CalcNormale(&V1,&V2,&V3).y),-(Environment::CalcNormale(&V1,&V2,&V3).z));
105     
106     glVertex3f((float)(x),(float)(y+1),mountainTest[x][y+1]);
107     glVertex3f((float)(x),(float)(y+2),mountainTest[x][y+2]);
108     glVertex3f((float)(x+1),(float)(y+1),mountainTest[x+1][y+1]);
109   
110     
111     V1.x=x;V1.y=y+2;V1.z=mountainTest[x][y+2];
112     V2.x=x+1;V2.y=y+2;V2.z=mountainTest[x+1][y+2];
113     V3.x=x+1;V3.y=y+1;V3.z=mountainTest[x+1][y+1];
114     
115     glNormal3d(-(Environment::CalcNormale(&V1,&V2,&V3).x),-(Environment::CalcNormale(&V1,&V2,&V3).y),-(Environment::CalcNormale(&V1,&V2,&V3).z));
116     
117     glVertex3f((float)(x),(float)(y+2),mountainTest[x][y+2]);
118     glVertex3f((float)(x+1),(float)(y+2),mountainTest[x+1][y+2]);
119     glVertex3f((float)(x+1),(float)(y+1),mountainTest[x+1][y+1]); 
120    }}
121   
122   
123  }
124  glEnd();
125  /*glBegin(GL_LINES);
126  for(int y=0+DataTank::yOffset/2;y<25+DataTank::yOffset/2;y+=1)
127  {
128    for(int x=0;x<25;x+=1)
129     {
130     glVertex3f((float)(2*x),(float)(2*y),mountainTest[x][y]);
131     glVertex3f((float)(2*(x+1)),(float)(2*y),mountainTest[x+1][y]);
132     }
133     }
134 
135  glEnd();
136  */
137  glPopMatrix();
138}
139
140
141
142dVector Environment::CalcNormale(dVector *V1, dVector *V2, dVector *V3){
143 GLdouble Betrag;
144 V1V2.x = V2->x - V1->x;
145 V1V2.y = V2->y -V1->y;
146 V1V2.z = V2->z -V1->z;
147 V1V3.x = V3->x -V1->x;
148 V1V3.y = V3->y -V1->y;
149 V1V3.z = V3->z -V1->z;
150 
151 Kreuz.x =+((V1V2.y * V1V3.z) -(V1V2.z * V1V3.y));
152 Kreuz.y =-((V1V2.x *V1V3.z) -(V1V2.z * V1V3.x));
153 Kreuz.z =+((V1V2.x * V1V3.y) - (V1V2.y * V1V3.x));
154 
155 Betrag =sqrt(pow(Kreuz.x, 2) + pow(Kreuz.y,2) +pow(Kreuz.z,2));
156 return Kreuz;
157 }
158 
159 
160 
161 
Note: See TracBrowser for help on using the repository browser.