moving majority of the matrix4x4 across to glm::mat4
moving majority of the matrix4x4 across to glm::mat4 This commit contains rendering issue
This commit is contained in:
@@ -10,7 +10,7 @@ namespace math
|
||||
ray (glm::vec3 origin, glm::vec3 const& direction): _origin (std::move (origin)), _direction (glm::normalize(direction))
|
||||
{}
|
||||
|
||||
ray (matrix_4x4 const& transform, ray const& other): ray (
|
||||
ray (glm::mat4x4 const& transform, ray const& other): ray (
|
||||
glm::vec3(
|
||||
(transform * glm::vec4(other._origin.x, other._origin.y, other._origin.z, 1.0))),
|
||||
glm::vec3((transform * glm::vec4(other._direction.x, other._direction.y, other._direction.z, 0.0)))
|
||||
|
||||
@@ -4138,19 +4138,10 @@ glm::mat4x4 MapView::model_view() const
|
||||
glm::vec3 target = eye;
|
||||
target.y -= 1.f;
|
||||
target.z -= 0.001f;
|
||||
|
||||
auto center = target;
|
||||
auto up = glm::vec3(0.f, 1.f, 0.f);
|
||||
|
||||
glm::vec3 const z = glm::normalize(eye - center);
|
||||
glm::vec3 const x = glm::normalize(glm::cross(up, z));
|
||||
glm::vec3 const y = glm::normalize(glm::cross(z, x));
|
||||
|
||||
return glm::transpose(glm::mat4x4(x.x, x.y, x.z, glm::dot(x, glm::vec3(-eye.x, -eye.y, -eye.z))
|
||||
, y.x, y.y, y.z, glm::dot(y, glm::vec3(-eye.x, -eye.y, -eye.z))
|
||||
, z.x, z.y, z.z, glm::dot(z, glm::vec3(-eye.x, -eye.y, -eye.z))
|
||||
, 0.f, 0.f, 0.f, 1.f
|
||||
));
|
||||
return glm::lookAt(eye, target, up);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <cassert>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
Model::Model(const std::string& filename, noggit::NoggitRenderContext context)
|
||||
: AsyncObject(filename)
|
||||
@@ -766,7 +767,7 @@ bool ModelRenderPass::prepare_draw(opengl::scoped::use_program& m2_shader, Model
|
||||
}
|
||||
|
||||
int16_t tex_anim_lookup = m->_texture_animation_lookups[uv_animations[0]];
|
||||
static const math::matrix_4x4 unit(math::matrix_4x4::unit);
|
||||
static const glm::mat4x4 unit(glm::mat4x4(1));
|
||||
|
||||
if (tex_anim_lookup != -1)
|
||||
{
|
||||
@@ -1230,13 +1231,13 @@ void Model::animate(glm::mat4x4 const& model_view, int anim_id, int anim_time)
|
||||
std::size_t bone_counter = 0;
|
||||
for (auto& bone : bones)
|
||||
{
|
||||
bone_matrices[bone_counter] = bone.mat.transposed();
|
||||
bone_matrices[bone_counter] = glm::transpose(bone.mat);
|
||||
bone_counter++;
|
||||
}
|
||||
|
||||
{
|
||||
opengl::scoped::buffer_binder<GL_TEXTURE_BUFFER> const binder (_bone_matrices_buffer);
|
||||
gl.bufferSubData(GL_TEXTURE_BUFFER, 0, bone_matrices.size() * sizeof(math::matrix_4x4), bone_matrices.data());
|
||||
gl.bufferSubData(GL_TEXTURE_BUFFER, 0, bone_matrices.size() * sizeof(glm::mat4x4), bone_matrices.data());
|
||||
}
|
||||
|
||||
|
||||
@@ -1275,8 +1276,8 @@ void Model::animate(glm::mat4x4 const& model_view, int anim_id, int anim_time)
|
||||
{
|
||||
if (_lights[i].parent >= 0)
|
||||
{
|
||||
_lights[i].tpos = bones[_lights[i].parent].mat * _lights[i].pos;
|
||||
_lights[i].tdir = bones[_lights[i].parent].mrot * _lights[i].dir;
|
||||
_lights[i].tpos = bones[_lights[i].parent].mat * glm::vec4(_lights[i].pos,0);
|
||||
_lights[i].tdir = bones[_lights[i].parent].mrot * glm::vec4(_lights[i].dir,0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1303,18 +1304,18 @@ void Model::animate(glm::mat4x4 const& model_view, int anim_id, int anim_time)
|
||||
|
||||
void TextureAnim::calc(int anim, int time, int animtime)
|
||||
{
|
||||
mat = math::matrix_4x4::unit;
|
||||
mat = glm::mat4x4(1);
|
||||
if (trans.uses(anim))
|
||||
{
|
||||
mat *= math::matrix_4x4 (math::matrix_4x4::translation, trans.getValue(anim, time, animtime));
|
||||
{
|
||||
mat = glm::translate(mat, trans.getValue(anim, time, animtime));
|
||||
}
|
||||
if (rot.uses(anim))
|
||||
{
|
||||
mat *= math::matrix_4x4 (math::matrix_4x4::rotation, rot.getValue(anim, time, animtime));
|
||||
mat *= glm::toMat4(rot.getValue(anim, time, animtime));
|
||||
}
|
||||
if (scale.uses(anim))
|
||||
{
|
||||
mat *= math::matrix_4x4 (math::matrix_4x4::scale, scale.getValue(anim, time, animtime));
|
||||
mat = glm::scale(mat, scale.getValue(anim, time, animtime));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1374,7 +1375,7 @@ TextureAnim::TextureAnim (const MPQFile& f, const ModelTexAnimDef &mta, int *glo
|
||||
: trans (mta.trans, f, global)
|
||||
, rot (mta.rot, f, global)
|
||||
, scale (mta.scale, f, global)
|
||||
, mat (math::matrix_4x4::uninitialized)
|
||||
, mat (glm::mat4x4())
|
||||
{}
|
||||
|
||||
Bone::Bone( const MPQFile& f,
|
||||
@@ -1403,8 +1404,8 @@ void Bone::calcMatrix(glm::mat4x4 const& model_view
|
||||
{
|
||||
if (calc) return;
|
||||
|
||||
math::matrix_4x4 m {math::matrix_4x4::unit};
|
||||
glm::quat q;
|
||||
glm::mat4x4 m = glm::mat4x4(1);
|
||||
glm::quat q = glm::quat();
|
||||
|
||||
if ( flags.transformed
|
||||
|| flags.billboard
|
||||
@@ -1413,38 +1414,44 @@ void Bone::calcMatrix(glm::mat4x4 const& model_view
|
||||
|| flags.cylindrical_billboard_lock_z
|
||||
)
|
||||
{
|
||||
m = {math::matrix_4x4::translation, pivot};
|
||||
m = glm::translate(m, pivot);
|
||||
|
||||
if (trans.uses(anim))
|
||||
{
|
||||
m *= math::matrix_4x4 (math::matrix_4x4::translation, trans.getValue (anim, time, animtime));
|
||||
m = glm::translate(m, trans.getValue (anim, time, animtime));
|
||||
}
|
||||
|
||||
if (rot.uses(anim))
|
||||
{
|
||||
m *= math::matrix_4x4 (math::matrix_4x4::rotation, q = rot.getValue (anim, time, animtime));
|
||||
m *= glm::toMat4(rot.getValue(anim, time, animtime));
|
||||
}
|
||||
|
||||
if (scale.uses(anim))
|
||||
{
|
||||
m *= math::matrix_4x4 (math::matrix_4x4::scale, scale.getValue (anim, time, animtime));
|
||||
m = glm::scale(m, scale.getValue (anim, time, animtime));
|
||||
}
|
||||
|
||||
if (flags.billboard)
|
||||
{
|
||||
glm::vec3 vRight (model_view[0][0], model_view[1][0], model_view[2][0]);
|
||||
glm::vec3 vUp (model_view[0][1], model_view[1][1], model_view[2][1]); // Spherical billboarding
|
||||
glm::vec3 vRight = model_view[0];
|
||||
glm::vec3 vUp = model_view[1];
|
||||
//glm::vec3 vUp = glm::vec3(0,1,0); // Cylindrical billboarding
|
||||
vRight = glm::vec3(vRight.x * -1, vRight.y * -1, vRight.z * -1);
|
||||
m (0, 2, vRight.x);
|
||||
m (1, 2, vRight.y);
|
||||
m (2, 2, vRight.z);
|
||||
m (0, 1, vUp.x);
|
||||
m (1, 1, vUp.y);
|
||||
m (2, 1, vUp.z);
|
||||
//m[0][2] = vRight.x;
|
||||
//m[1][2] = vRight.y;
|
||||
//m[2][2] = vRight.z;
|
||||
//m[0][1] = vUp.x;
|
||||
//m[1][1] = vUp.y;
|
||||
//m[2][1] = vUp.z;
|
||||
m[2][0] = vRight.x;
|
||||
m[2][1] = vRight.y;
|
||||
m[2][2] = vRight.z;
|
||||
m[1][0] = vUp.x;
|
||||
m[1][1] = vUp.y;
|
||||
m[1][2] = vUp.z;
|
||||
}
|
||||
|
||||
m *= math::matrix_4x4 (math::matrix_4x4::translation, -pivot);
|
||||
m = glm::translate(m, -pivot);
|
||||
}
|
||||
|
||||
if (parent >= 0)
|
||||
@@ -1462,16 +1469,16 @@ void Bone::calcMatrix(glm::mat4x4 const& model_view
|
||||
{
|
||||
if (parent >= 0)
|
||||
{
|
||||
mrot = allbones[parent].mrot * math::matrix_4x4 (math::matrix_4x4::rotation, q);
|
||||
mrot = allbones[parent].mrot * glm::toMat4(q);
|
||||
}
|
||||
else
|
||||
{
|
||||
mrot = math::matrix_4x4 (math::matrix_4x4::rotation, q);
|
||||
mrot = glm::toMat4(q);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mrot = math::matrix_4x4::unit;
|
||||
mrot = glm::mat4x4(1);
|
||||
}
|
||||
|
||||
calc = true;
|
||||
@@ -1541,7 +1548,7 @@ void Model::draw( glm::mat4x4 const& model_view
|
||||
}
|
||||
|
||||
void Model::draw (glm::mat4x4 const& model_view
|
||||
, std::vector<math::matrix_4x4> const& instances
|
||||
, std::vector<glm::mat4x4> const& instances
|
||||
, opengl::scoped::use_program& m2_shader
|
||||
, opengl::M2RenderState& model_render_state
|
||||
, math::frustum const& frustum
|
||||
@@ -1606,7 +1613,7 @@ void Model::draw (glm::mat4x4 const& model_view
|
||||
|
||||
{
|
||||
opengl::scoped::buffer_binder<GL_ARRAY_BUFFER> const transform_binder (_transform_buffer);
|
||||
gl.bufferData(GL_ARRAY_BUFFER, instances.size() * sizeof(::math::matrix_4x4), instances.data(), GL_DYNAMIC_DRAW);
|
||||
gl.bufferData(GL_ARRAY_BUFFER, instances.size() * sizeof(::glm::mat4x4), instances.data(), GL_DYNAMIC_DRAW);
|
||||
//m2_shader.attrib("transform", 0, 1);
|
||||
}
|
||||
|
||||
@@ -1635,7 +1642,7 @@ void Model::draw (glm::mat4x4 const& model_view
|
||||
|
||||
}
|
||||
|
||||
void Model::draw_particles( math::matrix_4x4 const& model_view
|
||||
void Model::draw_particles( glm::mat4x4 const& model_view
|
||||
, opengl::scoped::use_program& particles_shader
|
||||
, std::size_t instance_count
|
||||
)
|
||||
@@ -1755,7 +1762,7 @@ void Model::upload()
|
||||
{
|
||||
gl.bindTexture(GL_TEXTURE_BUFFER, _bone_matrices_buf_tex);
|
||||
opengl::scoped::buffer_binder<GL_TEXTURE_BUFFER> const binder(_bone_matrices_buffer);
|
||||
gl.bufferData(GL_TEXTURE_BUFFER, bone_matrices.size() * sizeof(math::matrix_4x4), nullptr, GL_STREAM_DRAW);
|
||||
gl.bufferData(GL_TEXTURE_BUFFER, bone_matrices.size() * sizeof(glm::mat4x4), nullptr, GL_STREAM_DRAW);
|
||||
gl.texBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, _bone_matrices_buffer);
|
||||
}
|
||||
|
||||
@@ -1829,7 +1836,7 @@ void Model::setupVAO(opengl::scoped::use_program& m2_shader)
|
||||
|
||||
{
|
||||
opengl::scoped::buffer_binder<GL_ARRAY_BUFFER> const transform_binder (_transform_buffer);
|
||||
gl.bufferData(GL_ARRAY_BUFFER, 10 * sizeof(::math::matrix_4x4), nullptr, GL_DYNAMIC_DRAW);
|
||||
gl.bufferData(GL_ARRAY_BUFFER, 10 * sizeof(::glm::mat4x4), nullptr, GL_DYNAMIC_DRAW);
|
||||
m2_shader.attrib("transform", 0, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,8 +52,8 @@ public:
|
||||
} bone_flags;
|
||||
|
||||
bone_flags flags;
|
||||
math::matrix_4x4 mat = math::matrix_4x4::uninitialized;
|
||||
math::matrix_4x4 mrot = math::matrix_4x4::uninitialized;
|
||||
glm::mat4x4 mat = glm::mat4x4();
|
||||
glm::mat4x4 mrot = glm::mat4x4();
|
||||
|
||||
bool calc;
|
||||
void calcMatrix(glm::mat4x4 const& model_view
|
||||
@@ -77,7 +77,7 @@ class TextureAnim {
|
||||
Animation::M2Value<glm::vec3> scale;
|
||||
|
||||
public:
|
||||
math::matrix_4x4 mat;
|
||||
glm::mat4x4 mat;
|
||||
|
||||
void calc(int anim, int time, int animtime);
|
||||
TextureAnim(const MPQFile& f, const ModelTexAnimDef &mta, int *global);
|
||||
@@ -224,7 +224,7 @@ public:
|
||||
, bool no_cull = false
|
||||
);
|
||||
void draw (glm::mat4x4 const& model_view
|
||||
, std::vector<math::matrix_4x4> const& instances
|
||||
, std::vector<glm::mat4x4> const& instances
|
||||
, opengl::scoped::use_program& m2_shader
|
||||
, opengl::M2RenderState& model_render_state
|
||||
, math::frustum const& frustum
|
||||
@@ -236,7 +236,7 @@ public:
|
||||
, display_mode display
|
||||
, bool no_cull = false
|
||||
);
|
||||
void draw_particles( math::matrix_4x4 const& model_view
|
||||
void draw_particles( glm::mat4x4 const& model_view
|
||||
, opengl::scoped::use_program& particles_shader
|
||||
, std::size_t instance_count
|
||||
);
|
||||
@@ -283,7 +283,7 @@ public:
|
||||
// Misc ?
|
||||
// ===============================
|
||||
std::vector<Bone> bones;
|
||||
std::vector<math::matrix_4x4> bone_matrices;
|
||||
std::vector<glm::mat4x4> bone_matrices;
|
||||
ModelHeader header;
|
||||
std::vector<uint16_t> blend_override;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
#include <math/bounding_box.hpp>
|
||||
#include <math/frustum.hpp>
|
||||
#include <noggit/Log.h>
|
||||
@@ -67,7 +68,7 @@ void ModelInstance::draw_box (glm::mat4x4 const& model_view
|
||||
|
||||
opengl::primitives::wire_box::getInstance(_context).draw ( model_view
|
||||
, projection
|
||||
, math::matrix_4x4(math::matrix_4x4::unit)
|
||||
, glm::mat4x4(glm::mat4x4((1)))
|
||||
, {0.0f, 1.0f, 0.0f, 1.0f}
|
||||
, extents[0]
|
||||
, extents[1]
|
||||
@@ -191,7 +192,13 @@ void ModelInstance::recalcExtents()
|
||||
point = transform(point);
|
||||
corners_in_world.push_back(point);
|
||||
}
|
||||
auto const rotated_corners_in_world (_transform_mat_transposed.transposed() * corners_in_world);
|
||||
|
||||
auto rotated_corners_in_world = std::vector<glm::vec3>();
|
||||
auto transposedMat = _transform_mat;
|
||||
for (auto const& point : corners_in_world)
|
||||
{
|
||||
rotated_corners_in_world.push_back(transposedMat * glm::vec4(point,0));
|
||||
}
|
||||
|
||||
math::aabb const bounding_of_rotated_points (rotated_corners_in_world);
|
||||
|
||||
@@ -255,23 +262,20 @@ void wmo_doodad_instance::update_transform_matrix_wmo(WMOInstance* wmo)
|
||||
return;
|
||||
}
|
||||
|
||||
world_pos = wmo->transformMatrix() * pos;
|
||||
world_pos = wmo->transformMatrix() * glm::vec4(pos,0);
|
||||
|
||||
math::matrix_4x4 m2_mat
|
||||
auto m2_mat = glm::mat4x4(1);
|
||||
m2_mat = glm::translate(m2_mat, pos);
|
||||
m2_mat = m2_mat * glm::toMat4(doodad_orientation);
|
||||
m2_mat = glm::scale(m2_mat, glm::vec3(scale));
|
||||
|
||||
glm::mat4x4 mat
|
||||
(
|
||||
math::matrix_4x4(math::matrix_4x4::translation, pos)
|
||||
* math::matrix_4x4 (math::matrix_4x4::rotation, doodad_orientation)
|
||||
* math::matrix_4x4 (math::matrix_4x4::scale, scale)
|
||||
wmo->transformMatrix() * m2_mat
|
||||
);
|
||||
|
||||
math::matrix_4x4 mat
|
||||
(
|
||||
wmo->transformMatrix()
|
||||
* m2_mat
|
||||
);
|
||||
|
||||
_transform_mat_inverted = mat.inverted();
|
||||
_transform_mat_transposed = mat.transposed();
|
||||
_transform_mat_inverted = glm::inverse(mat);
|
||||
_transform_mat_transposed = mat;
|
||||
|
||||
// to compute the size category (used in culling)
|
||||
recalcExtents();
|
||||
|
||||
@@ -268,7 +268,7 @@ void ParticleSystem::setup(int anim, int time, int animtime)
|
||||
manimtime = animtime;
|
||||
}
|
||||
|
||||
void ParticleSystem::draw( math::matrix_4x4 const& model_view
|
||||
void ParticleSystem::draw( glm::mat4x4 const& model_view
|
||||
, opengl::scoped::use_program& shader
|
||||
, GLuint const& transform_vbo
|
||||
, int instances_count
|
||||
@@ -325,8 +325,11 @@ void ParticleSystem::draw( math::matrix_4x4 const& model_view
|
||||
|
||||
if (billboard)
|
||||
{
|
||||
vRight = glm::vec3(model_view[0], model_view[4], model_view[8]);
|
||||
vUp = glm::vec3(model_view[1], model_view[5], model_view[9]); // Spherical billboarding
|
||||
vRight = model_view[0];
|
||||
vUp = model_view[1];
|
||||
|
||||
//vRight = glm::vec3(model_view[0][0], model_view[1][0], model_view[2][0]);
|
||||
//vUp = glm::vec3(model_view[0][1], model_view[1][1], model_view[2][1]); // Spherical billboarding
|
||||
//vUp = glm::vec3(0,1,0); // Cylindrical billboarding
|
||||
}
|
||||
|
||||
@@ -514,12 +517,12 @@ void ParticleSystem::unload()
|
||||
namespace
|
||||
{
|
||||
//Generates the rotation matrix based on spread
|
||||
math::matrix_4x4 CalcSpreadMatrix(float Spread1, float Spread2, float w, float l)
|
||||
glm::mat4x4 CalcSpreadMatrix(float Spread1, float Spread2, float w, float l)
|
||||
{
|
||||
int i, j;
|
||||
float a[2], c[2], s[2];
|
||||
|
||||
math::matrix_4x4 SpreadMat (math::matrix_4x4::unit);
|
||||
glm::mat4x4 SpreadMat = glm::mat4x4(1);
|
||||
|
||||
a[0] = misc::randfloat(-Spread1, Spread1) / 2.0f;
|
||||
a[1] = misc::randfloat(-Spread2, Spread2) / 2.0f;
|
||||
@@ -535,21 +538,21 @@ namespace
|
||||
}
|
||||
|
||||
{
|
||||
math::matrix_4x4 Temp (math::matrix_4x4::unit);
|
||||
Temp (1, 1, c[0]);
|
||||
Temp (2, 1, s[0]);
|
||||
Temp (2, 2, c[0]);
|
||||
Temp (1, 2, -s[0]);
|
||||
glm::mat4x4 Temp = glm::mat4x4(1);
|
||||
Temp[1][1] = c[0];
|
||||
Temp[2][1] = s[0];
|
||||
Temp[2][2] = c[0];
|
||||
Temp[1][2] = -s[0];
|
||||
|
||||
SpreadMat = SpreadMat*Temp;
|
||||
SpreadMat = SpreadMat * Temp;
|
||||
}
|
||||
|
||||
{
|
||||
math::matrix_4x4 Temp (math::matrix_4x4::unit);
|
||||
Temp (0, 0, c[1]);
|
||||
Temp (1, 0, s[1]);
|
||||
Temp (1, 1, c[1]);
|
||||
Temp (0, 1, -s[1]);
|
||||
glm::mat4x4 Temp = glm::mat4x4(1);
|
||||
Temp[0][0]= c[1];
|
||||
Temp[1][0]= s[1];
|
||||
Temp[1][1]= c[1];
|
||||
Temp[0][1]= -s[1];
|
||||
|
||||
SpreadMat = SpreadMat*Temp;
|
||||
}
|
||||
@@ -557,7 +560,7 @@ namespace
|
||||
float Size = std::abs(c[0])*l + std::abs(s[0])*w;
|
||||
for (i = 0; i<3; ++i)
|
||||
for (j = 0; j<3; j++)
|
||||
SpreadMat (i, j, SpreadMat (i, j) * Size);
|
||||
SpreadMat[i][j] = SpreadMat[i][j] * Size;
|
||||
|
||||
return SpreadMat;
|
||||
}
|
||||
@@ -610,7 +613,7 @@ Particle PlaneParticleEmitter::newParticle(ParticleSystem* sys, int anim, int ti
|
||||
auto mrot = sys->parent->mrot*CalcSpreadMatrix(spr, spr, 1.0f, 1.0f);
|
||||
|
||||
if (sys->flags == 1041) { // Trans Halo
|
||||
p.pos = sys->parent->mat * (sys->pos + glm::vec3(misc::randfloat(-l, l), 0, misc::randfloat(-w, w)));
|
||||
p.pos = sys->parent->mat * (glm::vec4(sys->pos,0) + glm::vec4(misc::randfloat(-l, l), 0, misc::randfloat(-w, w),0));
|
||||
|
||||
const float t = misc::randfloat(0.0f, 2.0f * glm::pi<float>());
|
||||
|
||||
@@ -626,30 +629,30 @@ Particle PlaneParticleEmitter::newParticle(ParticleSystem* sys, int anim, int ti
|
||||
}
|
||||
else if (sys->flags == 25 && sys->parent->parent<1) { // Weapon Flame
|
||||
p.pos = sys->parent->pivot + (sys->pos + glm::vec3(misc::randfloat(-l, l), misc::randfloat(-l, l), misc::randfloat(-w, w)));
|
||||
glm::vec3 dir = mrot * glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
glm::vec3 dir = mrot * glm::vec4(0.0f, 1.0f, 0.0f,0.0f);
|
||||
p.dir = glm::normalize(dir);
|
||||
//glm::vec3 dir = sys->model->bones[sys->parent->parent].mrot * sys->parent->mrot * glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
//p.speed = dir.normalize() * spd;
|
||||
|
||||
}
|
||||
else if (sys->flags == 25 && sys->parent->parent > 0) { // Weapon with built-in Flame (Avenger lightsaber!)
|
||||
p.pos = sys->parent->mat * (sys->pos + glm::vec3(misc::randfloat(-l, l), misc::randfloat(-l, l), misc::randfloat(-w, w)));
|
||||
glm::vec3 dir = glm::vec3(sys->parent->mat (1, 0), sys->parent->mat (1, 1), sys->parent->mat (1, 2)) + glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
p.pos = sys->parent->mat * (glm::vec4(sys->pos,0) + glm::vec4(misc::randfloat(-l, l), misc::randfloat(-l, l), misc::randfloat(-w, w),0));
|
||||
glm::vec3 dir = glm::vec4(sys->parent->mat[1][0], sys->parent->mat[1][1], sys->parent->mat [1][2],0.0f) + glm::vec4(0.0f, 1.0f, 0.0f,0.0f);
|
||||
p.speed = glm::normalize(dir) * spd * misc::randfloat(0, var * 2);
|
||||
|
||||
}
|
||||
else if (sys->flags == 17 && sys->parent->parent<1) { // Weapon Glow
|
||||
p.pos = sys->parent->pivot + (sys->pos + glm::vec3(misc::randfloat(-l, l), misc::randfloat(-l, l), misc::randfloat(-w, w)));
|
||||
glm::vec3 dir = mrot * glm::vec3(0, 1, 0);
|
||||
glm::vec3 dir = mrot * glm::vec4(0, 1, 0,0);
|
||||
p.dir = glm::normalize(dir);
|
||||
|
||||
}
|
||||
else {
|
||||
p.pos = sys->pos + glm::vec3(misc::randfloat(-l, l), 0, misc::randfloat(-w, w));
|
||||
p.pos = sys->parent->mat * p.pos;
|
||||
p.pos = sys->parent->mat * glm::vec4(p.pos,0);
|
||||
|
||||
//glm::vec3 dir = mrot * glm::vec3(0,1,0);
|
||||
glm::vec3 dir = sys->parent->mrot * glm::vec3(0, 1, 0);
|
||||
glm::vec3 dir = sys->parent->mrot * glm::vec4(0, 1, 0,0);
|
||||
|
||||
p.dir = dir;//.normalize();
|
||||
p.down = glm::vec3(0, -1.0f, 0); // dir * -1.0f;
|
||||
@@ -657,10 +660,10 @@ Particle PlaneParticleEmitter::newParticle(ParticleSystem* sys, int anim, int ti
|
||||
}
|
||||
|
||||
if (!sys->billboard) {
|
||||
p.corners[0] = mrot * glm::vec3(-1, 0, +1);
|
||||
p.corners[1] = mrot * glm::vec3(+1, 0, +1);
|
||||
p.corners[2] = mrot * glm::vec3(+1, 0, -1);
|
||||
p.corners[3] = mrot * glm::vec3(-1, 0, -1);
|
||||
p.corners[0] = mrot * glm::vec4(-1, 0, +1, 0);
|
||||
p.corners[1] = mrot * glm::vec4(+1, 0, +1, 0);
|
||||
p.corners[2] = mrot * glm::vec4(+1, 0, -1, 0);
|
||||
p.corners[3] = mrot * glm::vec4(-1, 0, -1, 0);
|
||||
}
|
||||
|
||||
p.life = 0;
|
||||
@@ -722,12 +725,12 @@ Particle SphereParticleEmitter::newParticle(ParticleSystem* sys, int anim, int t
|
||||
glm::vec3 bdir(w*glm::cos(t._)*1.6f, 0.0f, l*glm::sin(t._)*1.6f);
|
||||
|
||||
p.pos = sys->pos + bdir;
|
||||
p.pos = sys->parent->mat * p.pos;
|
||||
p.pos = sys->parent->mat * glm::vec4(p.pos,0);
|
||||
|
||||
if (glm::length(bdir) * glm::length(bdir) == 0)
|
||||
p.speed = glm::vec3(0, 0, 0);
|
||||
else {
|
||||
dir = sys->parent->mrot * (glm::normalize(bdir));//mrot * glm::vec3(0, 1.0f,0);
|
||||
dir = sys->parent->mrot * glm::vec4((glm::normalize(bdir)),0);//mrot * glm::vec3(0, 1.0f,0);
|
||||
p.speed = glm::normalize(dir) * spd * (1.0f + misc::randfloat(-var, var)); // ?
|
||||
}
|
||||
|
||||
@@ -736,12 +739,12 @@ Particle SphereParticleEmitter::newParticle(ParticleSystem* sys, int anim, int t
|
||||
glm::vec3 bdir;
|
||||
float temp;
|
||||
|
||||
bdir = mrot * glm::vec3(0, 1, 0) * radius;
|
||||
bdir = mrot * glm::vec4(0, 1, 0, 0) * radius;
|
||||
temp = bdir.z;
|
||||
bdir.z = bdir.y;
|
||||
bdir.y = temp;
|
||||
|
||||
p.pos = sys->parent->mat * sys->pos + bdir;
|
||||
p.pos = sys->parent->mat * glm::vec4(sys->pos,0) + glm::vec4(bdir,0);
|
||||
|
||||
|
||||
//p.pos = sys->pos + bdir;
|
||||
@@ -751,12 +754,12 @@ Particle SphereParticleEmitter::newParticle(ParticleSystem* sys, int anim, int t
|
||||
if (!(glm::length(bdir) * glm::length(bdir)) && !(sys->flags & 0x100))
|
||||
{
|
||||
p.speed = glm::vec3(0, 0, 0);
|
||||
dir = sys->parent->mrot * glm::vec3(0, 1, 0);
|
||||
dir = sys->parent->mrot * glm::vec4(0, 1, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sys->flags & 0x100)
|
||||
dir = sys->parent->mrot * glm::vec3(0, 1, 0);
|
||||
dir = sys->parent->mrot * glm::vec4(0, 1, 0, 0);
|
||||
else
|
||||
dir = glm::normalize(bdir);
|
||||
|
||||
@@ -855,8 +858,8 @@ RibbonEmitter::RibbonEmitter(RibbonEmitter&& other)
|
||||
|
||||
void RibbonEmitter::setup(int anim, int time, int animtime)
|
||||
{
|
||||
glm::vec3 ntpos = parent->mat * pos;
|
||||
glm::vec3 ntup = parent->mat * (pos + glm::vec3(0, 0, 1));
|
||||
glm::vec3 ntpos = parent->mat * glm::vec4(pos,0);
|
||||
glm::vec3 ntup = parent->mat * (glm::vec4(pos, 0) + glm::vec4(0, 0, 1,0));
|
||||
ntup -= ntpos;
|
||||
ntup = glm::normalize(ntup);
|
||||
float dlen = (ntpos - tpos).length();
|
||||
|
||||
@@ -93,7 +93,7 @@ public:
|
||||
void update(float dt);
|
||||
|
||||
void setup(int anim, int time, int animtime);
|
||||
void draw( math::matrix_4x4 const& model_view
|
||||
void draw( glm::mat4x4 const& model_view
|
||||
, opengl::scoped::use_program& shader
|
||||
, GLuint const& transform_vbo
|
||||
, int instances_count
|
||||
|
||||
@@ -63,12 +63,12 @@ void ViewportGizmo::handleTransformGizmo(MapView* map_view
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y);
|
||||
|
||||
math::matrix_4x4 delta_matrix = math::matrix_4x4(math::matrix_4x4::unit).transposed();
|
||||
math::matrix_4x4 object_matrix = {math::matrix_4x4::unit};
|
||||
math::matrix_4x4 pivot_matrix = math::matrix_4x4(math::matrix_4x4::translation,
|
||||
glm::mat4x4 delta_matrix = glm::transpose(glm::mat4x4(1.0f));
|
||||
glm::mat4x4 object_matrix = glm::mat4x4(1.0f);
|
||||
glm::mat4x4 pivot_matrix = glm::transpose(glm::translate(glm::mat4x4(),
|
||||
{_multiselection_pivot.x,
|
||||
_multiselection_pivot.y,
|
||||
_multiselection_pivot.z}).transposed();
|
||||
_multiselection_pivot.z }));
|
||||
float last_pivot_scale = 1.f;
|
||||
|
||||
switch (gizmo_selection_type)
|
||||
@@ -79,7 +79,7 @@ void ViewportGizmo::handleTransformGizmo(MapView* map_view
|
||||
obj_instance = boost::get<selected_object_type>(selection[0]);
|
||||
obj_instance->recalcExtents();
|
||||
object_matrix = obj_instance->transformMatrixTransposed();
|
||||
ImGuizmo::Manipulate(glm::value_ptr(model_view_trs), glm::value_ptr(projection_trs), _gizmo_operation, _gizmo_mode, object_matrix, delta_matrix, nullptr);
|
||||
ImGuizmo::Manipulate(glm::value_ptr(model_view_trs), glm::value_ptr(projection_trs), _gizmo_operation, _gizmo_mode, glm::value_ptr(object_matrix), glm::value_ptr(delta_matrix), nullptr);
|
||||
break;
|
||||
}
|
||||
case MULTISELECTION:
|
||||
@@ -87,7 +87,7 @@ void ViewportGizmo::handleTransformGizmo(MapView* map_view
|
||||
if (isUsing())
|
||||
_last_pivot_scale = ImGuizmo::GetOperationScaleLast();
|
||||
|
||||
ImGuizmo::Manipulate(glm::value_ptr(model_view_trs), glm::value_ptr(projection_trs), _gizmo_operation, _gizmo_mode, pivot_matrix, delta_matrix, nullptr);
|
||||
ImGuizmo::Manipulate(glm::value_ptr(model_view_trs), glm::value_ptr(projection_trs), _gizmo_operation, _gizmo_mode, glm::value_ptr(pivot_matrix), glm::value_ptr(delta_matrix), nullptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -113,9 +113,9 @@ void ViewportGizmo::handleTransformGizmo(MapView* map_view
|
||||
noggit::ActionManager::instance()->getCurrentAction()->registerObjectTransformed(obj_instance);
|
||||
|
||||
obj_instance->recalcExtents();
|
||||
object_matrix = math::matrix_4x4(obj_instance->transformMatrixTransposed());
|
||||
object_matrix = obj_instance->transformMatrixTransposed();
|
||||
|
||||
glm::mat4 glm_transform_mat = glm::make_mat4(static_cast<float*>(delta_matrix));
|
||||
glm::mat4 glm_transform_mat = delta_matrix;
|
||||
|
||||
glm::vec3& pos = obj_instance->pos;
|
||||
math::degrees::vec3& rotation = obj_instance->dir;
|
||||
@@ -163,10 +163,10 @@ void ViewportGizmo::handleTransformGizmo(MapView* map_view
|
||||
rotation.y += math::degrees(rot_euler.y)._;
|
||||
|
||||
// building model matrix
|
||||
glm::mat4 model_transform = glm::make_mat4(static_cast<float*>(object_matrix));
|
||||
glm::mat4 model_transform = object_matrix;
|
||||
|
||||
// only translation of pivot
|
||||
glm::mat4 transformed_pivot = glm::make_mat4(static_cast<float*>(pivot_matrix));
|
||||
glm::mat4 transformed_pivot = pivot_matrix;
|
||||
|
||||
// model matrix relative to translated pivot
|
||||
glm::mat4 model_transform_rel = glm::inverse(transformed_pivot) * model_transform;
|
||||
@@ -231,10 +231,10 @@ void ViewportGizmo::handleTransformGizmo(MapView* map_view
|
||||
noggit::ActionManager::instance()->getCurrentAction()->registerObjectTransformed(obj_instance);
|
||||
|
||||
obj_instance->recalcExtents();
|
||||
object_matrix = math::matrix_4x4(obj_instance->transformMatrixTransposed());
|
||||
object_matrix = obj_instance->transformMatrixTransposed();
|
||||
|
||||
|
||||
glm::mat4 glm_transform_mat = glm::make_mat4(static_cast<float*>(delta_matrix));
|
||||
glm::mat4 glm_transform_mat = delta_matrix;
|
||||
|
||||
glm::vec3& pos = obj_instance->pos;
|
||||
math::degrees::vec3& rotation = obj_instance->dir;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#include "SceneObject.hpp"
|
||||
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
#include <noggit/Misc.h>
|
||||
#include <math/trig.hpp>
|
||||
|
||||
@@ -26,20 +28,20 @@ bool SceneObject::isDuplicateOf(SceneObject const& other)
|
||||
|
||||
void SceneObject::updateTransformMatrix()
|
||||
{
|
||||
math::matrix_4x4 mat( math::matrix_4x4(math::matrix_4x4::translation, pos)
|
||||
* math::matrix_4x4
|
||||
( math::matrix_4x4::rotation_yzx
|
||||
, { -dir.z
|
||||
, dir.y - math::degrees(90.0)._
|
||||
, dir.x
|
||||
})
|
||||
auto rotationVector = glm::vec3(0);
|
||||
rotationVector.x = glm::radians(dir.x);
|
||||
rotationVector.y = glm::radians(dir.y - math::degrees(90.0)._);
|
||||
rotationVector.z = glm::radians(dir.z);
|
||||
|
||||
* math::matrix_4x4 (math::matrix_4x4::scale, scale)
|
||||
);
|
||||
auto matrix = glm::mat4x4(1);
|
||||
matrix = glm::translate(matrix, pos);
|
||||
glm::quat roationQuat = glm::quat(rotationVector);
|
||||
matrix = matrix * glm::toMat4(roationQuat);
|
||||
matrix = glm::scale(matrix, glm::vec3(scale, scale, scale));
|
||||
|
||||
_transform_mat = mat;
|
||||
_transform_mat_inverted = mat.inverted();
|
||||
_transform_mat_transposed = mat.transposed();
|
||||
_transform_mat = matrix;
|
||||
_transform_mat_inverted = glm::inverse(matrix);
|
||||
_transform_mat_transposed = matrix;
|
||||
}
|
||||
|
||||
void SceneObject::resetDirection()
|
||||
|
||||
@@ -40,13 +40,13 @@ public:
|
||||
void resetDirection();
|
||||
|
||||
[[nodiscard]]
|
||||
math::matrix_4x4 transformMatrix() const { return _transform_mat; };
|
||||
glm::mat4x4 transformMatrix() const { return _transform_mat; };
|
||||
|
||||
[[nodiscard]]
|
||||
math::matrix_4x4 transformMatrixInverted() const { return _transform_mat_inverted; };
|
||||
glm::mat4x4 transformMatrixInverted() const { return _transform_mat_inverted; };
|
||||
|
||||
[[nodiscard]]
|
||||
math::matrix_4x4 transformMatrixTransposed() const { return _transform_mat_transposed; };
|
||||
glm::mat4x4 transformMatrixTransposed() const { return _transform_mat_transposed; };
|
||||
|
||||
SceneObjectTypes which() const { return _type; };
|
||||
|
||||
@@ -69,9 +69,9 @@ public:
|
||||
protected:
|
||||
SceneObjectTypes _type;
|
||||
|
||||
math::matrix_4x4 _transform_mat = math::matrix_4x4::uninitialized;
|
||||
math::matrix_4x4 _transform_mat_inverted = math::matrix_4x4::uninitialized;
|
||||
math::matrix_4x4 _transform_mat_transposed = math::matrix_4x4::uninitialized;
|
||||
glm::mat4x4 _transform_mat = glm::mat4x4();
|
||||
glm::mat4x4 _transform_mat_inverted = glm::mat4x4();
|
||||
glm::mat4x4 _transform_mat_transposed = glm::mat4x4();
|
||||
|
||||
noggit::NoggitRenderContext _context;
|
||||
|
||||
|
||||
@@ -549,7 +549,7 @@ bool Skies::draw(glm::mat4x4 const& model_view
|
||||
return true;
|
||||
}
|
||||
|
||||
void Skies::drawLightingSpheres (math::matrix_4x4 const& model_view
|
||||
void Skies::drawLightingSpheres (glm::mat4x4 const& model_view
|
||||
, glm::mat4x4 const& projection
|
||||
, glm::vec3 const& camera_pos
|
||||
, math::frustum const& frustum
|
||||
@@ -562,13 +562,13 @@ void Skies::drawLightingSpheres (math::matrix_4x4 const& model_view
|
||||
{
|
||||
glm::vec3 diffuse = color_set[LIGHT_GLOBAL_DIFFUSE];
|
||||
glm::vec3 ambient = color_set[LIGHT_GLOBAL_AMBIENT];
|
||||
_sphere_render.draw(model_view.Convert() * projection, sky.pos, {ambient.x, ambient.y, ambient.z, 0.3}, sky.r1);
|
||||
_sphere_render.draw(model_view.Convert() * projection, sky.pos, {diffuse.x, diffuse.y, diffuse.z, 0.3}, sky.r2);
|
||||
_sphere_render.draw(model_view * projection, sky.pos, {ambient.x, ambient.y, ambient.z, 0.3}, sky.r1);
|
||||
_sphere_render.draw(model_view * projection, sky.pos, {diffuse.x, diffuse.y, diffuse.z, 0.3}, sky.r2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Skies::drawLightingSphereHandles (math::matrix_4x4 const& model_view
|
||||
void Skies::drawLightingSphereHandles (glm::mat4x4 const& model_view
|
||||
, glm::mat4x4 const& projection
|
||||
, glm::vec3 const& camera_pos
|
||||
, math::frustum const& frustum
|
||||
@@ -580,15 +580,15 @@ void Skies::drawLightingSphereHandles (math::matrix_4x4 const& model_view
|
||||
if ((sky.pos - camera_pos).length() - sky.r2 <= cull_distance) // TODO: frustum cull here
|
||||
{
|
||||
|
||||
_sphere_render.draw(model_view.Convert() * projection, sky.pos, {1.f, 0.f, 0.f, 1.f}, 5.f);
|
||||
_sphere_render.draw(model_view * projection, sky.pos, {1.f, 0.f, 0.f, 1.f}, 5.f);
|
||||
|
||||
if (sky.selected())
|
||||
{
|
||||
glm::vec3 diffuse = color_set[LIGHT_GLOBAL_DIFFUSE];
|
||||
glm::vec3 ambient = color_set[LIGHT_GLOBAL_AMBIENT];
|
||||
|
||||
_sphere_render.draw(model_view.Convert() * projection, sky.pos, {ambient.x, ambient.y, ambient.z, 0.3}, sky.r1);
|
||||
_sphere_render.draw(model_view.Convert() * projection, sky.pos, {diffuse.x, diffuse.y, diffuse.z, 0.3}, sky.r2);
|
||||
_sphere_render.draw(model_view * projection, sky.pos, {ambient.x, ambient.y, ambient.z, 0.3}, sky.r1);
|
||||
_sphere_render.draw(model_view * projection, sky.pos, {diffuse.x, diffuse.y, diffuse.z, 0.3}, sky.r2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,14 +170,14 @@ public:
|
||||
, OutdoorLightStats const& light_stats
|
||||
);
|
||||
|
||||
void drawLightingSpheres (math::matrix_4x4 const& model_view
|
||||
void drawLightingSpheres (glm::mat4x4 const& model_view
|
||||
, glm::mat4x4 const& projection
|
||||
, glm::vec3 const& camera_pos
|
||||
, math::frustum const& frustum
|
||||
, const float& cull_distance
|
||||
);
|
||||
|
||||
void drawLightingSphereHandles (math::matrix_4x4 const& model_view
|
||||
void drawLightingSphereHandles (glm::mat4x4 const& model_view
|
||||
, glm::mat4x4 const& projection
|
||||
, glm::vec3 const& camera_pos
|
||||
, math::frustum const& frustum
|
||||
|
||||
@@ -351,8 +351,8 @@ void WMO::waitForChildrenLoaded()
|
||||
void WMO::draw ( opengl::scoped::use_program& wmo_shader
|
||||
, glm::mat4x4 const& model_view
|
||||
, glm::mat4x4 const& projection
|
||||
, math::matrix_4x4 const& transform_matrix
|
||||
, math::matrix_4x4 const& transform_matrix_transposed
|
||||
, glm::mat4x4 const& transform_matrix
|
||||
, glm::mat4x4 const& transform_matrix_transposed
|
||||
, bool boundingbox
|
||||
, math::frustum const& frustum
|
||||
, const float& cull_distance
|
||||
@@ -1500,14 +1500,14 @@ void WMOGroup::fix_vertex_color_alpha()
|
||||
}
|
||||
}
|
||||
|
||||
bool WMOGroup::is_visible( math::matrix_4x4 const& transform
|
||||
bool WMOGroup::is_visible( glm::mat4x4 const& transform
|
||||
, math::frustum const& frustum
|
||||
, float const& cull_distance
|
||||
, glm::vec3 const& camera
|
||||
, display_mode display
|
||||
) const
|
||||
{
|
||||
glm::vec3 pos = transform * center;
|
||||
glm::vec3 pos = transform * glm::vec4(center, 0);
|
||||
|
||||
if (!frustum.intersects(pos + BoundingBoxMin, pos + BoundingBoxMax))
|
||||
{
|
||||
@@ -1612,7 +1612,7 @@ void WMOGroup::intersect (math::ray const& ray, std::vector<float>* results) con
|
||||
}
|
||||
|
||||
/*
|
||||
void WMOGroup::drawLiquid ( math::matrix_4x4 const& transform
|
||||
void WMOGroup::drawLiquid ( glm::mat4x4 const& transform
|
||||
, liquid_render& render
|
||||
, bool // draw_fog
|
||||
, int animtime
|
||||
|
||||
@@ -146,7 +146,7 @@ public:
|
||||
);
|
||||
|
||||
/*
|
||||
void drawLiquid ( math::matrix_4x4 const& transform
|
||||
void drawLiquid ( glm::mat4x4 const& transform
|
||||
, liquid_render& render
|
||||
, bool draw_fog
|
||||
, int animtime
|
||||
@@ -159,7 +159,7 @@ public:
|
||||
void intersect (math::ray const&, std::vector<float>* results) const;
|
||||
|
||||
// todo: portal culling
|
||||
bool is_visible( math::matrix_4x4 const& transform_matrix
|
||||
bool is_visible( glm::mat4x4 const& transform_matrix
|
||||
, math::frustum const& frustum
|
||||
, float const& cull_distance
|
||||
, glm::vec3 const& camera
|
||||
@@ -295,8 +295,8 @@ public:
|
||||
void draw ( opengl::scoped::use_program& wmo_shader
|
||||
, glm::mat4x4 const& model_view
|
||||
, glm::mat4x4 const& projection
|
||||
, math::matrix_4x4 const& transform_matrix
|
||||
, math::matrix_4x4 const& transform_matrix_transposed
|
||||
, glm::mat4x4 const& transform_matrix
|
||||
, glm::mat4x4 const& transform_matrix_transposed
|
||||
, bool boundingbox
|
||||
, math::frustum const& frustum
|
||||
, const float& cull_distance
|
||||
|
||||
@@ -95,7 +95,7 @@ void WMOInstance::draw ( opengl::scoped::use_program& wmo_shader
|
||||
return;
|
||||
}
|
||||
|
||||
wmo_shader.uniform("transform", _transform_mat_transposed);
|
||||
wmo_shader.uniform("transform", _transform_mat);
|
||||
|
||||
wmo->draw ( wmo_shader
|
||||
, model_view
|
||||
@@ -124,7 +124,7 @@ void WMOInstance::draw ( opengl::scoped::use_program& wmo_shader
|
||||
|
||||
opengl::primitives::wire_box::getInstance(_context).draw(model_view
|
||||
, projection
|
||||
, math::matrix_4x4(math::matrix_4x4::unit)
|
||||
, glm::mat4x4(glm::mat4x4(1))
|
||||
, color
|
||||
, extents[0]
|
||||
, extents[1]);
|
||||
@@ -169,23 +169,34 @@ void WMOInstance::recalcExtents()
|
||||
glm::vec3 wmo_min(misc::transform_model_box_coords(wmo->extents[0]));
|
||||
glm::vec3 wmo_max(misc::transform_model_box_coords(wmo->extents[1]));
|
||||
|
||||
auto&& root_points = _transform_mat * math::aabb(wmo_min, wmo_max).all_corners();
|
||||
auto&& root_points = math::aabb(wmo_min, wmo_max).all_corners();
|
||||
auto adjustedPoints = std::vector<glm::vec3>();
|
||||
|
||||
points.insert(points.end(), root_points.begin(), root_points.end());
|
||||
for (auto const& point : root_points)
|
||||
{
|
||||
adjustedPoints.push_back(_transform_mat * glm::vec4(point,0));
|
||||
}
|
||||
|
||||
points.insert(points.end(), adjustedPoints.begin(), adjustedPoints.end());
|
||||
|
||||
for (int i = 0; i < (int)wmo->groups.size(); ++i)
|
||||
{
|
||||
auto const& group = wmo->groups[i];
|
||||
auto&& group_points = _transform_mat
|
||||
* math::aabb( group.BoundingBoxMin // no need to use misc::transform_model_box_coords
|
||||
, group.BoundingBoxMax // they are already in world coord (see group ctor)
|
||||
).all_corners();
|
||||
|
||||
points.insert(points.end(), group_points.begin(), group_points.end());
|
||||
auto&& group_points = math::aabb(group.BoundingBoxMin, group.BoundingBoxMax).all_corners();
|
||||
auto adjustedGroupPoints = std::vector<glm::vec3>();
|
||||
|
||||
for (auto const& point : group_points)
|
||||
{
|
||||
adjustedGroupPoints.push_back(_transform_mat * glm::vec4(point, 0));
|
||||
}
|
||||
|
||||
|
||||
points.insert(points.end(), adjustedGroupPoints.begin(), adjustedGroupPoints.end());
|
||||
|
||||
if (group.has_skybox())
|
||||
{
|
||||
math::aabb const group_aabb(group_points);
|
||||
math::aabb const group_aabb(adjustedGroupPoints);
|
||||
|
||||
group_extents[i] = {group_aabb.min, group_aabb.max};
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
#define BOOST_POOL_NO_MT
|
||||
|
||||
@@ -764,11 +765,12 @@ void World::rotate_selected_models(math::degrees rx, math::degrees ry, math::deg
|
||||
|
||||
if (use_pivot && has_multi_select)
|
||||
{
|
||||
|
||||
glm::vec3& pos = obj->pos;
|
||||
math::degrees::vec3& dir = obj->dir;
|
||||
glm::vec3 diff_pos = pos - _multi_select_pivot.get();
|
||||
glm::vec3 rot_result = math::matrix_4x4(math::matrix_4x4::rotation_xyz, {rx._, ry._, rz._ }) * diff_pos;
|
||||
|
||||
glm::quat rotationQuat = glm::quat(glm::vec3(glm::radians(rx._), glm::radians(ry._), glm::radians(rz._)));
|
||||
glm::vec3 rot_result = glm::toMat4(rotationQuat) * glm::vec4(diff_pos,0);
|
||||
|
||||
pos += rot_result - diff_pos;
|
||||
}
|
||||
@@ -1110,7 +1112,7 @@ void World::draw (glm::mat4x4 const& model_view
|
||||
ZoneScoped;
|
||||
|
||||
glm::mat4x4 const mvp(projection * model_view);
|
||||
math::frustum const frustum (glm::transpose(mvp));
|
||||
math::frustum const frustum (mvp);
|
||||
|
||||
if (camera_moved)
|
||||
updateMVPUniformBlock(model_view, projection);
|
||||
@@ -1379,7 +1381,7 @@ void World::draw (glm::mat4x4 const& model_view
|
||||
|
||||
std::unordered_map<Model*, std::size_t> model_with_particles;
|
||||
|
||||
tsl::robin_map<Model*, std::vector<math::matrix_4x4, boost::pool_allocator<math::matrix_4x4>>> models_to_draw;
|
||||
tsl::robin_map<Model*, std::vector<glm::mat4x4, boost::pool_allocator<glm::mat4x4>>> models_to_draw;
|
||||
std::vector<WMOInstance*, boost::pool_allocator<WMOInstance*>> wmos_to_draw;
|
||||
|
||||
static int frame = 0;
|
||||
@@ -1532,7 +1534,7 @@ void World::draw (glm::mat4x4 const& model_view
|
||||
gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, _occluder_index);
|
||||
gl.disable(GL_CULL_FACE); // TODO: figure out why indices are bad and we need this
|
||||
|
||||
math::matrix_4x4 identity_mtx = math::matrix_4x4{math::matrix_4x4::unit};
|
||||
glm::mat4x4 identity_mtx = glm::mat4x4{glm::mat4x4(1)};
|
||||
for (auto& pair : _loaded_tiles_buffer)
|
||||
{
|
||||
MapTile* tile = pair.second;
|
||||
@@ -1620,7 +1622,7 @@ void World::draw (glm::mat4x4 const& model_view
|
||||
if (draw_hidden_models || !pair.first->is_hidden())
|
||||
{
|
||||
pair.first->draw( model_view
|
||||
, reinterpret_cast<std::vector<math::matrix_4x4> const&>(pair.second)
|
||||
, reinterpret_cast<std::vector<glm::mat4x4> const&>(pair.second)
|
||||
, m2_shader
|
||||
, model_render_state
|
||||
, frustum
|
||||
@@ -1681,7 +1683,7 @@ void World::draw (glm::mat4x4 const& model_view
|
||||
models_to_draw.clear();
|
||||
wmos_to_draw.clear();
|
||||
boost::singleton_pool<boost::pool_allocator_tag
|
||||
, sizeof(std::vector<math::matrix_4x4, boost::pool_allocator<math::matrix_4x4>>)>::purge_memory();
|
||||
, sizeof(std::vector<glm::mat4x4, boost::pool_allocator<glm::mat4x4>>)>::purge_memory();
|
||||
|
||||
boost::singleton_pool<boost::pool_allocator_tag
|
||||
, sizeof(std::vector<WMOInstance*, boost::pool_allocator<WMOInstance*>>)>::purge_memory();
|
||||
@@ -2460,7 +2462,7 @@ void World::drawMinimap ( MapTile *tile
|
||||
_global_vbos_initialized = true;
|
||||
}
|
||||
|
||||
math::matrix_4x4 const mvp(model_view * projection);
|
||||
glm::mat4x4 const mvp(model_view * projection);
|
||||
math::frustum const frustum(mvp);
|
||||
|
||||
if (!_m2_program_mini)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
#include <noggit/camera.hpp>
|
||||
|
||||
namespace noggit
|
||||
@@ -70,9 +71,9 @@ namespace noggit
|
||||
|
||||
glm::vec3 camera::direction() const
|
||||
{
|
||||
glm::vec3 forward (1.0f, 0.0f, 0.0f);
|
||||
|
||||
return glm::normalize((math::matrix_4x4(math::matrix_4x4::rotation_yzx, math::degrees::vec3(_roll._, _yaw._, _pitch._)) * forward));
|
||||
glm::vec4 forward (0.0f, 0.0f, 1.0f,0.0f);
|
||||
auto rotation = glm::quat(glm::vec3(glm::radians(_pitch._),glm::radians(_yaw._), glm::radians(_roll._)));
|
||||
return glm::normalize(glm::toMat4(rotation) * forward);
|
||||
}
|
||||
|
||||
glm::mat4x4 camera::look_at_matrix() const
|
||||
@@ -81,15 +82,7 @@ namespace noggit
|
||||
auto center = look_at();
|
||||
auto up = glm::vec3(0.f, 1.f, 0.f);
|
||||
|
||||
glm::vec3 const z = glm::normalize(eye - center);
|
||||
glm::vec3 const x = glm::normalize(glm::cross(up, z));
|
||||
glm::vec3 const y = glm::normalize(glm::cross(z, x));
|
||||
|
||||
return glm::transpose(glm::mat4x4(x.x, x.y, x.z, glm::dot(x, glm::vec3(-eye.x, -eye.y, -eye.z))
|
||||
, y.x, y.y, y.z, glm::dot(y, glm::vec3(-eye.x, -eye.y, -eye.z))
|
||||
, z.x, z.y, z.z, glm::dot(z, glm::vec3(-eye.x, -eye.y, -eye.z))
|
||||
, 0.f, 0.f, 0.f, 1.f
|
||||
));
|
||||
return glm::lookAt(eye, center, up);
|
||||
}
|
||||
|
||||
void camera::move_forward (float sign, float dt)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
namespace noggit
|
||||
{
|
||||
void cursor_render::draw(mode cursor_mode, math::matrix_4x4 const& mvp, glm::vec4 color, glm::vec3 const& pos, float radius, float inner_radius_ratio)
|
||||
void cursor_render::draw(mode cursor_mode, glm::mat4x4 const& mvp, glm::vec4 color, glm::vec3 const& pos, float radius, float inner_radius_ratio)
|
||||
{
|
||||
if (!_uploaded)
|
||||
{
|
||||
@@ -100,18 +100,20 @@ namespace noggit
|
||||
|
||||
for (int r = 0; r <= rotation_plane; ++r)
|
||||
{
|
||||
math::degrees rotation(360.f*r / static_cast<float>(rotation_plane));
|
||||
math::degrees rotation(360.f*r / static_cast<float>(rotation_plane));
|
||||
|
||||
glm::mat4x4 rotationMatrix = glm::mat4x4();
|
||||
glm::mat4x4 m = glm::rotate(rotationMatrix, math::radians(rotation)._, glm::vec3(0, 0, 1));
|
||||
|
||||
math::matrix_4x4 m(math::matrix_4x4::rotation_xyz, math::degrees::vec3(math::degrees(0.f)._, math::degrees(0.f)._, rotation._));
|
||||
|
||||
for (int i = 0; i < segment; ++i)
|
||||
{
|
||||
float x = glm::cos(math::radians(math::degrees(i * 360 / segment))._);
|
||||
float z = glm::sin(math::radians(math::degrees(i * 360 / segment))._);
|
||||
|
||||
glm::vec3 v(x, 0.f, z);
|
||||
glm::vec4 v(x, 0.f, z,0);
|
||||
|
||||
vertices.emplace_back(m*v);
|
||||
vertices.emplace_back(m * v);
|
||||
if (r < rotation_plane)
|
||||
{
|
||||
indices.emplace_back(i + id_ofs);
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace noggit
|
||||
mode_count
|
||||
};
|
||||
|
||||
void draw(mode cursor_mode, math::matrix_4x4 const& mvp, glm::vec4 color, glm::vec3 const& pos, float radius, float inner_radius_ratio = 0.f);
|
||||
void draw(mode cursor_mode, glm::mat4x4 const& mvp, glm::vec4 color, glm::vec3 const& pos, float radius, float inner_radius_ratio = 0.f);
|
||||
|
||||
void unload();
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ void wmo_liquid::upload(opengl::scoped::use_program& water_shader)
|
||||
}
|
||||
|
||||
/*
|
||||
void wmo_liquid::draw ( math::matrix_4x4 const& transform
|
||||
void wmo_liquid::draw ( glm::mat4x4 const& transform
|
||||
, liquid_render& render
|
||||
, int animtime
|
||||
)
|
||||
|
||||
@@ -364,7 +364,7 @@ namespace noggit
|
||||
gl.activeTexture(GL_TEXTURE0);
|
||||
gl.bindTexture(GL_TEXTURE_BUFFER, _m2_instances_transform_buf_tex);
|
||||
gl.bindBuffer(GL_TEXTURE_BUFFER, _m2_instances_transform_buf);
|
||||
gl.bufferData(GL_TEXTURE_BUFFER, _n_allocated_m2_transforms * sizeof(math::matrix_4x4), nullptr, GL_DYNAMIC_DRAW);
|
||||
gl.bufferData(GL_TEXTURE_BUFFER, _n_allocated_m2_transforms * sizeof(glm::mat4x4), nullptr, GL_DYNAMIC_DRAW);
|
||||
gl.texBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, _m2_instances_transform_buf);
|
||||
|
||||
_transform_storage_uploaded = true;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
namespace opengl
|
||||
{
|
||||
@@ -18,7 +19,7 @@ namespace opengl
|
||||
{
|
||||
void wire_box::draw ( glm::mat4x4 const& model_view
|
||||
, glm::mat4x4 const& projection
|
||||
, math::matrix_4x4 const& transform
|
||||
, glm::mat4x4 const& transform
|
||||
, glm::vec4 const& color
|
||||
, glm::vec3 const& min_point
|
||||
, glm::vec3 const& max_point
|
||||
@@ -330,16 +331,15 @@ void main()
|
||||
for (int rotation_step = 0; rotation_step <= segment; ++rotation_step)
|
||||
{
|
||||
math::degrees rotation(360.f*rotation_step / static_cast<float>(segment));
|
||||
math::matrix_4x4 m(math::matrix_4x4::rotation_xyz, math::degrees::vec3(math::degrees(0.f)._, math::degrees(0.f)._, rotation._));
|
||||
|
||||
auto rotationQuat = glm::angleAxis(rotation._, glm::vec3(0, 0, 1));
|
||||
for (int i = 0; i < segment; ++i)
|
||||
{
|
||||
float x = glm::cos(math::radians(math::degrees(i * 360 / segment))._);
|
||||
float z = glm::sin(math::radians(math::degrees(i * 360 / segment))._);
|
||||
|
||||
glm::vec3 v(x, 0.f, z);
|
||||
glm::vec4 v(x, 0.f, z,0.0f);
|
||||
|
||||
vertices.emplace_back(m*v);
|
||||
vertices.emplace_back(glm::toMat4(rotationQuat) * v);
|
||||
|
||||
if (rotation_step < segment)
|
||||
{
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace opengl
|
||||
|
||||
void draw ( glm::mat4x4 const& model_view
|
||||
, glm::mat4x4 const& projection
|
||||
, math::matrix_4x4 const& transform
|
||||
, glm::mat4x4 const& transform
|
||||
, glm::vec4 const& color
|
||||
, glm::vec3 const& min_point
|
||||
, glm::vec3 const& max_point
|
||||
|
||||
@@ -328,18 +328,6 @@ namespace opengl
|
||||
{
|
||||
gl.uniform4fv (pos, 1, glm::value_ptr(value));
|
||||
}
|
||||
void use_program::uniform (std::string const& name, math::matrix_4x4 const& value)
|
||||
{
|
||||
GLuint loc = uniform_location (name);
|
||||
if (loc < 0)
|
||||
return;
|
||||
|
||||
gl.uniformMatrix4fv (loc, 1, GL_FALSE, value);
|
||||
}
|
||||
void use_program::uniform (GLint pos, math::matrix_4x4 const& value)
|
||||
{
|
||||
gl.uniformMatrix4fv(pos, 1, GL_FALSE, value);
|
||||
}
|
||||
|
||||
void use_program::uniform(std::string const& name, glm::mat4x4 const& value)
|
||||
{
|
||||
@@ -389,7 +377,7 @@ namespace opengl
|
||||
_enabled_vertex_attrib_arrays.emplace (location);
|
||||
gl.vertexAttribPointer (location, 3, GL_FLOAT, GL_FALSE, 0, data);
|
||||
}
|
||||
void use_program::attrib (std::string const& name, math::matrix_4x4 const* data, GLuint divisor)
|
||||
void use_program::attrib (std::string const& name, glm::mat4x4 const* data, GLuint divisor)
|
||||
{
|
||||
GLuint const location (attrib_location (name));
|
||||
glm::vec4 const* vec4_ptr = reinterpret_cast<glm::vec4 const*>(data);
|
||||
@@ -398,7 +386,7 @@ namespace opengl
|
||||
{
|
||||
gl.enableVertexAttribArray (location + i);
|
||||
_enabled_vertex_attrib_arrays.emplace (location + i);
|
||||
gl.vertexAttribPointer (location + i, 4, GL_FLOAT, GL_FALSE, sizeof(math::matrix_4x4), vec4_ptr + i);
|
||||
gl.vertexAttribPointer (location + i, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4x4), vec4_ptr + i);
|
||||
gl.vertexAttribDivisor(location + i, divisor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,8 +113,6 @@ namespace opengl
|
||||
void uniform (GLint pos, glm::vec3 const&);
|
||||
void uniform (std::string const& name, glm::vec4 const&);
|
||||
void uniform (GLint pos, glm::vec4 const&);
|
||||
void uniform (std::string const& name, math::matrix_4x4 const&);
|
||||
void uniform (GLint pos, math::matrix_4x4 const&);
|
||||
void uniform(std::string const& name, glm::mat4x4 const&);
|
||||
void uniform(GLint pos, glm::mat4x4 const&);
|
||||
template<typename T> void uniform (std::string const&, T) = delete;
|
||||
@@ -131,7 +129,7 @@ namespace opengl
|
||||
void attrib (std::string const& name, std::vector<glm::vec2> const&);
|
||||
void attrib (std::string const& name, std::vector<glm::vec3> const&);
|
||||
void attrib (std::string const& name, glm::vec3 const*);
|
||||
void attrib (std::string const& name, math::matrix_4x4 const*, GLuint divisor = 0);
|
||||
void attrib (std::string const& name, glm::mat4x4 const*, GLuint divisor = 0);
|
||||
void attrib (std::string const& name, GLsizei size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* data);
|
||||
void attrib (std::string const& name, GLuint buffer, GLsizei size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* data);
|
||||
void attribi (std::string const& name, GLuint buffer, GLsizei size, GLenum type, GLsizei stride, const GLvoid* data);
|
||||
|
||||
Reference in New Issue
Block a user