Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4734 in orxonox.OLD for orxonox/trunk/src


Ignore:
Timestamp:
Jun 29, 2005, 3:05:47 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: light loadable

Location:
orxonox/trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/graphics/light.cc

    r4597 r4734  
    2323#include "vector.h"
    2424#include "debug.h"
     25#include "tinyxml.h"
     26#include "load_param.h"
     27#include "factory.h"
    2528
    2629using namespace std;
    2730
     31CREATE_FACTORY(Light);
     32
    2833//! Definition of the Lights
    29 int lightsV[] = {GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, GL_LIGHT3, GL_LIGHT4, GL_LIGHT5, GL_LIGHT6, GL_LIGHT7};
     34int lightsV[] =
     35{
     36                  GL_LIGHT0,
     37                  GL_LIGHT1,
     38                  GL_LIGHT2,
     39                  GL_LIGHT3,
     40                  GL_LIGHT4,
     41                  GL_LIGHT5,
     42                  GL_LIGHT6,
     43                  GL_LIGHT7
     44};
    3045
    3146
     
    3449*/
    3550Light::Light(int lightNumber)
     51{
     52  this->init(lightNumber);
     53}
     54
     55/**
     56 * \param root The XML-element to load the Light from
     57 */
     58 Light::Light(const TiXmlElement* root)
     59{
     60  this->init(1);
     61  this->loadParams(root);
     62}
     63
     64/**
     65   \brief destroys a Light
     66*/
     67Light::~Light(void)
     68{
     69  glDisable(lightsV[this->lightNumber]);
     70}
     71
     72/**
     73 * \brief initializes a Light
     74 */
     75void Light::init(int lightNumber)
    3676{
    3777  this->setClassID(CL_LIGHT, "Light");
     
    4686  // set values (defaults)
    4787  this->lightNumber = lightNumber;
    48   this->setPosition(0.0, 0.0, 0.0);
     88  this->setPosition(0,0,0);
    4989  this->setDiffuseColor(1.0, 1.0, 1.0);
    5090  this->setSpecularColor(1.0, 1.0, 1.0);
    5191}
    5292
    53 
    54 /**
    55    \brief destroys a Light
    56 */
    57 Light::~Light(void)
    58 {
    59   glDisable(lightsV[this->lightNumber]);
    60 }
    61 
     93/**
     94 * \param root The XML-element to load the Light from
     95 */
     96void Light::loadParams(const TiXmlElement* root)
     97{
     98  static_cast<PNode*>(this)->loadParams(root);
     99
     100  LoadParam<Light>(root, "diffuse-color", this, &Light::setDiffuseColor)
     101      .describe("sets the diffuse color of the Light (red [0-1], green [0-1], blue [0-1])");
     102
     103  LoadParam<Light>(root, "specular-color", this, &Light::setSpecularColor)
     104      .describe("sets the specular color of the Light (red [0-1], green [0-1], blue [0-1])");
     105
     106  LoadParam<Light>(root, "spot-direction", this, &Light::setSpotDirection)
     107      .describe("sets the Direction of the Spot");
     108
     109  LoadParam<Light>(root, "spot-cutoff", this, &Light::setSpotCutoff)
     110      .describe("the cuttoff of the Spotlight");
     111}
    62112
    63113/**
     
    66116   \todo patrick: is it ok to set a Light Position even if it is derived from p_node??
    67117*/
    68 void Light::setPosition(Vector position)
     118void Light::setPosition(const Vector& position)
    69119{
    70120  this->lightPosition[0] = position.x;
     
    107157}
    108158
    109 
    110159/**
    111160   \brief sets an emitting Specular color of this Light
     
    147196   \param direction The direction of the Spot Light.
    148197*/
    149 void Light::setSpotDirection(Vector direction)
     198void Light::setSpotDirection(const Vector& direction)
    150199{
    151200  this->spotDirection[0] = direction.x;
  • orxonox/trunk/src/lib/graphics/light.h

    r4519 r4734  
    1 /*! 
     1/*!
    22    \file light.h
    33    \brief Handles Lights.
     
    2020// FORWARD DEFINITIONS //
    2121class Vector;
    22 
     22class TiXmlElement;
    2323
    2424//! A class that handles Lights. The LightManager operates on this.
     
    2727 public:
    2828  Light(int lightNumber);
     29  Light(const TiXmlElement* root);
    2930  virtual ~Light(void);
    3031
    31   void setPosition(Vector position);
     32  void init(int lightNumber);
     33  void loadParams(const TiXmlElement* root);
     34
     35  void setPosition(const Vector& position);
    3236  void setPosition(GLfloat x, GLfloat y, GLfloat z);
    3337  Vector getPosition() const;
     
    3640  void setSpecularColor(GLfloat r, GLfloat g, GLfloat b);
    3741  void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation);
    38   void setSpotDirection(Vector direction);
     42  void setSpotDirection(const Vector& direction);
     43  void setSpotDirection(float x, float y, float z) { setSpotDirection(Vector(x,y,z)); };
    3944  void setSpotCutoff(GLfloat cutoff);
    4045
    4146  /** \returns the lightNumber*/
    4247  int getLightNumber(void) const {return this->lightNumber;}
    43  
     48
    4449  virtual void draw();
    4550
     
    8994   To redraw the light use
    9095   \li void draw();
    91    
     96
    9297   and to delete one just use
    9398   \li void deleteLight(void);
     
    96101   \li void debug(void) const;
    97102
    98    You can also operate on the single Lights themselves, by first retreaving them with 
     103   You can also operate on the single Lights themselves, by first retreaving them with
    99104   \li Light* getLight(int LightNumber);
    100105   \n
     
    108113  /** \returns a Pointer to the only object of this Class */
    109114  inline static LightManager* getInstance(void) { if (!singletonRef) singletonRef = new LightManager();  return singletonRef; };
     115
     116  void loadParams(const TiXmlElement* root);
    110117
    111118  // set Attributes
     
    132139  Vector getPosition(void) const;
    133140  Vector getPosition(int lightNumber) const;
    134  
     141
    135142  Light* getLight(int lightNumber) const;
    136  
     143
    137144  void debug(void) const;
    138145
     
    141148  LightManager(void);
    142149  void initLight(int LightNumber);
    143  
     150
    144151
    145152 private:
     
    149156  Light**                 lights;             //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues.
    150157  Light*                  currentLight;       //!< The current Light, we are working with.
    151  
     158
    152159};
    153160
  • orxonox/trunk/src/lib/util/substring.cc

    r4597 r4734  
    2727#include <assert.h>
    2828
    29 SubString::SubString( const char* string)
     29SubString::SubString( const char* string, char splitter)
    3030{
    3131  n = 0;
     
    3333  assert( string != NULL);
    3434
    35   for( int i = 0; i < strlen(string); i++) if( string[i] == ',') n++;
     35  for( int i = 0; i < strlen(string); i++) if( string[i] == splitter) n++;
    3636
    3737  n += 1;
     
    4545
    4646  const char* offset = string;
    47   char* end = strchr( string, ',');
     47  char* end = strchr( string, splitter);
    4848  while( end != NULL)
    4949    {
     
    5757      end++;
    5858      offset = end;
    59       end = strchr( offset, ',');
     59      end = strchr( offset, splitter);
    6060    }
    6161
  • orxonox/trunk/src/lib/util/substring.h

    r4597 r4734  
    1111{
    1212 public:
    13   SubString(const char* string);
     13  SubString(const char* string, char splitter = ',');
    1414  ~SubString();
    1515
  • orxonox/trunk/src/util/loading/load_param.cc

    r4637 r4734  
    114114
    115115
    116 int isInt(const char* Int, int defaultValue)
     116int isInt(const char* INT, int defaultValue)
    117117{
    118118  char* endPtr = NULL;
    119   int result = strtol(Int, &endPtr, 10);
    120 
    121   if ( endPtr >= Int && endPtr < Int + strlen(Int))
     119  int result = strtol(INT, &endPtr, 10);
     120
     121  if ( endPtr >= INT && endPtr < INT + strlen(INT))
    122122    return defaultValue;
    123123  else
     
    125125}
    126126
    127 float isFloat(const char* Float, float defaultValue)
     127float isFloat(const char* FLOAT, float defaultValue)
    128128{
    129129  char* endPtr = NULL;
    130   double result = strtod(Float, &endPtr);
    131 
    132   if ( endPtr >= Float && endPtr < Float + strlen(Float))
     130  double result = strtod(FLOAT, &endPtr);
     131
     132  if ( endPtr >= FLOAT && endPtr < FLOAT + strlen(FLOAT))
    133133    return defaultValue;
    134134  else
     
    136136}
    137137
    138 const char* isString(const char* string, const char* defaultValue)
    139 {
    140   if (string != NULL)
    141     return string;
     138const Vector& isVector(const char* VECTOR, const Vector& defaultValue)
     139{
     140
     141
     142}
     143
     144const char* isString(const char* STRING, const char* defaultValue)
     145{
     146  if (STRING != NULL)
     147    return STRING;
    142148  else
    143149    return defaultValue;
  • orxonox/trunk/src/util/loading/load_param.h

    r4726 r4734  
    2323
    2424#include "base_object.h"
     25#include "vector.h"
    2526#include "factory.h"
    2627#include "debug.h"
     
    6970#define l_FLOAT_NAME       "float"              //!< The name of a FLOAT
    7071#define l_FLOAT_DEFAULT    0.0                  //!< a default Value for a FLOAT
     72
     73//#define l_VECTOR_TYPE      const Vector&        //!< The type of a VECTOR
     74//#define l_VECTOR_FUNC      isVector             //!< The function to parse a VECTOR
     75//#define l_VECTOR_NAME      "Vector[x/y/z]"      //!< The name of a VECTOR
     76//#define l_VECTOR_DEFAULT   Vector(0,0,0)        //!< Default value for a VECTOR
    7177
    7278#define l_STRING_TYPE      const char*          //!< The type of a STRING
     
    230236*** HELPER FUNCTIONS ***
    231237***********************/
    232 int           isInt(const char* Int, int defaultValue);
    233 float         isFloat(const char* Float, float defaultValue);
    234 const char*   isString(const char* string, const char* defaultValue);
     238int           isInt(const char* INT, int defaultValue);
     239float         isFloat(const char* FLOAT, float defaultValue);
     240//const Vector& isVector(const char* VECTOR, const Vector& defaultValue);
     241const char*   isString(const char* STRING, const char* defaultValue);
     242
    235243//TiXmlEmlemnt* isXmlElem(const)
    236244
     
    346354  LoadParam5(l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT);
    347355
     356  //! makes functions with one Vector loadable
     357  //LoadParam1(l_VECTOR);
     358
    348359  // loads a Ti-XML-element
    349360  LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(const TiXmlElement*), bool multi = false)
Note: See TracChangeset for help on using the changeset viewer.