I am trying to perform view transform to a 3D point in world coordinates stored in Vector3f, my view matrix is stored in Matrix4f. Would it be possible to initialize Vector4f with an extended Vector3f. This's what I've done so far:
Eigen::Vector4f Graphics::getLookVectorView() {
Eigen::Matrix4f viewMatrix = dxToEigen(m_camera->getViewMatrix());
Eigen::Vector3f Vec = m_eyeball0->getLookVector();
Eigen::Vector4f lookVec4;
lookVec4 << Vec.x(), Vec.y(), Vec.z(), 1;
return (viewMatrix*lookVec4);
//Eigen::Vector3f lookVecEye1 = m_eyeball1->getLookVector();}
but I get an error when I try to do it this way, is there any way where I can extend Vector3f by one and store in Vector4f to perform the transform?
This's the error I get:
1>....\eigen-eigen-b30b87236a1b\eigen\src\core\assign.h(499): error C2338: YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES
1>....\eigen-eigen-b30b87236a1b\eigen\src\core\plainobjectbase.h(414): note: see reference to function template instantiation 'Derived &Eigen::DenseBase<Derived>::lazyAssign<Eigen::Matrix<float,4,1,0,4,1>>(const Eigen::DenseBase<Eigen::Matrix<float,4,1,0,4,1>> &)' being compiled
1> with
1> [
1> Derived=Eigen::Matrix<float,3,1,0,3,1>
1> ]
Any help is highly appreciated :)
You could circumvent the conversion using Affine3f instead of Matrix4f.
An Affine3f object internally stores a Matrix4f (that can be accessed by Affine3f.matrix()
) and the multiplication with a Vector3f
returns a Vector3f
performing the same calculation done using a Vector4f
created adding the trailing 1.
#include <Eigen/Geometry>
Eigen::Vector3f Graphics::getLookVectorView() {
Eigen::Matrix4f viewMatrix = dxToEigen(m_camera->getViewMatrix());
Eigen::Affine3d affine(viewMatrix);
Eigen::Vector3f Vec = m_eyeball0->getLookVector();
return (affine*Vec);
}