summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorConstantin Riß <constantin.riss@dre.de>2010-02-10 22:30:18 +0100
committerConstantin Riß <constantin.riss@dre.de>2010-02-10 22:30:18 +0100
commit22b2912bbdd637c1a206b30f7d02c8e560ff9850 (patch)
tree33889a87dc0bce5e5380d0d88b95c9fb623b7685
parent897a54945c4a9112ee5c97e2eb8937adc57f17fe (diff)
downloadc3d-22b2912bbdd637c1a206b30f7d02c8e560ff9850.tar
c3d-22b2912bbdd637c1a206b30f7d02c8e560ff9850.zip
veränderungen
-rw-r--r--CMakeLists.txt1
-rw-r--r--DisplayClass.cpp116
-rw-r--r--DisplayClass.h11
-rw-r--r--Temparray.cpp39
-rw-r--r--Temparray.h3
-rw-r--r--main.cpp140
6 files changed, 218 insertions, 92 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d68742c..2df99b0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,6 +11,7 @@ add_executable(c3d
DisplayClass.cpp DisplayClass.h
gl.h
House.h House.cpp
+ Keys.h
main.cpp
Sun.h Sun.cpp
Temparray.h Temparray.cpp
diff --git a/DisplayClass.cpp b/DisplayClass.cpp
index b34156b..a031946 100644
--- a/DisplayClass.cpp
+++ b/DisplayClass.cpp
@@ -2,13 +2,8 @@
DisplayClass::Renderer DisplayClass::render;
-DisplayClass::DisplayClass(int x, int y, int z) : angle(0) {
-
-// Temparray temp(20, x, y, z);
-// triangles=temp.getTriangles();
-this->x=x;
-this->y=y;
-this->z=z;
+DisplayClass::DisplayClass(int x0, int y0, int z0) : angleY(0), angleX(0), distance(20),
+ x(x0), y(y0), z(z0) {
//tree = new BSPTree(triangles);
}
@@ -16,26 +11,22 @@ DisplayClass::~DisplayClass() {
//delete tree;
}
-void DisplayClass::renderScene(unsigned long delta, std::bitset<256>& keys) {
- angle += delta*0.005;
- if(angle >= 360)
- angle -= 360;
+void DisplayClass::renderScene(unsigned long delta, const Keyset &keys) {
+ handleKeys(delta, keys);
- static bool on = true;
+ /*static bool on = true;
static float angle2 =5;
if (angle2 <= 10 && on){angle2 += 0.5;}
else if (angle2 >=0 && !on){angle2 -= 0.5;}
else if (angle2 >=10)on=false;
- else if (angle2 <=0)on=true;
+ else if (angle2 <=0)on=true;*/
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-// keyhandler(keys);
-
glLoadIdentity(); // Clean up matrix
- glTranslatef(0.0, -2.0, -12.0); // Then set up transformation
- glRotatef(angle2, 1.0, 0.0, 0.0);
- glRotatef(angle, 0.0, 1.0, 0.0);
+ glTranslatef(0.0, -distanceh, -distance); // Then set up transformation
+ glRotatef(angleX, 1.0, 0.0, 0.0);
+ glRotatef(angleY, 0.0, 1.0, 0.0);
// glRotatef(angle*2, 1.0, 0.0, 0.0);
// glRotatef(angle*3, 1.0, 0.5, 0.0);
// glRotatef(-angle*5, 1.0, 1.0, 0.0);
@@ -45,7 +36,7 @@ void DisplayClass::renderScene(unsigned long delta, std::bitset<256>& keys) {
static House house(20, x, y, z, 100, 400, 53.55, 0.82, 2.82, 0.0047, 40, 45, 1900, 3, 11500);
triangles=house.getTriangles();
house.controller();
-//// temp.calcTemp();
+// temp.calcTemp();
//vmml::mat4f transform, inverseTransform;
//glGetFloatv(GL_MODELVIEW_MATRIX, transform.array);
@@ -65,46 +56,51 @@ void DisplayClass::renderScene(unsigned long delta, std::bitset<256>& keys) {
glFlush();
}
-void DisplayClass::keyhandler(std::bitset<256>& keys){
- static float abstand = 0;
- if(keys.any()) {
- glLoadIdentity();
-
- static float rotm[16] = {
- 1, 0, 0, 0,
- 0, 1, 0, 0,
- 0, 0, 1, 0,
- 0, 0, 0, 1};
- char h = '2';
- if(keys.test(50))
- glRotatef(3, 1, 0, 0);
-
- h = '4';
- if(keys.test(52))
- glRotatef(-3, 0, 1, 0);
-
- h = '6';
- if(keys.test(54))
- glRotatef(3, 0, 1, 0);
-
- h = '8';
- if(keys.test(56))
- glRotatef(-3, 1, 0, 0);
-
- h = '+';
- if(keys.test(43))
- abstand -= 0.2;
-
- h = '-';
- if(keys.test(45))
- abstand += 0.2;
-
- glMultMatrixf(rotm);
- glGetFloatv(GL_MODELVIEW_MATRIX, rotm);
-
- glLoadIdentity();
- glTranslatef(0, 0, abstand);
- glMultMatrixf(rotm);
-// glutPostRedisplay();
+void DisplayClass::handleKeys(unsigned long delta, const Keyset &keys) {
+ /*angle += delta*0.005;
+ if(angle >= 360)
+ angle -= 360;*/
+
+ if(keys.test(KEY_UP)) {
+ angleX += 0.005*delta;
+ }
+
+ if(keys.test(KEY_DOWN)) {
+ angleX -= 0.005*delta;
+ }
+
+ if(keys.test(KEY_LEFT)) {
+ angleY += 0.005*delta;
+ }
+
+ if(keys.test(KEY_RIGHT)) {
+ angleY -= 0.005*delta;
}
+
+ if(keys.test(KEY_ZOOM_IN)) {
+ distance -= 0.005*delta;
+ }
+
+ if(keys.test(KEY_ZOOM_OUT)) {
+ distance += 0.005*delta;
+ }
+
+ if(keys.test(KEY_TOP)) {
+ distanceh -= 0.0005*delta;
+ }
+
+ if(keys.test(KEY_BOTTOM)) {
+ distanceh += 0.0005*delta;
+ }
+
+
+ if(angleX >= 360)
+ angleX -= 360;
+ else if(angleX < 0)
+ angleX += 360;
+
+ if(angleY >= 360)
+ angleY -= 360;
+ else if(angleY < 0)
+ angleY += 360;
}
diff --git a/DisplayClass.h b/DisplayClass.h
index 5b646ed..ee245af 100644
--- a/DisplayClass.h
+++ b/DisplayClass.h
@@ -1,12 +1,10 @@
#ifndef _DISPLAYCLASS_H_
#define _DISPLAYCLASS_H_
-//#include "Cubehole.h"
-//#include "Temparray.h"
#include "BSPTree.h"
#include "gl.h"
#include "House.h"
-#include <bitset>
+#include "Keys.h"
class DisplayClass
{
@@ -14,7 +12,7 @@ class DisplayClass
DisplayClass(int x, int y, int z);
virtual ~DisplayClass();
- void renderScene(unsigned long delta, std::bitset<256>& keys);
+ void renderScene(unsigned long delta, const Keyset &keys);
private:
struct Renderer {
@@ -25,11 +23,12 @@ class DisplayClass
static Renderer render;
- float angle;
+ float angleY, angleX;
+ float distance, distanceh;
int x, y, z;
//Cubehole cubehole0, cubehole1, cubehole2, cubehole3, cubehole4, cubehole5;
std::list<Triangle> triangles;
- void keyhandler(std::bitset<256>& keys);
+ void handleKeys(unsigned long delta, const Keyset &keys);
//BSPTree *tree;
};
#endif /*_DISPLAYCLASS_H_*/
diff --git a/Temparray.cpp b/Temparray.cpp
index 17889ae..115d199 100644
--- a/Temparray.cpp
+++ b/Temparray.cpp
@@ -240,7 +240,7 @@ void Temparray::calcTemp(){
temperatureold(i, j-1, k, l, m))*(1-exp(-(1/tau21))));
}
- /*if(m == 0) {
+ if(m == 0) {
area = (sqrt(pow((depth-innerdepth)/2, 2) + pow((width-innerwidth)/2, 2))* height) /
0.9 * meterperunit;
@@ -331,8 +331,8 @@ void Temparray::calcTemp(){
temperaturenew(i, j, k, l, 0) =
temperaturenew(i, j, k, l, 0) + ((temperatureold(i, j, k, l, 3) -
temperatureold(i, j, k, l, 0))*(1-exp(-(1/tau21))));
- }*/
- if(j == sy-1) {
+ }
+ if(j == 0) {
if(m % 2 == 0)area = (((depth - innerdepth)/2)*((width + innerwidth)/2))
/ 0.9 * meterperunit;
if(m % 2 == 1)area = (((width - innerwidth)/2)*((depth + innerdepth)/2))
@@ -349,8 +349,29 @@ void Temparray::calcTemp(){
tau12 = capacity * thermalresistance;
- temperaturenew(i, j, k, 0, m) =
- temperaturenew(i, j, k, 0, m) - ((temperatureold(i, j, k, 0, m) - earthtemp)
+ temperaturenew(i, j, k, l, m) =
+ temperaturenew(i, j, k, l, m) - ((temperatureold(i, j, k, l, m) - earthtemp)
+ *(1-exp(-(1/tau12))));
+ }
+ if(j == sy-1) {
+ if(m % 2 == 0)area = (((depth - innerdepth)/2)*((width + innerwidth)/2))
+ / 0.9 * meterperunit;
+ if(m % 2 == 1)area = (((width - innerwidth)/2)*((depth + innerdepth)/2))
+ / 0.9 * meterperunit;
+
+ thermalresistance = (3 + height/2) / 0.9 * meterperunit /(conductivity * area);
+
+ if(m % 2 == 0)capacity = specificcapacity *((((depth - innerdepth)/2)*
+ ((width + innerwidth)/2)*height)
+ / 0.9 * meterperunit);
+ if(m % 2 == 1)capacity = specificcapacity *((((width - innerwidth)/2)*
+ ((depth + innerdepth)/2)*height)
+ / 0.9 * meterperunit);
+
+ tau12 = capacity * thermalresistance;
+
+ temperaturenew(i, j, k, l, m) =
+ temperaturenew(i, j, k, l, m) - ((temperatureold(i, j, k, l, m) - basementtemp)
*(1-exp(-(1/tau12))));
}
}
@@ -379,8 +400,8 @@ void Temparray::calcTemp(){
temperatureold(i-1, j, k, 0, 3))*(1-exp(-(1/tau12))));
}
if (i == 0 || i == sx-1) {
- int h=3;
- if(i == sx-1) h=1;
+ int h=1;
+ if(i == sx-1) h=3;
width = cubehole(i, j, k, 0).getWidth();
height = cubehole(i, j, k, 0).getHeight();
@@ -425,8 +446,8 @@ void Temparray::calcTemp(){
temperatureold(i, j, k-1, 0, 0))*(1-exp(-(1/tau12))));
}
if(k == 0 || k == sz-1) {
- int h=0;
- if(i == sz-1) h=2;
+ int h=2;
+ if(k == sz-1) h=0;
width = cubehole(i, j, k, 0).getWidth();
height = cubehole(i, j, k, 0).getHeight();
diff --git a/Temparray.h b/Temparray.h
index 19040a2..ed5813e 100644
--- a/Temparray.h
+++ b/Temparray.h
@@ -32,7 +32,7 @@ class Temparray
float *temparrayold, *temparraynew;
Cubehole *cubearray;
int sx, sy, sz, *weight1, maxweight;
- float averagetemp, earthtemp, probetemp, input, inputpower, factor;
+ float averagetemp, earthtemp, probetemp, input, inputpower, factor, basementtemp;
Cubehole& cubehole(int x, int y, int z, int line) {
return cubearray[x*sy*sz*6 + y*sz*6 + z*6 + line];
@@ -61,6 +61,7 @@ class Temparray
}
}
earthtemp=8;
+ basementtemp=20;
}
void calcAverage(){
float tempcache = 0;
diff --git a/main.cpp b/main.cpp
index 062950c..a786e85 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,7 +1,8 @@
#include "DisplayClass.h"
#include "gl.h"
-#include <cstdlib>
-#include <bitset>
+#include "Keys.h"
+//#include <cstdlib>
+//#include <bitset>
#ifdef _WIN32
#else
@@ -20,7 +21,7 @@
//#define DEFAULT_HEIGHT 200
//#define DEFAULT_WIDTH 200
-std::bitset<256> keys;
+Keyset keys;
void initGL(bool multisample);
void resize(int width, int height);
@@ -36,7 +37,7 @@ void initGL(bool multisample) {
#ifndef _WIN32
if(multisample)
- glDisable(GL_MULTISAMPLE_ARB);
+ glEnable(GL_MULTISAMPLE_ARB);
#endif
resize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
@@ -260,12 +261,65 @@ LRESULT CALLBACK wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
return 0;
case WM_KEYDOWN:
- keys.set(wParam, true);
- return 0;
-
case WM_KEYUP:
- keys.set(wParam, false);
- return 0;
+ bool pressed = (uMsg == WM_KEYDOWN);
+
+ switch(wParam) {
+ case VK_Escape:
+ PostQuitMessage(0);
+ break;
+ case VK_Up:
+ case VK_W:
+ case VK_KP_8:
+ case VK_KP_Up:
+ keys.set(KEY_UP, pressed);
+ break;
+
+ case VK_Left:
+ case VK_A:
+ case VK_KP_4:
+ case VK_KP_Left:
+ keys.set(KEY_LEFT, pressed);
+ break;
+
+ case VK_Right:
+ case VK_D:
+ case VK_KP_6:
+ case VK_KP_Right:
+ keys.set(KEY_RIGHT, pressed);
+ break;
+
+ case VK_Down:
+ case VK_S:
+ case VK_KP_2:
+ case VK_KP_Down:
+ keys.set(KEY_DOWN, pressed);
+ break;
+
+ case VK_Page_Up:
+ case VK_minus:
+ case VK_KP_Subtract:
+ case VK_KP_Page_Up:
+ keys.set(KEY_ZOOM_OUT, pressed);
+ break;
+
+ case VK_Page_Down:
+ case VK_plus:
+ case VK_KP_Add:
+ case VK_KP_Page_Down:
+ keys.set(KEY_ZOOM_IN, pressed);
+ break;
+
+ case VK_HOME:
+ case VK_KP_HOME:
+ keys.set(KEY_TOP, pressed);
+ break;
+
+ case VK_END:
+ case VK_KP_END:
+ keys.set(KEY_BOTTOM, pressed);
+ break;
+ }
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
@@ -313,7 +367,7 @@ bool GLXinit(Display *disp, Atom windele, Window *wnd, GLXContext *gc, bool *mul
XSetWindowAttributes swa;
swa.colormap = cmap;
swa.border_pixel = 0;
- swa.event_mask = StructureNotifyMask/* | PointerMotionMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask*/;
+ swa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask/* | PointerMotionMask | ButtonPressMask | ButtonReleaseMask*/;
*wnd = XCreateWindow(disp, RootWindow(disp, vi->screen), 0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT, 0, vi->depth, InputOutput,
vi->visual, CWBorderPixel|CWColormap|CWEventMask, &swa);
@@ -386,6 +440,7 @@ int main(int argc, char *argv[]) {
while(XPending(disp)) {
XEvent event;
XNextEvent(disp, &event);
+
switch(event.type) {
case ConfigureNotify:
resize(event.xconfigure.width, event.xconfigure.height);
@@ -397,13 +452,66 @@ int main(int argc, char *argv[]) {
break;
case KeyPress:
- keys.set(event.xkey.keycode, true);
- if(XKeycodeToKeysym(disp, event.xkey.keycode, 0) == XK_Escape) running = false;
-
- break;
-
case KeyRelease:
- keys.set(event.xkey.keycode, false);
+ KeySym keysym = XKeycodeToKeysym(disp, event.xkey.keycode, 0);
+ bool pressed = (event.type == KeyPress);
+
+ switch(keysym) {
+ case XK_Escape:
+ running = false;
+ break;
+ case XK_Up:
+ case XK_w:
+ case XK_KP_8:
+ case XK_KP_Up:
+ keys.set(KEY_UP, pressed);
+ break;
+
+ case XK_Left:
+ case XK_a:
+ case XK_KP_4:
+ case XK_KP_Left:
+ keys.set(KEY_LEFT, pressed);
+ break;
+
+ case XK_Right:
+ case XK_d:
+ case XK_KP_6:
+ case XK_KP_Right:
+ keys.set(KEY_RIGHT, pressed);
+ break;
+
+ case XK_Down:
+ case XK_s:
+ case XK_KP_2:
+ case XK_KP_Down:
+ keys.set(KEY_DOWN, pressed);
+ break;
+
+ case XK_Page_Up:
+ case XK_minus:
+ case XK_KP_Subtract:
+ case XK_KP_Page_Up:
+ keys.set(KEY_ZOOM_OUT, pressed);
+ break;
+
+ case XK_Page_Down:
+ case XK_plus:
+ case XK_KP_Add:
+ case XK_KP_Page_Down:
+ keys.set(KEY_ZOOM_IN, pressed);
+ break;
+
+ case XK_Home:
+ case XK_KP_Home:
+ keys.set(KEY_TOP, pressed);
+ break;
+
+ case XK_End:
+ case XK_KP_End:
+ keys.set(KEY_BOTTOM, pressed);
+ break;
+ }
}
}