2021-01-26 23:28:20 -06:00
|
|
|
/*
|
2021-01-30 19:39:25 -06:00
|
|
|
Dane Johnson <dane@danejohnson.org>
|
2021-01-26 23:28:20 -06:00
|
|
|
|
2021-01-30 19:39:25 -06:00
|
|
|
LICENSE
|
2021-01-26 23:28:20 -06:00
|
|
|
|
2021-01-30 19:39:25 -06:00
|
|
|
Couch Copyright (C) 2021 Dane Johnson
|
2021-01-26 23:28:20 -06:00
|
|
|
|
2021-01-30 19:39:25 -06:00
|
|
|
This program comes with ABSOLUTELY NO WARRANTY; without event the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the GNU General Public License for details at
|
|
|
|
https://www.gnu.org/licenses/gpl-3.0.html
|
2021-01-26 23:28:20 -06:00
|
|
|
|
2021-01-30 19:39:25 -06:00
|
|
|
This is free software, and you are welcome to redistribute it
|
|
|
|
under the terms of the GNU General Public License as published
|
|
|
|
by the Free Software Foundation; either version 3 of the License,
|
|
|
|
or (at your option) any later version.
|
2021-01-26 23:28:20 -06:00
|
|
|
|
2021-01-30 19:39:25 -06:00
|
|
|
DESCRIPTION
|
2021-01-26 23:28:20 -06:00
|
|
|
|
2021-01-30 19:39:25 -06:00
|
|
|
A spatial is a node with a transform property, i.e. position, scale or rotation.
|
|
|
|
They can be instanced on the scene tree as an anchor for some other nodes.
|
2021-01-26 23:28:20 -06:00
|
|
|
*/
|
2021-01-21 15:26:39 -06:00
|
|
|
#include "Spatial.h"
|
2021-01-30 19:39:25 -06:00
|
|
|
#include "Util.h"
|
2021-01-21 15:26:39 -06:00
|
|
|
|
|
|
|
Name Spatial::GetType() const {return "Spatial";}
|
2021-01-24 16:37:35 -06:00
|
|
|
|
2021-01-26 23:28:20 -06:00
|
|
|
Transform Spatial::GetTransform() {
|
|
|
|
return transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spatial::SetTransform(Transform transform) {
|
|
|
|
this->transform = transform;
|
|
|
|
}
|
|
|
|
|
2021-01-30 19:39:25 -06:00
|
|
|
Transform Spatial::GetGlobalTransform() {
|
|
|
|
Util::Die("Global transform is not implemented yet.\n"
|
|
|
|
"I don't fully understand the maths yet!");
|
|
|
|
return Transform();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spatial::SetGlobalTransform(Transform globalTransform) {
|
|
|
|
// TODO
|
|
|
|
Util::Die("Global transform is not implemented yet.\n"
|
|
|
|
"I don't fully understand the maths yet!");
|
|
|
|
}
|
|
|
|
|
2021-01-24 16:37:35 -06:00
|
|
|
Spatial *Spatial::Create() {
|
|
|
|
return new Spatial;
|
|
|
|
}
|
|
|
|
|
2021-01-26 23:28:20 -06:00
|
|
|
void Spatial::Translate(Vector3 offset) {
|
|
|
|
Transform t = this->GetTransform();
|
|
|
|
t.position += offset;
|
|
|
|
this->SetTransform(t);
|
|
|
|
}
|
|
|
|
|
2021-01-27 16:17:22 -06:00
|
|
|
void Spatial::RotateX(float phi) {
|
2021-01-26 23:28:20 -06:00
|
|
|
Transform t = this->GetTransform();
|
|
|
|
t.rotation.x += phi;
|
|
|
|
this->SetTransform(t);
|
|
|
|
}
|
|
|
|
|
2021-01-27 16:17:22 -06:00
|
|
|
void Spatial::RotateY(float phi) {
|
2021-01-26 23:28:20 -06:00
|
|
|
Transform t = this->GetTransform();
|
|
|
|
t.rotation.y += phi;
|
|
|
|
this->SetTransform(t);
|
|
|
|
}
|
|
|
|
|
2021-01-27 16:17:22 -06:00
|
|
|
void Spatial::RotateZ(float phi) {
|
2021-01-26 23:28:20 -06:00
|
|
|
Transform t = this->GetTransform();
|
|
|
|
t.rotation.z += phi;
|
|
|
|
this->SetTransform(t);
|
|
|
|
}
|
|
|
|
|
2021-01-27 16:17:22 -06:00
|
|
|
void Spatial::UniformScale(float scale) {
|
2021-01-26 23:28:20 -06:00
|
|
|
Transform t = this->GetTransform();
|
|
|
|
t.scale *= scale;
|
|
|
|
this->SetTransform(t);
|
|
|
|
}
|
|
|
|
|
2021-01-24 16:37:35 -06:00
|
|
|
Spatial *Spatial::Duplicate() {
|
|
|
|
Spatial *spatial = static_cast<Spatial*>(Node::Duplicate());
|
|
|
|
spatial->transform = transform;
|
|
|
|
|
|
|
|
return spatial;
|
|
|
|
}
|
|
|
|
|
|
|
|
Spatial *Spatial::Instance() {
|
|
|
|
return static_cast<Spatial*>(Node::Instance());
|
|
|
|
}
|
|
|
|
|