update according to code review

This commit is contained in:
Mikulas Florek 2014-02-24 20:32:41 +01:00
parent e00624d5ec
commit 0b346c0026
9 changed files with 62 additions and 57 deletions

View file

@ -55,15 +55,18 @@ void Animation::loaded(FS::IFile* file, bool success)
}
static const float ANIMATION_FPS = 30.0f;
void Animation::getPose(float time, Pose& pose) const
{
int frame = (int)(time * 30.0f);
int frame = (int)(time * ANIMATION_FPS);
frame = frame >= m_frame_count ? m_frame_count - 1 : frame;
Vec3* pos = pose.getPositions();
Quat* rot = pose.getRotations();
int off = frame * m_bone_count;
int off2 = off + m_bone_count;
float t = (time - frame / 30.0f) / (1 / 30.0f);
float t = (time - frame / ANIMATION_FPS) / (1 / ANIMATION_FPS);
if(frame < m_frame_count - 1)
{

View file

@ -30,10 +30,10 @@ class Animation
void loaded(FS::IFile* file, bool success);
private:
int m_frame_count;
int m_bone_count;
Vec3* m_positions;
Quat* m_rotations;
int m_frame_count;
int m_bone_count;
Vec3* m_positions;
Quat* m_rotations;
};

View file

@ -80,7 +80,7 @@ class Array
m_data[index].~T();
for(int i = index + 1; i < m_size; ++i)
{
new ((char*)(m_data+i-1)) T(m_data[i]);
new ((char*)(m_data + i - 1)) T(m_data[i]);
m_data[i].~T();
}
--m_size;
@ -111,21 +111,20 @@ class Array
{
grow();
}
new ((char*)(m_data+m_size)) T;
new ((char*)(m_data + m_size)) T;
++m_size;
return m_data[m_size-1];
return m_data[m_size - 1];
}
const T& back() const
{
return m_data[m_size-1];
return m_data[m_size - 1];
}
T& back()
{
return m_data[m_size-1];
return m_data[m_size - 1];
}
@ -133,7 +132,7 @@ class Array
{
if(m_size > 0)
{
m_data[m_size-1].~T();
m_data[m_size - 1].~T();
--m_size;
}
}
@ -146,7 +145,7 @@ class Array
}
for(int i = m_size; i < size; ++i)
{
new ((char*)(m_data+i)) T();
new ((char*)(m_data + i)) T();
}
callDestructors(m_data + size, m_data + m_size);
m_size = size;
@ -159,7 +158,7 @@ class Array
T* newData = (T*)m_allocator.allocate(capacity * sizeof(T));
for(int i = 0; i < m_size; ++i)
{
new ((char*)(newData+i)) T(m_data[i]);
new ((char*)(newData + i)) T(m_data[i]);
}
callDestructors(m_data, m_data + m_size);
m_allocator.deallocate(m_data);

View file

@ -52,7 +52,7 @@ namespace Lux
return (n) && !(n & (n - 1));
}
inline float degreesToRadians(float angle)
LUX_FORCE_INLINE float degreesToRadians(float angle)
{
return angle * PI / 180.0f;
}

View file

@ -78,12 +78,12 @@ struct LUX_CORE_API Matrix
float determinant()
{
return
m14*m23*m32*m41 - m13*m24*m32*m41 - m14*m22*m33*m41 + m12*m24*m33*m41 +
m13*m22*m34*m41 - m12*m23*m34*m41 - m14*m23*m31*m42 + m13*m24*m31*m42 +
m14*m21*m33*m42 - m11*m24*m33*m42 - m13*m21*m34*m42 + m11*m23*m34*m42 +
m14*m22*m31*m43 - m12*m24*m31*m43 - m14*m21*m32*m43 + m11*m24*m32*m43 +
m12*m21*m34*m43 - m11*m22*m34*m43 - m13*m22*m31*m44 + m12*m23*m31*m44 +
m13*m21*m32*m44 - m11*m23*m32*m44 - m12*m21*m33*m44 + m11*m22*m33*m44;
m14 * m23 * m32 * m41 - m13 * m24 * m32 * m41 - m14 * m22 * m33 * m41 + m12 * m24 * m33 * m41 +
m13 * m22 * m34 * m41 - m12 * m23 * m34 * m41 - m14 * m23 * m31 * m42 + m13 * m24 * m31 * m42 +
m14 * m21 * m33 * m42 - m11 * m24 * m33 * m42 - m13 * m21 * m34 * m42 + m11 * m23 * m34 * m42 +
m14 * m22 * m31 * m43 - m12 * m24 * m31 * m43 - m14 * m21 * m32 * m43 + m11 * m24 * m32 * m43 +
m12 * m21 * m34 * m43 - m11 * m22 * m34 * m43 - m13 * m22 * m31 * m44 + m12 * m23 * m31 * m44 +
m13 * m21 * m32 * m44 - m11 * m23 * m32 * m44 - m12 * m21 * m33 * m44 + m11 * m22 * m33 * m44;
}
@ -94,22 +94,22 @@ struct LUX_CORE_API Matrix
if( d == 0 ) return;
d = 1.0f / d;
mtx.m11 = d * (m23*m34*m42 - m24*m33*m42 + m24*m32*m43 - m22*m34*m43 - m23*m32*m44 + m22*m33*m44);
mtx.m12 = d * (m14*m33*m42 - m13*m34*m42 - m14*m32*m43 + m12*m34*m43 + m13*m32*m44 - m12*m33*m44);
mtx.m13 = d * (m13*m24*m42 - m14*m23*m42 + m14*m22*m43 - m12*m24*m43 - m13*m22*m44 + m12*m23*m44);
mtx.m14 = d * (m14*m23*m32 - m13*m24*m32 - m14*m22*m33 + m12*m24*m33 + m13*m22*m34 - m12*m23*m34);
mtx.m21 = d * (m24*m33*m41 - m23*m34*m41 - m24*m31*m43 + m21*m34*m43 + m23*m31*m44 - m21*m33*m44);
mtx.m22 = d * (m13*m34*m41 - m14*m33*m41 + m14*m31*m43 - m11*m34*m43 - m13*m31*m44 + m11*m33*m44);
mtx.m23 = d * (m14*m23*m41 - m13*m24*m41 - m14*m21*m43 + m11*m24*m43 + m13*m21*m44 - m11*m23*m44);
mtx.m24 = d * (m13*m24*m31 - m14*m23*m31 + m14*m21*m33 - m11*m24*m33 - m13*m21*m34 + m11*m23*m34);
mtx.m31 = d * (m22*m34*m41 - m24*m32*m41 + m24*m31*m42 - m21*m34*m42 - m22*m31*m44 + m21*m32*m44);
mtx.m32 = d * (m14*m32*m41 - m12*m34*m41 - m14*m31*m42 + m11*m34*m42 + m12*m31*m44 - m11*m32*m44);
mtx.m33 = d * (m12*m24*m41 - m14*m22*m41 + m14*m21*m42 - m11*m24*m42 - m12*m21*m44 + m11*m22*m44);
mtx.m34 = d * (m14*m22*m31 - m12*m24*m31 - m14*m21*m32 + m11*m24*m32 + m12*m21*m34 - m11*m22*m34);
mtx.m41 = d * (m23*m32*m41 - m22*m33*m41 - m23*m31*m42 + m21*m33*m42 + m22*m31*m43 - m21*m32*m43);
mtx.m42 = d * (m12*m33*m41 - m13*m32*m41 + m13*m31*m42 - m11*m33*m42 - m12*m31*m43 + m11*m32*m43);
mtx.m43 = d * (m13*m22*m41 - m12*m23*m41 - m13*m21*m42 + m11*m23*m42 + m12*m21*m43 - m11*m22*m43);
mtx.m44 = d * (m12*m23*m31 - m13*m22*m31 + m13*m21*m32 - m11*m23*m32 - m12*m21*m33 + m11*m22*m33);
mtx.m11 = d * (m23 * m34 * m42 - m24 * m33 * m42 + m24 * m32 * m43 - m22 * m34 * m43 - m23 * m32 * m44 + m22 * m33 * m44);
mtx.m12 = d * (m14 * m33 * m42 - m13 * m34 * m42 - m14 * m32 * m43 + m12 * m34 * m43 + m13 * m32 * m44 - m12 * m33 * m44);
mtx.m13 = d * (m13 * m24 * m42 - m14 * m23 * m42 + m14 * m22 * m43 - m12 * m24 * m43 - m13 * m22 * m44 + m12 * m23 * m44);
mtx.m14 = d * (m14 * m23 * m32 - m13 * m24 * m32 - m14 * m22 * m33 + m12 * m24 * m33 + m13 * m22 * m34 - m12 * m23 * m34);
mtx.m21 = d * (m24 * m33 * m41 - m23 * m34 * m41 - m24 * m31 * m43 + m21 * m34 * m43 + m23 * m31 * m44 - m21 * m33 * m44);
mtx.m22 = d * (m13 * m34 * m41 - m14 * m33 * m41 + m14 * m31 * m43 - m11 * m34 * m43 - m13 * m31 * m44 + m11 * m33 * m44);
mtx.m23 = d * (m14 * m23 * m41 - m13 * m24 * m41 - m14 * m21 * m43 + m11 * m24 * m43 + m13 * m21 * m44 - m11 * m23 * m44);
mtx.m24 = d * (m13 * m24 * m31 - m14 * m23 * m31 + m14 * m21 * m33 - m11 * m24 * m33 - m13 * m21 * m34 + m11 * m23 * m34);
mtx.m31 = d * (m22 * m34 * m41 - m24 * m32 * m41 + m24 * m31 * m42 - m21 * m34 * m42 - m22 * m31 * m44 + m21 * m32 * m44);
mtx.m32 = d * (m14 * m32 * m41 - m12 * m34 * m41 - m14 * m31 * m42 + m11 * m34 * m42 + m12 * m31 * m44 - m11 * m32 * m44);
mtx.m33 = d * (m12 * m24 * m41 - m14 * m22 * m41 + m14 * m21 * m42 - m11 * m24 * m42 - m12 * m21 * m44 + m11 * m22 * m44);
mtx.m34 = d * (m14 * m22 * m31 - m12 * m24 * m31 - m14 * m21 * m32 + m11 * m24 * m32 + m12 * m21 * m34 - m11 * m22 * m34);
mtx.m41 = d * (m23 * m32 * m41 - m22 * m33 * m41 - m23 * m31 * m42 + m21 * m33 * m42 + m22 * m31 * m43 - m21 * m32 * m43);
mtx.m42 = d * (m12 * m33 * m41 - m13 * m32 * m41 + m13 * m31 * m42 - m11 * m33 * m42 - m12 * m31 * m43 + m11 * m32 * m43);
mtx.m43 = d * (m13 * m22 * m41 - m12 * m23 * m41 - m13 * m21 * m42 + m11 * m23 * m42 + m12 * m21 * m43 - m11 * m22 * m43);
mtx.m44 = d * (m12 * m23 * m31 - m13 * m22 * m31 + m13 * m21 * m32 - m11 * m23 * m32 - m12 * m21 * m33 + m11 * m22*m33);
*this = mtx;
}

View file

@ -314,13 +314,13 @@ void EditorServerImpl::onPointerDown(int x, int y, MouseButton::Value button)
else if(button == MouseButton::LEFT)
{
Vec3 origin, dir;
m_engine.getRenderer().getRay(m_camera.getComponent(crc32("camera")), (float)x, (float)y, origin, dir);
m_engine.getRenderer().getRay(m_camera.getComponent(camera_type), (float)x, (float)y, origin, dir);
RayCastModelHit hit = m_engine.getRenderer().castRay(origin, dir);
if(hit.m_is_hit)
{
selectEntity(hit.m_renderable.entity);
m_mouse_mode = EditorServerImpl::MouseMode::TRANSFORM;
m_gizmo.startTransform(m_camera.getComponent(crc32("camera")), x, y, Gizmo::TransformMode::CAMERA_XZ);
m_gizmo.startTransform(m_camera.getComponent(camera_type), x, y, Gizmo::TransformMode::CAMERA_XZ);
}
/*Vec3 hit_pos;
char node_name[20];
@ -382,7 +382,7 @@ void EditorServerImpl::onPointerMove(int x, int y, int relx, int rely)
Gizmo::TransformOperation tmode = GetKeyState(VK_MENU) & 0x8000 ? Gizmo::TransformOperation::ROTATE : Gizmo::TransformOperation::TRANSLATE;
int flags = GetKeyState(VK_LCONTROL) & 0x8000 ? Gizmo::Flags::FIXED_STEP : 0;
m_gizmo.transform(m_camera.getComponent(crc32("camera")), tmode, x, y, relx, rely, flags);
m_gizmo.transform(m_camera.getComponent(camera_type), tmode, x, y, relx, rely, flags);
}
break;
}
@ -1126,12 +1126,12 @@ void EditorServerImpl::createUniverse(bool create_scene, const char* base_path)
m_camera = m_engine.getUniverse()->createEntity();
m_camera.setPosition(0, 0, -5);
m_camera.setRotation(Quat(Vec3(0, 1, 0), -3.14159265f));
Component cmp = m_engine.getRenderer().createComponent(crc32("camera"), m_camera);
m_camera.setRotation(Quat(Vec3(0, 1, 0), -Math::PI));
Component cmp = m_engine.getRenderer().createComponent(camera_type, m_camera);
m_engine.getRenderer().setCameraPipeline(cmp, string("pipelines/main.json"));
m_engine.getRenderer().setCameraActive(cmp, true);
Component cmp2 = m_engine.getRenderer().createComponent(crc32("renderable"), m_engine.getUniverse()->createEntity());
Component cmp2 = m_engine.getRenderer().createComponent(renderable_type, m_engine.getUniverse()->createEntity());
m_engine.getRenderer().setRenderablePath(cmp2, string("models/blender.msh"));
/*
universe->getEventManager()->addListener(EntityMovedEvent::type).bind<EditorServerImpl, &EditorServerImpl::onEvent>(this);

View file

@ -240,7 +240,7 @@ namespace Lux
{
m_impl->m_universe->serialize(serializer);
//m_impl->m_renderer.serialize(serializer);
ASSERT(false);
//ASSERT(false);
m_impl->m_script_system.serialize(serializer);
m_impl->m_plugin_manager.serialize(serializer);
}
@ -250,7 +250,7 @@ namespace Lux
{
m_impl->m_universe->deserialize(serializer);
//m_impl->m_renderer.deserialize(serializer);
ASSERT(false);
//ASSERT(false);
m_impl->m_script_system.deserialize(serializer);
m_impl->m_plugin_manager.deserialize(serializer);
}

View file

@ -2,16 +2,16 @@
#include <Windows.h>
#include <gl/GL.h>
#define GL_ARRAY_BUFFER 0x8892
#define GL_FRAGMENT_SHADER 0x8B30
#define GL_STATIC_DRAW 0x88E4
#define GL_VERTEX_SHADER 0x8B31
#define GL_CLAMP_TO_EDGE 0x812F
#define GL_TEXTURE0 0x84C0
#define GL_TEXTURE1 0x84C1
#define GL_TEXTURE2 0x84C2
#define GL_TEXTURE3 0x84C3
#define GL_TEXTURE4 0x84C4
const GLuint GL_ARRAY_BUFFER = 0x8892;
const GLuint GL_FRAGMENT_SHADER = 0x8B30;
const GLuint GL_STATIC_DRAW = 0x88E4;
const GLuint GL_VERTEX_SHADER = 0x8B31;
const GLuint GL_CLAMP_TO_EDGE = 0x812F;
const GLuint GL_TEXTURE0 = 0x84C0;
const GLuint GL_TEXTURE1 = 0x84C1;
const GLuint GL_TEXTURE2 = 0x84C2;
const GLuint GL_TEXTURE3 = 0x84C3;
const GLuint GL_TEXTURE4 = 0x84C4;
typedef ptrdiff_t GLsizeiptr;
typedef char GLchar;

View file

@ -1,6 +1,9 @@
#pragma once
#include "core/lux.h"
namespace Lux
{
@ -23,7 +26,7 @@ class Pose
Quat* getRotations() const { return m_rotations; }
private:
int m_count;
int32_t m_count;
Vec3* m_positions;
Quat* m_rotations;
};