模型加载坐标似乎终于正确
This commit is contained in:
parent
023a8eaa01
commit
a9a7b0373a
@ -168,19 +168,16 @@ private:
|
||||
aiVector3D *max_pos,
|
||||
const Matrix4f &up_matrix)
|
||||
{
|
||||
Matrix4f cur_matrix;
|
||||
uint n = 0, t;
|
||||
Matrix4f cur_matrix=up_matrix*MatrixConvert(node->mTransformation);
|
||||
uint n, t;
|
||||
|
||||
cur_matrix=up_matrix*MatrixConvert(node->mTransformation);
|
||||
|
||||
for (; n < node->mNumMeshes; ++n)
|
||||
for (n=0; n < node->mNumMeshes; ++n)
|
||||
{
|
||||
const aiMesh *mesh=scene->mMeshes[node->mMeshes[n]];
|
||||
|
||||
for (t = 0; t < mesh->mNumVertices; ++t)
|
||||
{
|
||||
aiVector3D gl_tmp = mesh->mVertices[t];
|
||||
|
||||
Vector4f tmp=cur_matrix*Vector4f(gl_tmp.x,
|
||||
gl_tmp.y,
|
||||
gl_tmp.z,
|
||||
@ -214,9 +211,7 @@ public:
|
||||
|
||||
AssimpLoaderMesh(const OSString &fn,const aiScene *s):filename(fn),scene(s)
|
||||
{
|
||||
OpenGLCoord2VulkanCoordMatrix=Matrix4f::RotateZ(hgl_ang2rad(-90))*Matrix4f::RotateX(hgl_ang2rad(90));
|
||||
|
||||
//rotate(hgl_ang2rad(90),Vector3f(0,0,1))*rotate(hgl_ang2rad(90),Vector3f(1,0,0))*scale(1,1,-1);
|
||||
OpenGLCoord2VulkanCoordMatrix=scale(1,-1,1)*rotate(hgl_ang2rad(90),Vector3f(1,0,0));
|
||||
|
||||
model_data=new ModelData;
|
||||
|
||||
|
@ -15,9 +15,9 @@ protected:
|
||||
|
||||
AABB bounding_box;
|
||||
|
||||
Matrix4f object_matrix;
|
||||
Matrix4f object_matrix,origin_matrix;
|
||||
|
||||
ControlCamera camera;
|
||||
ControlCamera camera,origin_camera;
|
||||
float move_speed=1;
|
||||
|
||||
Vector2f mouse_last_pos;
|
||||
@ -44,12 +44,13 @@ public:
|
||||
|
||||
virtual void InitCamera(int w,int h)
|
||||
{
|
||||
math::vec center_point=bounding_box.CenterPoint();
|
||||
math::vec min_point=bounding_box.minPoint;
|
||||
math::vec max_point=bounding_box.maxPoint;
|
||||
math::vec center_point =bounding_box.CenterPoint();
|
||||
math::vec min_point =bounding_box.minPoint;
|
||||
math::vec max_point =bounding_box.maxPoint;
|
||||
math::vec size =bounding_box.Size();
|
||||
|
||||
math::vec eye( max_point.x*5,
|
||||
center_point.y,
|
||||
math::vec eye( center_point.x,
|
||||
center_point.y-size.y*2,
|
||||
center_point.z,
|
||||
1.0f);
|
||||
|
||||
@ -61,9 +62,12 @@ public:
|
||||
|
||||
camera.Refresh(); //更新矩阵计算
|
||||
|
||||
origin_camera=camera;
|
||||
|
||||
move_speed=length(min_point,center_point)/100.0f;
|
||||
|
||||
object_matrix=translate(-center_point.xyz());
|
||||
origin_matrix=object_matrix;
|
||||
}
|
||||
|
||||
bool InitCameraUBO(vulkan::DescriptorSets *desc_set,uint world_matrix_bindpoint)
|
||||
@ -97,18 +101,31 @@ public:
|
||||
|
||||
SubmitDraw(index);
|
||||
|
||||
if(key_status[kbEnter])
|
||||
{
|
||||
origin_camera.width=camera.width;
|
||||
origin_camera.height=camera.height;
|
||||
camera=origin_camera;
|
||||
object_matrix=origin_matrix;
|
||||
}
|
||||
else
|
||||
if(key_status[kbW])camera.Forward (move_speed);else
|
||||
if(key_status[kbS])camera.Backward (move_speed);else
|
||||
if(key_status[kbA])camera.Left (move_speed);else
|
||||
if(key_status[kbD])camera.Right (move_speed);else
|
||||
if(key_status[kbR])camera.Up (move_speed);else
|
||||
if(key_status[kbF])camera.Down (move_speed);else
|
||||
{
|
||||
auto axis=normalized(camera.center-camera.eye);
|
||||
float rotate_rad=hgl_ang2rad(move_speed)*10;
|
||||
|
||||
if(key_status[kbLeft ])
|
||||
object_matrix=rotate(-rotate_rad,camera.forward_vector)*object_matrix;else
|
||||
if(key_status[kbRight])
|
||||
object_matrix=rotate( rotate_rad,camera.forward_vector)*object_matrix;else
|
||||
|
||||
// if(key_status[kbLeft ])object_matrix=rotate(hgl_ang2rad(move_speed),normalized(camera.center-camera.eye))*object_matrix;else
|
||||
//if(key_status[kbRight])object_matrix=rotate(hgl_ang2rad(-move_speed),normalized(camera.center-camera.eye))*object_matrix;else
|
||||
if(key_status[kbLeft ])camera.WrapHorzRotate(move_speed);else
|
||||
if(key_status[kbRight])camera.WrapHorzRotate(-move_speed);else
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void KeyPress(KeyboardButton kb)override
|
||||
@ -137,12 +154,12 @@ public:
|
||||
else if(mouse_key&mbRight)
|
||||
{
|
||||
if(gap.x!=0)object_matrix=rotate(hgl_ang2rad(gap.x),camera.up_vector)*object_matrix;
|
||||
if(gap.y!=0)object_matrix=rotate(hgl_ang2rad(-gap.y),camera.forward_vector)*object_matrix;
|
||||
if(gap.y!=0)object_matrix=rotate(hgl_ang2rad(gap.y),camera.right_vector)*object_matrix;
|
||||
}
|
||||
else if(mouse_key&mbMid)
|
||||
{
|
||||
if(gap.x!=0)camera.Left(gap.x*move_speed/10.0f);
|
||||
if(gap.y!=0)camera.Up(gap.y*move_speed/10.0f);
|
||||
if(gap.x!=0)camera.Left(gap.x*move_speed/5.0f);
|
||||
if(gap.y!=0)camera.Up(gap.y*move_speed/5.0f);
|
||||
}
|
||||
|
||||
mouse_last_pos=mouse_pos;
|
||||
|
@ -6,11 +6,27 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/*
|
||||
* OpenGL Coordinate System Vulkan Coordinate System My Coordinate System
|
||||
*
|
||||
* /Z
|
||||
* Y| /Z / Z| /Y
|
||||
* | / / | /
|
||||
* | / *------------ | /
|
||||
* | / | X | /
|
||||
* |/ | |/
|
||||
* *------------ | *------------
|
||||
* X | Y X
|
||||
*/
|
||||
|
||||
/**
|
||||
* 摄像机类型
|
||||
*/
|
||||
enum class CameraType
|
||||
{
|
||||
Perspective,
|
||||
Ortho
|
||||
};//
|
||||
};//enum class CameraType
|
||||
|
||||
/**
|
||||
* 摄像机数据结构
|
||||
@ -28,7 +44,7 @@ namespace hgl
|
||||
Vector4f eye; ///<眼睛坐标
|
||||
Vector4f center; ///<视点坐标
|
||||
Vector4f up_vector =Vector4f(0,0,1,0); ///<向上量(默认0,0,1)
|
||||
Vector4f forward_vector =Vector4f(0,-1,0,0); ///<向前量(默认0,1,0)
|
||||
Vector4f forward_vector =Vector4f(0,1,0,0); ///<向前量(默认0,1,0)
|
||||
Vector4f right_vector =Vector4f(1,0,0,0); ///<向右量(默认0,0,1)
|
||||
|
||||
public:
|
||||
@ -40,6 +56,25 @@ namespace hgl
|
||||
public:
|
||||
|
||||
void Refresh();
|
||||
|
||||
void operator = (const Camera &cam)
|
||||
{
|
||||
type =cam.type;
|
||||
width =cam.width;
|
||||
height =cam.height;
|
||||
fov =cam.fov;
|
||||
znear =cam.znear;
|
||||
zfar =cam.zfar;
|
||||
|
||||
eye =cam.eye;
|
||||
center =cam.center;
|
||||
up_vector =cam.up_vector;
|
||||
forward_vector =cam.forward_vector;
|
||||
right_vector =cam.right_vector;
|
||||
|
||||
matrix =cam.matrix;
|
||||
frustum =cam.frustum;
|
||||
}
|
||||
};//struct Camera
|
||||
|
||||
/**
|
||||
@ -75,11 +110,11 @@ namespace hgl
|
||||
* @param ang 角度
|
||||
* @param axis 旋转轴
|
||||
*/
|
||||
void WrapRotate(double ang,Vector4f axis)
|
||||
{
|
||||
void WrapRotate(double ang,Vector4f axis)
|
||||
{
|
||||
normalize(axis);
|
||||
eye=center+(eye-center)*rotate(hgl_ang2rad(ang),axis);
|
||||
}
|
||||
}
|
||||
|
||||
public: //方法
|
||||
|
||||
|
@ -20,7 +20,7 @@ namespace hgl
|
||||
alignas(16) Matrix4f modelview;
|
||||
alignas(16) Matrix4f mvp;
|
||||
alignas(16) Matrix3f normal;
|
||||
};//
|
||||
};//struct WorldMatrix
|
||||
|
||||
inline Matrix4f identity()
|
||||
{
|
||||
|
@ -18,8 +18,8 @@ namespace hgl
|
||||
|
||||
Matrix4f result( side.x, side.y, side.z, 0.0f,
|
||||
nup.x, nup.y, nup.z, 0.0f,
|
||||
-forward.x, -forward.y, -forward.z, 0.0f,
|
||||
-dot(side,eye), -dot(nup,eye), dot(forward,eye), 1.0f);
|
||||
-forward.x, -forward.y, -forward.z/2.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.5f, 1.0f);
|
||||
|
||||
return result*translate(-eye.xyz());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user