Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelloader/src/world_entities/environment.cc @ 3542

Last change on this file since 3542 was 3542, checked in by chris, 19 years ago

orxonox/branches/levelloader: First incarnation of a debugworld loaded from a XML-File in place, compilability in place, all necessary basic loading constuctors in place. Unfortunately the code still generates interferences with the old hardcoded debugworld resulting in SegFault crash.

File size: 2.8 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: Patrick Boenzli
15   co-programmer:
16*/
17
18
19#include "environment.h"
20#include "stdincl.h"
21#include "world_entity.h"
22#include "vector.h"
23#include "objModel.h"
24
25using namespace std;
26
27
28CREATE_FACTORY(Environment);
29
30Environment::Environment () : WorldEntity()
31{
32  this->model = new OBJModel("../data/models/fighter.obj");
33}
34
35Environment::Environment ( TiXmlElement* root)
36{
37        char* temp;
38        const char* string = grabParameter( root, "name");
39        if( string == NULL)
40        {
41                PRINTF(1)("Environment is missing a proper 'name'\n");
42                string = "Unknown";
43                temp = new char[strlen(string + 2)];
44                strcpy( temp, string);
45                this->setName( temp);
46        }
47        else
48        {
49                temp = new char[strlen(string + 2)];
50                strcpy( temp, string);
51                this->setName( temp);
52        }
53       
54        this->model = NULL;
55        string = grabParameter( root, "model");
56        if( string != NULL)
57                this->model = new OBJModel( string);
58        else
59        {
60                PRINTF(1)("Environment is missing a proper 'model'\n");
61                this->model = new OBJModel( "../data/models/reaplow.obj");
62        }
63        if( this->model == NULL)
64        {
65                PRINTF(1)("Environment model '%s' could not be loaded\n", string);
66        }
67       
68        double buff[3];
69       
70        string = grabParameter( root, "position");
71        if( string != NULL && sscanf( string, "%f,%f,%f", &(buff[0]), &(buff[1]), &(buff[2])) == 3)
72        {
73                Vector* es = new Vector( buff[0], buff[1], buff[2]);
74                this->setAbsCoor(es);
75                delete es;
76        }
77        else
78        {
79                PRINTF(1)("Environment is missing a proper 'position'\n");
80                Vector* es = new Vector();
81                this->setAbsCoor(es);
82                delete es;
83        }
84       
85        string = grabParameter( root, "orientation");
86        if( string != NULL && sscanf( string, "%f,%f,%f", &(buff[0]), &(buff[1]), &(buff[2])) == 3)
87        {
88                Quaternion* qs = new Quaternion( buff[0], buff[1], buff[2]);
89                this->setAbsDir(qs);
90                delete qs;
91        }
92        else
93        {
94                PRINTF(1)("Environment is missing a proper 'orientation'\n");
95        Quaternion* qs = new Quaternion ();
96                this->setAbsDir(qs);
97                delete qs;
98        }
99}
100
101Environment::~Environment () 
102{
103  delete this->model;
104}
105
106void Environment::tick (float time) {}
107
108void Environment::hit (WorldEntity* weapon, Vector loc) {}
109
110void Environment::destroy () {}
111
112void Environment::collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags) {}
113
114void Environment::draw () 
115{
116  glMatrixMode(GL_MODELVIEW);
117  glLoadIdentity();
118  float matrix[4][4];
119 
120  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
121  //rotate
122  this->getAbsDir().matrix (matrix);
123  glMultMatrixf((float*)matrix);
124 
125  this->model->draw();
126}
127
Note: See TracBrowser for help on using the repository browser.