From: Mikko Rasa Date: Thu, 13 Nov 2014 21:22:04 +0000 (+0200) Subject: Adapt to the new vector/matrix slicing API in mspmath X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=50a0c7fd661fe6bfa3f929ad66e47cfab4a0fb87;p=libs%2Fgl.git Adapt to the new vector/matrix slicing API in mspmath --- diff --git a/source/camera.cpp b/source/camera.cpp index a0c89e0e..6cbcf6f4 100644 --- a/source/camera.cpp +++ b/source/camera.cpp @@ -82,7 +82,7 @@ void Camera::look_at(const Vector3 &p) Vector3 Camera::project(const Vector4 &p) const { Vector4 r = proj_matrix*(view_matrix*p); - return Vector3(r)/r.w; + return r.slice<3>(0)/r.w; } Vector3 Camera::project(const Vector3 &p) const @@ -121,10 +121,10 @@ void Camera::update_object_matrix() { Vector3 right_dir = normalize(cross(look_dir, up_dir)); Vector4 columns[4]; - columns[0] = Vector4(right_dir, 0.0f); - columns[1] = Vector4(cross(right_dir, look_dir), 0.0f); - columns[2] = Vector4(-look_dir, 0.0f); - columns[3] = Vector4(position, 1.0f); + columns[0] = compose(right_dir, 0.0f); + columns[1] = compose(cross(right_dir, look_dir), 0.0f); + columns[2] = compose(-look_dir, 0.0f); + columns[3] = compose(position, 1.0f); object_matrix = Matrix::from_columns(columns); view_matrix = invert(object_matrix); } diff --git a/source/environmentmap.cpp b/source/environmentmap.cpp index ec406d15..1e6f639a 100644 --- a/source/environmentmap.cpp +++ b/source/environmentmap.cpp @@ -79,19 +79,8 @@ void EnvironmentMap::render(Renderer &renderer, const Tag &tag) const shdata.uniform("environment", static_cast(unit)); Bind _bind_env(env_tex, unit); - const Matrix &view_matrix = renderer.get_camera()->get_matrix(); - // XXX The camera should maybe have store its own object matrix - float env_mdata[9]; - env_mdata[0] = view_matrix[0]; - env_mdata[1] = view_matrix[4]; - env_mdata[2] = view_matrix[8]; - env_mdata[3] = view_matrix[1]; - env_mdata[4] = view_matrix[5]; - env_mdata[5] = view_matrix[9]; - env_mdata[6] = view_matrix[2]; - env_mdata[7] = view_matrix[6]; - env_mdata[8] = view_matrix[10]; - shdata.uniform_matrix3("env_eye_matrix", env_mdata); + const Matrix &camera_matrix = renderer.get_camera()->get_object_matrix(); + shdata.uniform("env_eye_matrix", camera_matrix.block<3, 3>(0, 0)); renderer.add_shader_data(shdata); renderer.render(renderable, tag); diff --git a/source/lighting.cpp b/source/lighting.cpp index d1fd9a70..239bdc19 100644 --- a/source/lighting.cpp +++ b/source/lighting.cpp @@ -62,7 +62,7 @@ void Lighting::update_shader_data(ProgramData &shdata, const Matrix &view_matrix { shdata.uniform("ambient_color", ambient); shdata.uniform("sky_color", sky_color); - shdata.uniform("eye_sky_dir", Vector3(view_matrix*Vector4(sky_direction, 0.0f))); + shdata.uniform("eye_sky_dir", view_matrix.block<3, 3>(0, 0)*sky_direction); shdata.uniform("horizon_limit", horizon_angle.radians()); for(unsigned i=0; i(0); } float Matrix::operator[](unsigned i) const diff --git a/source/renderer.cpp b/source/renderer.cpp index bc49b0f8..184d3269 100644 --- a/source/renderer.cpp +++ b/source/renderer.cpp @@ -257,10 +257,7 @@ void Renderer::apply_state() { const Matrix &m = mtx_stack.top(); standard_shdata.uniform("eye_obj_matrix", mtx_stack.top()); - LinAl::SquareMatrix nm; - for(unsigned i=0; i<3; ++i) - for(unsigned j=0; j<3; ++j) - nm(i, j) = m(i, j); + LinAl::SquareMatrix nm = m.block<3, 3>(0, 0); nm = transpose(invert(nm)); standard_shdata.uniform_matrix3("eye_obj_normal_matrix", &nm(0, 0)); changed &= ~MODERN_MATRIX; diff --git a/source/shadowmap.cpp b/source/shadowmap.cpp index 372fa113..bc46f2c1 100644 --- a/source/shadowmap.cpp +++ b/source/shadowmap.cpp @@ -70,10 +70,10 @@ void ShadowMap::setup_frame() const { /* XXX Not really proper way to support positional lights, but good enough when the light source is far away */ - back = Vector3(lpos)-target; + back = lpos.slice<3>(0)-target; } else - back = Vector3(lpos); + back = lpos.slice<3>(0); back.normalize(); Vector3 up; @@ -85,10 +85,10 @@ void ShadowMap::setup_frame() const Vector3 right = normalize(cross(up, back)); Vector4 columns[4]; - columns[0] = Vector4(right, 0.0f); - columns[1] = Vector4(normalize(cross(back, right)), 0.0f); - columns[2] = Vector4(back, 0.0f); - columns[3] = Vector4(target, 1.0f); + columns[0] = compose(right, 0.0f); + columns[1] = compose(normalize(cross(back, right)), 0.0f); + columns[2] = compose(back, 0.0f); + columns[3] = compose(target, 1.0f); light_matrix = Matrix::from_columns(columns); view_matrix = invert(light_matrix); diff --git a/source/zsortedscene.cpp b/source/zsortedscene.cpp index da406b7e..5cbd2021 100644 --- a/source/zsortedscene.cpp +++ b/source/zsortedscene.cpp @@ -44,7 +44,7 @@ void ZSortedScene::render(Renderer &renderer, const Tag &tag) const if(const Matrix *model_matrix = (*i)->get_matrix()) { if(const Geometry::BoundingSphere *bsphere = (*i)->get_bounding_sphere()) - z = (view_matrix**model_matrix*Vector4(bsphere->get_center(), 1.0f)).z+bsphere->get_radius()*radius_factor; + z = (view_matrix**model_matrix*compose(bsphere->get_center(), 1.0f)).z+bsphere->get_radius()*radius_factor; else z = (view_matrix**model_matrix*Vector4(0.0f, 0.0f, 0.0f, 1.0f)).z; }