Kukatz 3D  0.1
Török Attila szakdolgozata
projects/Kukatz 3D/src/gameobject.cpp
00001 /*
00002  * gameobject.cpp - Kukatz 3D
00003  * Copyright (c) 2011 - TÖRÖK Attila (torokati44@gmail.com)
00004  *
00005  * This software is provided 'as-is', without any express or implied
00006  * warranty. In no event will the authors be held liable for any damages
00007  * arising from the use of this software.
00008  *
00009  * Permission is granted to anyone to use this software for any purpose,
00010  * including commercial applications, and to alter it and redistribute it
00011  * freely, subject to the following restrictions:
00012  *
00013  *       1. The origin of this software must not be misrepresented; you must not
00014  *                      claim that you wrote the original software. If you use this software
00015  *                      in a product, an acknowledgment in the product documentation would be
00016  *                      appreciated but is not required.
00017  *
00018  *       2. Altered source versions must be plainly marked as such, and must not be
00019  *                      misrepresented as being the original software.
00020  *
00021  *       3. This notice may not be removed or altered from any source
00022  *                      distribution.
00023  */
00024 
00025 #include "gameobject.hpp"
00026 
00027 #include "opengl.hpp"
00028 #include "camera.hpp"
00029 #include "misc.hpp"
00030 
00031 GameObject::GameObject()
00032 {
00033         matrix = new float[16];
00034         set_identity();
00035 }
00036 
00037 sf::Vector3f GameObject::local_to_global(const sf::Vector3f& v)
00038 {
00039         return transform(v, matrix);
00040 }
00041 
00042 void GameObject::set_identity()
00043 {
00044         matrix[0]  = 1; matrix[1]  = 0; matrix[2]  = 0; matrix[3]  = 0;
00045         matrix[4]  = 0; matrix[5]  = 1; matrix[6]  = 0; matrix[7]  = 0;
00046         matrix[8]  = 0; matrix[9]  = 0; matrix[10] = 1; matrix[11] = 0;
00047         matrix[12] = 0; matrix[13] = 0; matrix[14] = 0; matrix[15] = 1;
00048 }
00049 
00050 void GameObject::set_transform()
00051 {
00052         glPushMatrix();
00053         glMultMatrixf(matrix);
00054 }
00055 
00056 void GameObject::unset_transform()
00057 {
00058         glPopMatrix();
00059 }
00060 
00061 void GameObject::get_x_axis(float& x, float& y, float& z)
00062 {
00063         x = matrix[0];
00064         y = matrix[1];
00065         z = matrix[2];
00066 }
00067 
00068 void GameObject::get_x_axis(sf::Vector3f& v)
00069 {
00070         v.x = matrix[0];
00071         v.y = matrix[1];
00072         v.z = matrix[2];
00073 }
00074 
00075 sf::Vector3f GameObject::get_x_axis()
00076 {
00077         return sf::Vector3f(matrix[0], matrix[1], matrix[2]);
00078 }
00079 
00080 void GameObject::set_x_axis()
00081 {
00082         set_x_axis(crossprod(
00083                 matrix[4], matrix[5], matrix[6], // y
00084                 matrix[8], matrix[9], matrix[10] // z
00085         ));
00086 }
00087 
00088 void GameObject::set_x_axis(float x, float y, float z)
00089 {
00090         matrix[0] = x;
00091         matrix[1] = y;
00092         matrix[2] = z;
00093 }
00094 
00095 void GameObject::set_x_axis(const sf::Vector3f& v)
00096 {
00097         matrix[0] = v.x;
00098         matrix[1] = v.y;
00099         matrix[2] = v.z;
00100 }
00101 
00102 void GameObject::set_x_axis(const sf::Vector3i& v)
00103 {
00104         matrix[0] = v.x;
00105         matrix[1] = v.y;
00106         matrix[2] = v.z;
00107 }
00108 
00109 
00110 void GameObject::get_y_axis(float& x, float& y, float& z)
00111 {
00112         x = matrix[4];
00113         y = matrix[5];
00114         z = matrix[6];
00115 }
00116 
00117 void GameObject::get_y_axis(sf::Vector3f& v)
00118 {
00119         v.x = matrix[4];
00120         v.y = matrix[5];
00121         v.z = matrix[6];
00122 }
00123 
00124 sf::Vector3f GameObject::get_y_axis()
00125 {
00126         return sf::Vector3f(matrix[4], matrix[5], matrix[6]);
00127 }
00128 
00129 void GameObject::set_y_axis()
00130 {
00131         set_y_axis(crossprod(
00132                 matrix[8], matrix[9], matrix[10], // z
00133                 matrix[0], matrix[1], matrix[2]   // x
00134         ));
00135 }
00136 
00137 void GameObject::set_y_axis(float x, float y, float z)
00138 {
00139         matrix[4] = x;
00140         matrix[5] = y;
00141         matrix[6] = z;
00142 }
00143 
00144 void GameObject::set_y_axis(const sf::Vector3f& v)
00145 {
00146         matrix[4] = v.x;
00147         matrix[5] = v.y;
00148         matrix[6] = v.z;
00149 }
00150 
00151 void GameObject::set_y_axis(const sf::Vector3i& v)
00152 {
00153         matrix[4] = v.x;
00154         matrix[5] = v.y;
00155         matrix[6] = v.z;
00156 }
00157 
00158 
00159 void GameObject::get_z_axis(float& x, float& y, float& z)
00160 {
00161         x = matrix[8];
00162         y = matrix[9];
00163         z = matrix[10];
00164 }
00165 
00166 void GameObject::get_z_axis(sf::Vector3f& v)
00167 {
00168         v.x = matrix[8];
00169         v.y = matrix[9];
00170         v.z = matrix[10];
00171 }
00172 
00173 sf::Vector3f GameObject::get_z_axis()
00174 {
00175         return sf::Vector3f(matrix[8], matrix[9], matrix[10]);
00176 }
00177 
00178 void GameObject::set_z_axis()
00179 {
00180         set_z_axis(crossprod(
00181                 matrix[0], matrix[1], matrix[2], // x
00182                 matrix[4], matrix[5], matrix[6] // y
00183         ));
00184 }
00185 
00186 void GameObject::set_z_axis(float x, float y, float z)
00187 {
00188         matrix[8] = x;
00189         matrix[9] = y;
00190         matrix[10] = z;
00191 }
00192 
00193 void GameObject::set_z_axis(const sf::Vector3f& v)
00194 {
00195         matrix[8] = v.x;
00196         matrix[9] = v.y;
00197         matrix[10] = v.z;
00198 }
00199 
00200 void GameObject::set_z_axis(const sf::Vector3i& v)
00201 {
00202         matrix[8] = v.x;
00203         matrix[9] = v.y;
00204         matrix[10] = v.z;
00205 }
00206 
00207 
00208 void GameObject::set_axes(const sf::Vector3f& x, const sf::Vector3f& y,
00209         const sf::Vector3f& z)
00210 {
00211         set_x_axis(x);
00212         set_y_axis(y);
00213         set_z_axis(z);
00214 }
00215 
00216 void GameObject::set_axes(const sf::Vector3i& x, const sf::Vector3i& y,
00217         const sf::Vector3i& z)
00218 {
00219         set_x_axis(x);
00220         set_y_axis(y);
00221         set_z_axis(z);
00222 }
00223 
00224 sf::Vector3f GameObject::get_position()
00225 {
00226         return sf::Vector3f(matrix[12], matrix[13], matrix[14]);
00227 }
00228 
00229 void GameObject::set_position(float x, float y, float z)
00230 {
00231         matrix[12] = x;
00232         matrix[13] = y;
00233         matrix[14] = z;
00234 }
00235 
00236 void GameObject::set_position(const sf::Vector3f& p)
00237 {
00238         matrix[12] = p.x;
00239         matrix[13] = p.y;
00240         matrix[14] = p.z;
00241 }
00242 
00243 void GameObject::set_position(const sf::Vector3i& p)
00244 {
00245         matrix[12] = p.x;
00246         matrix[13] = p.y;
00247         matrix[14] = p.z;
00248 }
00249 
00250 GameObject::~GameObject()
00251 {
00252         delete[] matrix;
00253 }
 Összes Osztályok