Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/skysphere.cc @ 3442

Last change on this file since 3442 was 3429, checked in by bensch, 20 years ago

orxonox/trunk: skysphere now produces no more segfault while level changes

File size: 3.0 KB
RevLine 
[3411]1
[3416]2/*
3   orxonox - the future of 3D-vertical-scrollers
4
5   Copyright (C) 2004 orx
6
7   This program is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2, or (at your option)
10   any later version.
11
12   ### File Specific:
13   main-programmer: David Gruetter
[3421]14   co-programmer: Benjamin Grauer
[3416]15
[3421]16    Created by Dave: this file is actually quite similar to player.cc and so is
[3411]17    skybox.h similar to player.h
18    With that said, things should be clear:)
19
[3421]20    Edited by Bensch: more constructors, changeability, comments...
[3411]21
22*/
23
24#include "importer/material.h"
25#include "skysphere.h"
26#include "stdincl.h"
27#include "vector.h"
28#include "world_entity.h"
29
30
31using namespace std;
32
[3416]33/**
34   \brief Standart Constructor
35*/
[3411]36Skysphere::Skysphere()
37{ 
[3419]38  initialize("../data/pictures/sky-replace.jpg");
39}
[3411]40
[3419]41/**
42   \brief Constructs a SkySphere and takes fileName as a map.
43   \param fileName the file to take as input for the skysphere
44*/
45Skysphere::Skysphere(char* fileName)
46{
47  initialize(fileName);
[3411]48}
49
[3416]50/**
51   \brief default destructor
52*/
[3411]53Skysphere::~Skysphere()
54{
[3429]55  PRINTF(3)("Deleting the SkySphere\n");
[3420]56  delete skyMaterial;
[3419]57  free(sphereObj);
58}
[3411]59
[3419]60/**
61   \brief initializes the Skysphere.
62   \param fileName the file to take as input for the skysphere
63*/
64void Skysphere::initialize(char* fileName)
65{
[3429]66  PRINTF(1)("initializing the Skysphere with Material %s.\n", fileName);
[3420]67  this->sphereObj = gluNewQuadric();
68  gluQuadricTexture(this->sphereObj, GL_TRUE);
69  this->setRadius(250.0);
70
71  this->skyMaterial = new Material("Sky");
72  this->setTexture(fileName);
73  this->skyMaterial->setIllum(3);
[3422]74  this->skyMaterial->setAmbient(1.0, 1.0, 1.0);
[3411]75}
76
[3416]77/**
[3420]78   \brief sets the Radius of the Sphere.
79   \param radius The Radius of The Sphere
80*/
81void Skysphere::setRadius(float radius)
82{
83  this->sphereRadius = radius;
84}
85
86/**
87   \brief Defines which texture should be loaded onto the skysphere.
88   \param fileName The filename of the Texture
89*/
90void Skysphere::setTexture(char* fileName)
91{
92  this->skyMaterial->setDiffuseMap(fileName);
93}
94
95/**
[3416]96   \brief updates the position of the Skysphere
97   \param x the x-coordinate of the Center of the Sphere
98   \param y the y-coordinate of the Center of the Sphere
99   \param z the z-coordinate of the Center of the Sphere
[3419]100   
[3416]101   This is normally done in the update-phase of world, so the Skysphere is always centered at the Camera.
102*/
[3419]103void Skysphere::updatePosition(Vector sphereCenter)
[3411]104{
[3419]105  this->sphereCenter = sphereCenter;
[3411]106}
107
[3416]108/**
109   \brief draws the Skysphere
[3419]110   
[3416]111   This part is normally precessed in the "Painting Phase".
112*/
[3419]113
[3411]114void Skysphere::draw()
115{
[3422]116  glEnable(GL_TEXTURE_2D);
[3420]117  skyMaterial->select();
[3419]118  glPushMatrix();
119  glTranslatef(this->sphereCenter.x,this->sphereCenter.y,this->sphereCenter.z);
120 
[3420]121  glRotatef(-30, 1, 0, 0);
122  glRotatef(95.0f, 0.0f, 0.0f, 1.0f);
123  glRotatef(-250.0f, 0.0, 1.0f, 0.0f);
[3419]124 
[3420]125  gluSphere(sphereObj, sphereRadius, 20, 20);
[3419]126  glPopMatrix();
[3422]127  glDisable(GL_TEXTURE_2D);
128
[3411]129}
Note: See TracBrowser for help on using the repository browser.