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
{
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);
}
shdata.uniform("environment", static_cast<int>(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);
{
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<lights.size(); ++i)
Vector3 Matrix::operator*(const Vector3 &vec) const
{
- return Vector3((*this)*Vector4(vec, 1.0f));
+ return ((*this)*compose(vec, 1.0f)).slice<3>(0);
}
float Matrix::operator[](unsigned i) const
{
const Matrix &m = mtx_stack.top();
standard_shdata.uniform("eye_obj_matrix", mtx_stack.top());
- LinAl::SquareMatrix<float, 3> nm;
- for(unsigned i=0; i<3; ++i)
- for(unsigned j=0; j<3; ++j)
- nm(i, j) = m(i, j);
+ LinAl::SquareMatrix<float, 3> 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;
{
/* 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;
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);
if(const Matrix *model_matrix = (*i)->get_matrix())
{
if(const Geometry::BoundingSphere<float, 3> *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;
}