RigsofRods
Soft-body Physics Simulation
BasicController.cpp
Go to the documentation of this file.
1 /*
2 --------------------------------------------------------------------------------
3 This source file is part of SkyX.
4 Visit http://www.paradise-studios.net/products/skyx/
5 
6 Copyright (C) 2009-2012 Xavier Verguín González <xavyiy@gmail.com>
7 
8 This program is free software; you can redistribute it and/or modify it under
9 the terms of the GNU Lesser General Public License as published by the Free Software
10 Foundation; either version 2 of the License, or (at your option) any later
11 version.
12 
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License along with
18 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20 http://www.gnu.org/copyleft/lesser.txt.
21 --------------------------------------------------------------------------------
22 */
23 
24 #include "BasicController.h"
25 
26 namespace SkyX
27 {
28  BasicController::BasicController(const bool& deleteBySkyX)
29  : Controller(deleteBySkyX)
30  , mTime(Ogre::Vector3(14.0f, 7.50f, 20.50f))
31  , mSunDirection(Ogre::Vector3(0,1,0))
32  , mMoonDirection(Ogre::Vector3(0,-1,0))
33  , mEastDirection(Ogre::Vector2(0,1))
34  , mMoonPhase(0)
35  {
36  }
37 
38  void BasicController::update(const Ogre::Real& simDeltaTime)
39  {
40  mTime.x += simDeltaTime;
41 
42  if (mTime.x > 24)
43  {
44  mTime.x -= 24;
45  }
46  else if (mTime.x < 0)
47  {
48  mTime.x += 24;
49  }
50 
51  // 24h day:
52  // 0______A(Sunrise)_______B(Sunset)______24
53  //
54 
55  float y,
56  X = mTime.x,
57  A = mTime.y,
58  B = mTime.z,
59  AB = A+24-B,
60  AB_ = B-A,
61  XB = X+24-B;
62 
63  if (X<A || X>B)
64  {
65  if (X<A)
66  {
67  y = -XB / AB;
68  }
69  else
70  {
71  y = -(X-B) / AB;
72  }
73 
74  if (y > -0.5f)
75  {
76  y *= 2;
77  }
78  else
79  {
80  y = -(1 + y)*2;
81  }
82  }
83  else
84  {
85  y = (X-A)/(B-A);
86 
87  if (y < 0.5f)
88  {
89  y *= 2;
90  }
91  else
92  {
93  y = (1 - y)*2;
94  }
95  }
96 
97  Ogre::Vector2 East = mEastDirection;
98 
99  if (X > A && X < B)
100  {
101  if (X > (A + AB_/2))
102  {
103  East = -East;
104  }
105  }
106  else
107  {
108  if (X<=A)
109  {
110  if (XB < (24-AB_)/2)
111  {
112  East = -East;
113  }
114  }
115  else
116  {
117  if ((X-B) < (24-AB_)/2)
118  {
119  East = -East;
120  }
121  }
122  }
123 
124  float ydeg = (Ogre::Math::PI/2)*y,
125  sn = Ogre::Math::Sin(ydeg),
126  cs = Ogre::Math::Cos(ydeg);
127 
128  mSunDirection = Ogre::Vector3(East.x*cs, sn, East.y*cs);
130  }
131 }
SkyX::BasicController::mTime
Ogre::Vector3 mTime
Time information: x = time in [0, 24]h range, y = sunrise hour in [0, 24]h range, z = sunset hour in ...
Definition: BasicController.h:117
BasicController.h
y
float y
Definition: (ValueTypes) quaternion.h:6
SkyX::BasicController::BasicController
BasicController(const bool &deleteBySkyX=true)
Constructor.
Definition: BasicController.cpp:28
SkyX
Definition: AtmosphereManager.cpp:30
SkyX::BasicController::mEastDirection
Ogre::Vector2 mEastDirection
East direction (in X,Z world coords)
Definition: BasicController.h:119
SkyX::BasicController::mMoonDirection
Ogre::Vector3 mMoonDirection
Moon direction.
Definition: BasicController.h:124
SkyX::BasicController::update
void update(const Ogre::Real &simDeltaTime)
Update controller.
Definition: BasicController.cpp:38
SkyX::BasicController::mSunDirection
Ogre::Vector3 mSunDirection
Sun direction.
Definition: BasicController.h:122
SkyX::Controller
Controller base class.
Definition: Controller.h:33
Ogre
Definition: ExtinguishableFireAffector.cpp:35