mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-21 20:09:00 -05:00
Coordinate transformation with kameleon
This commit is contained in:
@@ -28,7 +28,6 @@ return {
|
||||
--"gridGalactic",
|
||||
--"gridEcliptic",
|
||||
--"gridEquatorial",
|
||||
"iswa",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
return {
|
||||
{
|
||||
Name = "iSWA",
|
||||
Parent = "Root",
|
||||
Ephemeris = {
|
||||
Type = "Spice",
|
||||
Body = "Sun",
|
||||
Observer = "Earth",
|
||||
Kernels = {
|
||||
"${SPICE}/iSWAKernels/heliospheric.tf",
|
||||
"${SPICE}/iSWAKernels/GSE.ti",
|
||||
"${SPICE}/iSWAKernels/GSM.ti",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,9 +46,9 @@ void CygnetPlane::render(const RenderData& data){
|
||||
psc position = data.position;
|
||||
glm::mat4 transform = glm::mat4(1.0);
|
||||
|
||||
glm::mat4 rotx = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(1, 0, 0));
|
||||
glm::mat4 roty = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, -1, 0));
|
||||
glm::mat4 rotz = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, 0, 1));
|
||||
// glm::mat4 rotx = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(1, 0, 0));
|
||||
// glm::mat4 roty = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, -1, 0));
|
||||
// glm::mat4 rotz = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, 0, 1));
|
||||
|
||||
glm::mat4 rot = glm::mat4(1.0);
|
||||
for (int i = 0; i < 3; i++){
|
||||
@@ -59,25 +59,25 @@ void CygnetPlane::render(const RenderData& data){
|
||||
|
||||
|
||||
// Correct for the small error of x-axis not pointing directly at the sun
|
||||
if(_data->frame == "GSM"){
|
||||
// if(_data->frame == "GSM"){
|
||||
|
||||
transform = transform * rotz * roty; //BATSRUS
|
||||
// transform = transform * rotz * roty; //BATSRUS
|
||||
|
||||
glm::vec4 v(1,0,0,1);
|
||||
glm::vec3 xVec = glm::vec3(transform*v);
|
||||
xVec = glm::normalize(xVec);
|
||||
// glm::vec4 v(1,0,0,1);
|
||||
// glm::vec3 xVec = glm::vec3(transform*v);
|
||||
// xVec = glm::normalize(xVec);
|
||||
|
||||
double lt;
|
||||
glm::vec3 sunVec =
|
||||
SpiceManager::ref().targetPosition("Sun", "Earth", "GALACTIC", {}, _openSpaceTime, lt);
|
||||
sunVec = glm::normalize(sunVec);
|
||||
// double lt;
|
||||
// glm::vec3 sunVec =
|
||||
// SpiceManager::ref().targetPosition("Sun", "Earth", "GALACTIC", {}, _openSpaceTime, lt);
|
||||
// sunVec = glm::normalize(sunVec);
|
||||
|
||||
float angle = acos(glm::dot(xVec, sunVec));
|
||||
glm::vec3 ref = glm::cross(xVec, sunVec);
|
||||
// float angle = acos(glm::dot(xVec, sunVec));
|
||||
// glm::vec3 ref = glm::cross(xVec, sunVec);
|
||||
|
||||
glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), angle, ref);
|
||||
transform = rotation * transform;
|
||||
}
|
||||
// glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), angle, ref);
|
||||
// transform = rotation * transform;
|
||||
// }
|
||||
|
||||
position += transform*glm::vec4(_data->spatialScale.x*_data->offset, _data->spatialScale.w);
|
||||
|
||||
@@ -105,9 +105,12 @@ void CygnetPlane::render(const RenderData& data){
|
||||
void CygnetPlane::update(const UpdateData& data){
|
||||
_openSpaceTime = Time::ref().currentTime();
|
||||
_realTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
|
||||
_stateMatrix = SpiceManager::ref().positionTransformMatrix("GALACTIC", _data->frame, _openSpaceTime);
|
||||
|
||||
|
||||
_stateMatrix = ISWAManager::ref().getTransform(_data->frame, "GALACTIC", _openSpaceTime);
|
||||
// glm::dmat3 spiceMatrix = SpiceManager::ref().positionTransformMatrix("J2000", "GALACTIC", _openSpaceTime);
|
||||
// = spiceMatrix*kameleonMatrix;
|
||||
|
||||
bool timeToUpdate = (fabs(_openSpaceTime-_lastUpdateOpenSpaceTime) >= _data->updateTime &&
|
||||
(_realTime.count()-_lastUpdateRealTime.count()) > _minRealTimeUpdateInterval);
|
||||
if( _data->updateTime != 0 && (Time::ref().timeJumped() || timeToUpdate )){
|
||||
|
||||
@@ -70,6 +70,11 @@ ISWAManager::ISWAManager()
|
||||
|
||||
_geom[CygnetGeometry::Plane] = "Plane";
|
||||
_geom[CygnetGeometry::Sphere] = "Sphere";
|
||||
|
||||
_kameleon = std::make_shared<ccmc::Kameleon>();
|
||||
_kameleonFrames = { "J200", "GEI", "GEO", "MAG", "GSE", "GSM", "SM", "RTN", "GSEQ", //geocentric
|
||||
"HEE", "HAE", "HEEQ" //heliocentric
|
||||
};
|
||||
}
|
||||
|
||||
ISWAManager::~ISWAManager(){
|
||||
@@ -421,4 +426,66 @@ scripting::ScriptEngine::LuaLibrary ISWAManager::luaLibrary() {
|
||||
};
|
||||
}
|
||||
|
||||
glm::dmat3 ISWAManager::getTransform(std::string from, std::string to, double et){
|
||||
auto fromit = _kameleonFrames.find(from);
|
||||
auto toit = _kameleonFrames.find(to);
|
||||
|
||||
bool fromKameleon = (fromit != _kameleonFrames.end());
|
||||
bool toKameleon = (toit != _kameleonFrames.end());
|
||||
|
||||
ccmc::Position in0 = {1, 0, 0};
|
||||
ccmc::Position in1 = {0, 1, 0};
|
||||
ccmc::Position in2 = {0, 0, 1};
|
||||
|
||||
ccmc::Position out0;
|
||||
ccmc::Position out1;
|
||||
ccmc::Position out2;
|
||||
|
||||
if(fromKameleon && toKameleon){
|
||||
_kameleon->_cxform(from.c_str(), to.c_str(), et, &in0, &out0);
|
||||
_kameleon->_cxform(from.c_str(), to.c_str(), et, &in1, &out1);
|
||||
_kameleon->_cxform(from.c_str(), to.c_str(), et, &in2, &out2);
|
||||
|
||||
|
||||
return glm::dmat3(
|
||||
out0.c0 , out0.c1 , out0.c2,
|
||||
out1.c0 , out1.c1 , out1.c2,
|
||||
out2.c0 , out2.c1 , out2.c2
|
||||
);
|
||||
|
||||
}else if(fromKameleon && !toKameleon){
|
||||
_kameleon->_cxform(from.c_str(), "J2000", et, &in0, &out0);
|
||||
_kameleon->_cxform(from.c_str(), "J2000", et, &in1, &out1);
|
||||
_kameleon->_cxform(from.c_str(), "J2000", et, &in2, &out2);
|
||||
|
||||
glm::dmat3 kameleonTrans(
|
||||
out0.c0 , out0.c1 , out0.c2,
|
||||
out1.c0 , out1.c1 , out1.c2,
|
||||
out2.c0 , out2.c1 , out2.c2
|
||||
);
|
||||
|
||||
glm::dmat3 spiceTrans = SpiceManager::ref().positionTransformMatrix("J2000", to, et);
|
||||
|
||||
return spiceTrans*kameleonTrans;
|
||||
|
||||
}else if(!fromKameleon && toKameleon){
|
||||
glm::dmat3 spiceTrans = SpiceManager::ref().positionTransformMatrix(from, "J2000", et);
|
||||
|
||||
_kameleon->_cxform("J2000", to.c_str(), et, &in0, &out0);
|
||||
_kameleon->_cxform("J2000", to.c_str(), et, &in1, &out1);
|
||||
_kameleon->_cxform("J2000", to.c_str(), et, &in2, &out2);
|
||||
|
||||
glm::dmat3 kameleonTrans(
|
||||
out0.c0 , out0.c1 , out0.c2,
|
||||
out1.c0 , out1.c1 , out1.c2,
|
||||
out2.c0 , out2.c1 , out2.c2
|
||||
);
|
||||
|
||||
return kameleonTrans*spiceTrans;
|
||||
}else{
|
||||
|
||||
return SpiceManager::ref().positionTransformMatrix(from, to, et);
|
||||
}
|
||||
}
|
||||
|
||||
}// namsepace openspace
|
||||
@@ -35,6 +35,8 @@
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/properties/selectionproperty.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
|
||||
// #include <modules/iswa/rendering/iswacygnet.h>
|
||||
// #include <modules/iswa/rendering/iswagroup.h>
|
||||
|
||||
@@ -80,6 +82,8 @@ public:
|
||||
void registerOptionsToGroup(int id, const std::vector<properties::SelectionProperty::Option>& options);
|
||||
std::shared_ptr<ISWAGroup> iSWAGroup(std::string name);
|
||||
|
||||
glm::dmat3 getTransform(std::string from, std::string to, double et);
|
||||
|
||||
static scripting::ScriptEngine::LuaLibrary luaLibrary();
|
||||
|
||||
private:
|
||||
@@ -100,6 +104,7 @@ private:
|
||||
std::map<int, std::shared_ptr<ISWAGroup>> _groups;
|
||||
|
||||
std::shared_ptr<ccmc::Kameleon> _kameleon;
|
||||
std::set<std::string> _kameleonFrames;
|
||||
};
|
||||
|
||||
} //namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user