transform.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2014 Google Inc. All Rights Reserved.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "tango-gl/transform.h"
00018 #include "tango-gl/util.h"
00019 
00020 #define nullptr 0
00021 
00022 namespace tango_gl {
00023 
00024 Transform::Transform()
00025   : parent_(nullptr),
00026     position_(0.0f, 0.0f, 0.0f),
00027     rotation_(1.0f, 0.0f, 0.0f, 0.0f),
00028     scale_(1.0f, 1.0f, 1.0f) {
00029 }
00030 
00031 Transform::~Transform() {
00032   // Objects are not responsible for deleting their parents.
00033 }
00034 
00035 void Transform::SetPosition(const glm::vec3& position) {
00036   position_ = position;
00037 }
00038 
00039 glm::vec3 Transform::GetPosition() const {
00040   return position_;
00041 }
00042 
00043 void Transform::SetRotation(const glm::quat& rotation) {
00044   rotation_ = rotation;
00045 }
00046 
00047 glm::quat Transform::GetRotation() const {
00048   return rotation_;
00049 }
00050 
00051 void Transform::SetScale(const glm::vec3& scale) {
00052   scale_ = scale;
00053 }
00054 
00055 glm::vec3 Transform::GetScale() const {
00056   return scale_;
00057 }
00058 
00059 void Transform::Translate(const glm::vec3& translation) {
00060   position_ += translation;
00061 }
00062 
00063 void Transform::SetTransformationMatrix(const glm::mat4& transform_mat) {
00064   util::DecomposeMatrix(transform_mat, position_, rotation_, scale_);
00065 }
00066 
00067 glm::mat4 Transform::GetTransformationMatrix() const {
00068   glm::mat4 trans_mat = glm::scale(glm::mat4_cast(rotation_), scale_);
00069   trans_mat[3][0] = position_.x;
00070   trans_mat[3][1] = position_.y;
00071   trans_mat[3][2] = position_.z;
00072   glm::mat4 parent_mat = glm::mat4(1.0f);
00073   if (parent_ != NULL) {
00074     parent_mat = parent_->GetTransformationMatrix();
00075     trans_mat = parent_mat * trans_mat;
00076   }
00077   return  trans_mat;
00078 }
00079 
00080 void Transform::SetParent(Transform* transform) {
00081   parent_ = transform;
00082 }
00083 
00084 const Transform* Transform::GetParent() const {
00085   return parent_;
00086 }
00087 
00088 Transform* Transform::GetParent() {
00089   return parent_;
00090 }
00091 
00092 }  // namespace tango_gl


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jun 6 2019 21:59:31