frame.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00027 #include "renderstack/frame.hpp"
00028 #include "renderstack/matrix.hpp"
00029 #include "renderstack/quaternion.hpp"
00030
00031 namespace renderstack {
00032
00033 class frame frame::identity = frame();
00034
00035 frame::frame()
00036 {
00037 m_local_to_world = matrix::identity();
00038 m_world_to_local = matrix::identity();
00039 }
00040
00041 bool frame::connect(uniform_bindings &bindings, enum logical_uniform uniform, int slot)
00042 {
00043 switch(uniform)
00044 {
00045 case logical_uniform_local_to_world: return bindings.add(uniform_type_matrix_4, slot, 1, &m_local_to_world.m[0][0]);
00046 case logical_uniform_world_to_local: return bindings.add(uniform_type_matrix_4, slot, 1, &m_world_to_local.m[0][0]);
00047 default: return false;
00048 }
00049 }
00050
00051 void frame::translate_in_world(vec3 const &t)
00052 {
00053 m_local_to_world.m[3][0] += t.x;
00054 m_local_to_world.m[3][1] += t.y;
00055 m_local_to_world.m[3][2] += t.z;
00056 m_world_to_local = inverse(m_local_to_world);
00057 }
00058
00059 void frame::rotate_in_world(vec3 const &axis, float angle)
00060 {
00061 vec3 a = axis;
00062 float half_angle = 0.5f * angle;
00063 float half_angle_sin = sinf(half_angle);
00064 float half_angle_cos = cosf(half_angle);
00065 matrix local_to_world;
00066
00067 while(angle < 0)
00068 {
00069 angle += RS_TWO_PI;
00070 }
00071
00072 while(angle >= RS_TWO_PI)
00073 {
00074 angle -= RS_TWO_PI;
00075 }
00076
00077 quaternion q = quaternion(axis, half_angle_sin, half_angle_cos);
00078 m_local_to_world *= matrix(q);
00079 m_world_to_local = inverse(m_local_to_world);
00080 }
00081
00082 void frame::set_hpb_xyz(
00083 vec3 const &hpb,
00084 vec3 const &translation
00085 )
00086 {
00087 make_matrix_hpb_xyz(
00088 m_local_to_world,
00089 m_world_to_local,
00090 hpb_mod_2pi(hpb),
00091 translation
00092 );
00093 }
00094
00095 }
00096