Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
BasicController.cpp
Go to the documentation of this file.
1/*
2--------------------------------------------------------------------------------
3This source file is part of SkyX.
4Visit http://www.paradise-studios.net/products/skyx/
5
6Copyright (C) 2009-2012 Xavier Vergu�n Gonz�lez <xavyiy@gmail.com>
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt.
21--------------------------------------------------------------------------------
22*/
23
24#include "BasicController.h"
25
26namespace 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}
BasicController(const bool &deleteBySkyX=true)
Constructor.
void update(const Ogre::Real &simDeltaTime)
Update controller.
Ogre::Vector3 mSunDirection
Sun direction.
Ogre::Vector2 mEastDirection
East direction (in X,Z world coords)
Ogre::Vector3 mTime
Time information: x = time in [0, 24]h range, y = sunrise hour in [0, 24]h range, z = sunset hour in ...
Ogre::Vector3 mMoonDirection
Moon direction.
Controller base class.
Definition Controller.h:34