Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
s1t1proofofconcept
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Flatland
s1t1proofofconcept
Commits
b45f895d
Commit
b45f895d
authored
Jul 14, 2019
by
Chae Ho Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working version(with inertial movement)
parent
4e42a919
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
229 additions
and
138 deletions
+229
-138
main.cpp
PoC/PoC/main.cpp
+26
-0
mainobserver.cpp
PoC/PoC/mainobserver.cpp
+203
-138
No files found.
PoC/PoC/main.cpp
View file @
b45f895d
#include <iostream>
#include <Windows.h>
#include "mainobserver.h"
int
main
(
void
)
{
auto
dummyobserver
=
Flatland
::
Mainworldobserver
();
auto
x
=
std
::
make_tuple
(
Flatland
::
INERTIAL
,
0.0
,
0.0
,
0.0
,
0.0
,
0
);
auto
player
=
Flatland
::
Player
(
x
);
Flatland
::
Flatlandobject
*
wow
=
&
player
;
dummyobserver
.
objectlist
.
push_back
(
std
::
make_tuple
(
wow
,
std
::
get
<
3
>
(
x
)));
auto
object1
=
Flatland
::
Object1
();
wow
=
&
object1
;
dummyobserver
.
objectlist
.
push_back
(
std
::
make_tuple
(
wow
,
std
::
get
<
3
>
(
object1
.
objecthistory
[
0
])));
while
(
true
)
{
int
x
;
std
::
cin
>>
x
;
//dummyobserver.updatebytick(1.0);
dummyobserver
.
currenttime
+=
1.0
;
player
.
changestate
(
dummyobserver
.
currenttime
);
wow
->
changestate
(
dummyobserver
.
currenttime
);
//dummyobserver.objectlist[1] =
player
.
updatepastlightcone
(
&
dummyobserver
);
std
::
cout
<<
player
.
pastlightcone
<<
std
::
endl
;
}
}
\ No newline at end of file
PoC/PoC/mainobserver.cpp
View file @
b45f895d
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <functional>
#include "mainobserver.h"
#define LIGHTSPEED 10
#define GAMMA(v) (1.0/sqrt(1.0 - (v*v)/(LIGHTSPEED * LIGHTSPEED)))
typedef
std
::
vector
<
double
>
Vec
;
typedef
std
::
vector
<
Vec
>
Mat
;
#define LORENTZ_BOOST(v) (Mat{{GAMMA(v), -GAMMA(v) * (v/LIGHTSPEED)},{-GAMMA(v) * (v/LIGHTSPEED), GAMMA(v)}})
Vec
operator
*
(
const
Mat
&
a
,
const
Vec
&
x
)
{
int
i
,
j
;
...
...
@@ -29,58 +22,23 @@ Vec operator*(const Mat &a, const Vec &x) {
}
namespace
flatland
{
enum
State
{
INERTIAL
,
ACCELERATING
,
};
class
Flatlandobject
{
Flatlandobject
(
/*std::vector<std::tuple<Flatlandobject, double>> theparts,*/
std
::
tuple
<
State
,
double
,
double
,
int
,
double
,
int
>
initialstate
,
Mainworldobserver
*
thegame
)
{
//parts = theparts;
objecthistory
.
push_back
(
initialstate
);
thegame
->
objectlist
.
push_back
(
std
::
make_tuple
(
*
this
,
std
::
get
<
3
>
(
initialstate
)));
}
public:
bool
isPlayer
=
false
;
//std::vector<std::tuple<Flatlandobject, double>> parts = {};
std
::
vector
<
std
::
tuple
<
State
,
double
,
double
,
int
,
double
,
int
>>
objecthistory
=
{};
// state, time(in main observer clock) at statechange, proper time clock at state change, location(in main observer coordinates) at state change,
// velocity(if inertial) relative to mainobserver, proper acceleration(if accelerating)
double
propertime
;
double
currentvelocity
;
int
currentproperacceleration
;
char
name
;
auto
changestate
(
double
maintime
)
->
void
auto
Flatland
::
Player
::
updatepastlightcone
(
Mainworldobserver
*
mainobserver
)
->
void
{
for
(
auto
x
=
0
;
x
<
80
;
++
x
)
{
return
;
pastlightcone
[
x
]
=
'-'
;
}
};
class
Player
:
public
Flatlandobject
{
public:
bool
isPlayer
=
true
;
std
::
vector
<
std
::
tuple
<
Flatlandobject
,
double
>>
world
=
{};
char
pastlightcone
[
81
]
=
"--------------------------------------------------------------------------------"
;
auto
hmm
=
std
::
vector
<
std
::
tuple
<
Flatlandobject
*
,
double
>>
(
mainobserver
->
objectlist
.
begin
()
+
1
,
mainobserver
->
objectlist
.
end
());
auto
updatepastlightcone
(
Mainworldobserver
*
mainobserver
)
->
void
{
for
(
auto
object
:
world
)
for
(
auto
object
:
hmm
)
{
auto
theobject
=
std
::
get
<
0
>
(
object
);
for
(
auto
objectstate
:
theobject
.
objecthistory
)
for
(
auto
it
=
theobject
->
objecthistory
.
begin
();
it
!=
theobject
->
objecthistory
.
end
();
++
it
)
{
auto
objectstate
=
*
it
;
auto
mainclocktimeatstatechange
=
std
::
get
<
1
>
(
objectstate
);
auto
propertimeclockatstatechange
=
std
::
get
<
2
>
(
objectstate
);
auto
maincoordinatelocationatstatechange
=
std
::
get
<
3
>
(
objectstate
);
...
...
@@ -89,83 +47,192 @@ namespace flatland {
if
(
std
::
get
<
0
>
(
objectstate
)
==
INERTIAL
)
{
auto
lightconeeq1
=
std
::
vector
<
double
>
{
LIGHTSPEED
,
mainobserver
->
currenttime
-
std
::
get
<
1
>
(
mainobserver
->
objectlist
[
0
]
)
};
auto
lightconeeq2
=
std
::
vector
<
double
>
{
-
LIGHTSPEED
,
mainobserver
->
currenttime
-
std
::
get
<
1
>
(
mainobserver
->
objectlist
[
0
]
)
};
auto
worldlineeq
=
std
::
vector
<
double
>
{
mainrelativevelocity
,
mainclocktimeatstatechange
-
maincoordinatelocationatstatechange
};
auto
lightconeeq1
=
std
::
vector
<
double
>
{
1.0
,
(
mainobserver
->
currenttime
*
LIGHTSPEED
-
std
::
get
<
1
>
(
mainobserver
->
objectlist
[
0
])
)
};
auto
lightconeeq2
=
std
::
vector
<
double
>
{
-
1.0
,
(
mainobserver
->
currenttime
*
LIGHTSPEED
+
std
::
get
<
1
>
(
mainobserver
->
objectlist
[
0
])
)
};
auto
worldlineeq
=
std
::
vector
<
double
>
{
LIGHTSPEED
/
mainrelativevelocity
,
(
mainclocktimeatstatechange
*
LIGHTSPEED
-
maincoordinatelocationatstatechange
*
(
LIGHTSPEED
/
mainrelativevelocity
))
};
//get intersection points(always exists since v<c)
auto
intersection1
=
std
::
vector
<
double
>
{
(
lightconeeq1
[
0
]
*
worldlineeq
[
1
]
-
worldlineeq
[
0
]
*
lightconeeq1
[
1
])
/
(
lightconeeq1
[
0
]
-
worldlineeq
[
0
]),
(
worldlineeq
[
1
]
-
lightconeeq1
[
1
])
/
(
lightconeeq1
[
0
]
-
worldlineeq
[
0
]),
(
worldlineeq
[
1
]
-
lightconeeq1
[
1
])
/
(
lightconeeq1
[
0
]
-
worldlineeq
[
0
]),
};
auto
intersection2
=
std
::
vector
<
double
>
{
(
lightconeeq2
[
0
]
*
worldlineeq
[
1
]
-
worldlineeq
[
0
]
*
lightconeeq2
[
1
])
/
(
lightconeeq2
[
0
]
-
worldlineeq
[
0
]),
(
worldlineeq
[
1
]
-
lightconeeq2
[
1
])
/
(
lightconeeq2
[
0
]
-
worldlineeq
[
0
]),
};
if
(
mainclocktimeatstatechange
<
intersection1
[
0
]
&&
intersection1
[
0
]
<
mainobserver
->
currenttime
)
//auto & nextobjectstate = *(std::next(it));
auto
lasttime
=
mainobserver
->
currenttime
;
if
(
std
::
next
(
it
)
!=
theobject
->
objecthistory
.
end
())
{
auto
&
nextobjectstate
=
*
(
std
::
next
(
it
));
lasttime
=
std
::
get
<
1
>
(
nextobjectstate
);
}
if
(
mainclocktimeatstatechange
<=
intersection1
[
0
]
/
LIGHTSPEED
&&
intersection1
[
0
]
/
LIGHTSPEED
<
lasttime
)
{
intersection1
=
std
::
vector
<
double
>
{
intersection1
[
0
]
-
mainobserver
->
currenttime
,
intersection1
[
1
]
-
std
::
get
<
1
>
(
mainobserver
->
objectlist
[
0
])
};
intersection1
=
std
::
vector
<
double
>
{
intersection1
[
0
]
-
LIGHTSPEED
*
mainobserver
->
currenttime
,
intersection1
[
1
]
-
std
::
get
<
1
>
(
mainobserver
->
objectlist
[
0
])
};
intersection1
=
LORENTZ_BOOST
(
-
currentvelocity
)
*
intersection1
;
intersection1
[
0
]
=
intersection1
[
0
]
/
LIGHTSPEED
;
if
(
-
40.0
<
intersection1
[
1
]
&&
intersection1
[
1
]
<
40.0
)
{
pastlightcone
[(
int
)
round
(
intersection1
[
1
])]
=
name
;
pastlightcone
[(
int
)
round
(
intersection1
[
1
])]
=
theobject
->
name
;
}
}
if
(
mainclocktimeatstatechange
<
intersection2
[
0
]
&&
intersection2
[
0
]
<
mainobserver
->
curren
ttime
)
if
(
mainclocktimeatstatechange
<=
intersection2
[
0
]
/
LIGHTSPEED
&&
intersection2
[
0
]
/
LIGHTSPEED
<
las
ttime
)
{
intersection2
=
std
::
vector
<
double
>
{
intersection2
[
0
]
-
mainobserver
->
currenttime
,
intersection2
[
1
]
-
std
::
get
<
1
>
(
mainobserver
->
objectlist
[
0
])
};
intersection2
=
std
::
vector
<
double
>
{
intersection2
[
0
]
-
LIGHTSPEED
*
mainobserver
->
currenttime
,
intersection2
[
1
]
-
std
::
get
<
1
>
(
mainobserver
->
objectlist
[
0
])
};
intersection2
=
LORENTZ_BOOST
(
-
currentvelocity
)
*
intersection2
;
intersection2
[
0
]
=
intersection2
[
0
]
/
LIGHTSPEED
;
if
(
-
40.0
<
intersection2
[
1
]
&&
intersection2
[
1
]
<
40.0
)
{
pastlightcone
[(
int
)
round
(
intersection2
[
1
])]
=
name
;
pastlightcone
[(
int
)
round
(
intersection2
[
1
])
+
40
]
=
theobject
->
name
;
}
}
}
else
{
auto
lightconeeq1
=
std
::
vector
<
double
>
{
LIGHTSPEED
,
mainobserver
->
currenttime
-
std
::
get
<
1
>
(
mainobserver
->
objectlist
[
0
])
};
auto
lightconeeq2
=
std
::
vector
<
double
>
{
-
LIGHTSPEED
,
mainobserver
->
currenttime
-
std
::
get
<
1
>
(
mainobserver
->
objectlist
[
0
])
};
auto
lightconeeq1
=
std
::
vector
<
double
>
{
1.0
,
(
mainobserver
->
currenttime
*
LIGHTSPEED
-
std
::
get
<
1
>
(
mainobserver
->
objectlist
[
0
]))
};
auto
lightconeeq2
=
std
::
vector
<
double
>
{
-
1.0
,
(
mainobserver
->
currenttime
*
LIGHTSPEED
+
std
::
get
<
1
>
(
mainobserver
->
objectlist
[
0
]))
};
auto
intersection1
=
std
::
vector
<
double
>
{
0
,
0
};
auto
intersection2
=
std
::
vector
<
double
>
{
0
,
0
};
// point at which mainrelativevelocity is tangent to the acceleration hyperbola (t', x') with (0,0) being v=0
// so (t', x') -> (mainclocktimeatstatechange, maincoordinatelocationatstatechange)
auto
accelerationeqoffset
=
std
::
vector
<
double
>
{
(
LIGHTSPEED
*
GAMMA
(
mainrelativevelocity
)
*
mainrelativevelocity
/
properacceleration
)
-
LIGHTSPEED
*
mainclocktimeatstatechange
,
((
LIGHTSPEED
*
LIGHTSPEED
/
properacceleration
)
*
(
sqrt
((
GAMMA
(
mainrelativevelocity
)
*
mainrelativevelocity
/
LIGHTSPEED
)
*
(
GAMMA
(
mainrelativevelocity
)
*
mainrelativevelocity
/
LIGHTSPEED
)
+
1.0
)
-
1.0
))
-
maincoordinatelocationatstatechange
};
auto
accelerationeq
=
std
::
vector
<
double
>
{};
//change lightcones eq. coord. so that they share (0,0) with acceleration hyperbola with (0,0) being v=0
lightconeeq1
[
1
]
+=
accelerationeqoffset
[
0
]
-
accelerationeqoffset
[
1
];
lightconeeq2
[
1
]
+=
accelerationeqoffset
[
0
]
+
accelerationeqoffset
[
1
];
//change lightcones eq. coord. such that they now share (0,0) with shifted acceleration hyperbola with (0,c^2/a) being v=0
lightconeeq1
[
1
]
+=
(
LIGHTSPEED
*
LIGHTSPEED
/
properacceleration
);
lightconeeq2
[
1
]
+=
(
-
LIGHTSPEED
*
LIGHTSPEED
/
properacceleration
);
auto
lasttime
=
mainobserver
->
currenttime
;
if
(
std
::
next
(
it
)
!=
theobject
->
objecthistory
.
end
())
{
auto
&
nextobjectstate
=
*
(
std
::
next
(
it
));
lasttime
=
std
::
get
<
1
>
(
nextobjectstate
);
}
if
(
lightconeeq1
[
1
]
*
lightconeeq1
[
1
]
>
0.0
)
// determinant for intersection
{
intersection1
[
1
]
=
((
LIGHTSPEED
*
LIGHTSPEED
*
LIGHTSPEED
*
LIGHTSPEED
)
/
(
properacceleration
*
properacceleration
)
+
(
lightconeeq1
[
1
]
*
lightconeeq1
[
1
]))
/
(
2
*
lightconeeq1
[
1
]);
intersection1
[
0
]
=
intersection1
[
1
]
+
lightconeeq1
[
1
];
//shift intersection point x back to main observer coordinates
intersection1
[
1
]
-=
(
accelerationeqoffset
[
1
])
+
((
LIGHTSPEED
*
LIGHTSPEED
)
/
properacceleration
);
//shift intersection point y back to main observer coordinates
intersection1
[
0
]
-=
(
accelerationeqoffset
[
0
]);
if
(
mainclocktimeatstatechange
<=
intersection1
[
0
]
/
LIGHTSPEED
&&
intersection1
[
0
]
/
LIGHTSPEED
<
lasttime
)
{
intersection1
=
std
::
vector
<
double
>
{
intersection1
[
0
]
-
LIGHTSPEED
*
mainobserver
->
currenttime
,
intersection1
[
1
]
-
std
::
get
<
1
>
(
mainobserver
->
objectlist
[
0
])
};
intersection1
=
LORENTZ_BOOST
(
-
currentvelocity
)
*
intersection1
;
intersection1
[
0
]
=
intersection1
[
0
]
/
LIGHTSPEED
;
if
(
-
40.0
<
intersection1
[
1
]
&&
intersection1
[
1
]
<
40.0
)
{
pastlightcone
[(
int
)
round
(
intersection1
[
1
])]
=
theobject
->
name
;
}
}
}
else
if
(
lightconeeq2
[
1
]
*
lightconeeq2
[
1
]
>
0.0
)
{
intersection2
[
1
]
=
((
LIGHTSPEED
*
LIGHTSPEED
*
LIGHTSPEED
*
LIGHTSPEED
)
/
(
properacceleration
*
properacceleration
)
+
(
lightconeeq2
[
1
]
*
lightconeeq2
[
1
]))
/
(
2.0
*
lightconeeq2
[
1
]);
intersection2
[
0
]
=
intersection2
[
1
]
+
lightconeeq2
[
1
];
};
//shift intersection point x back to main observer coordinates
intersection2
[
1
]
-=
(
accelerationeqoffset
[
1
])
-
((
LIGHTSPEED
*
LIGHTSPEED
)
/
properacceleration
);
//shift intersection point y back to main observer coordinates
intersection2
[
0
]
-=
(
accelerationeqoffset
[
0
]);
class
Mainworldobserver
if
(
mainclocktimeatstatechange
<=
intersection2
[
0
]
/
LIGHTSPEED
&&
intersection2
[
0
]
/
LIGHTSPEED
<
lasttime
)
{
public:
intersection2
=
std
::
vector
<
double
>
{
intersection2
[
0
]
-
LIGHTSPEED
*
mainobserver
->
currenttime
,
intersection2
[
1
]
-
std
::
get
<
1
>
(
mainobserver
->
objectlist
[
0
])
};
intersection2
=
LORENTZ_BOOST
(
-
currentvelocity
)
*
intersection2
;
intersection2
[
0
]
=
intersection2
[
0
]
/
LIGHTSPEED
;
std
::
vector
<
std
::
tuple
<
Flatlandobject
,
double
>>
objectlist
=
{};
// first object is always player
//int playervelocity;
double
currenttime
=
0.0
;
if
(
-
40.0
<
intersection2
[
1
]
&&
intersection2
[
1
]
<
40.0
)
{
pastlightcone
[(
int
)
round
(
intersection2
[
1
])]
=
theobject
->
name
;
}
}
}
}
}
auto
updatebytick
(
double
tick
)
->
void
;
//for (auto objectstate : theobject.objecthistory)
//{
//
//}
}
return
;
}
};
auto
Mainworldobserver
::
updatebytick
(
double
tick
)
->
void
auto
Flatland
::
Player
::
changestate
(
double
maintime
)
->
void
{
return
;
}
auto
Flatland
::
Object1
::
changestate
(
double
maintime
)
->
void
{
if
(
maintime
/
5.0
>=
cnt
)
{
this
->
currenttime
+=
tick
;
for
(
std
::
tuple
<
Flatlandobject
,
double
>
a
:
this
->
objectlist
)
for
(
auto
i
=
cnt
;
i
<=
(
maintime
/
5.0
);
++
i
)
{
auto
v
=
2.5
/
sqrt
(
1.0
+
(
2.5
/
LIGHTSPEED
)
*
(
2.5
/
LIGHTSPEED
));
Flatlandobject
::
objecthistory
.
push_back
(
std
::
make_tuple
(
ACCELERATING
,
cnt
*
5
,
GAMMA
(
5.0
)
*
5.0
*
i
,
5.0
,
(
toggle
)
?
-
v
:
v
,
(
toggle
)
?
1
:
-
1
));
toggle
=
!
toggle
;
cnt
++
;
}
}
return
;
}
auto
Flatland
::
Mainworldobserver
::
updatebytick
(
double
tick
)
->
void
{
currenttime
+=
tick
;
auto
cnt
=
0
;
for
(
std
::
tuple
<
Flatlandobject
*
,
double
>
a
:
objectlist
)
{
auto
theobject
=
std
::
get
<
0
>
(
a
);
auto
objectstate
=
theobject
.
objecthistory
.
back
();
auto
objectstate
=
theobject
->
objecthistory
.
back
();
auto
mainclocktimeatstatechange
=
std
::
get
<
1
>
(
objectstate
);
auto
propertimeclockatstatechange
=
std
::
get
<
2
>
(
objectstate
);
auto
maincoordinatelocationatstatechange
=
std
::
get
<
3
>
(
objectstate
);
auto
mainrelativevelocity
=
std
::
get
<
4
>
(
objectstate
);
auto
properacceleration
=
std
::
get
<
5
>
(
objectstate
);
double
newx
;
if
(
std
::
get
<
0
>
(
objectstate
)
==
INERTIAL
)
/*
if (std::get<0>(objectstate) == INERTIAL)
{
newx = maincoordinatelocationatstatechange + mainrelativevelocity * (this->currenttime - mainclocktimeatstatechange);
std::tuple<Flatlandobject, double> newobjectinfo = std::make_tuple(theobject, newx);
...
...
@@ -193,9 +260,7 @@ namespace flatland {
thepart.currentvelocity = theobject.currentvelocity;
}
}*/
theobject
.
changestate
(
this
->
currenttime
);
theobject
->
changestate
(
currenttime
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment