改进Gizmo3DMove的选中判断
This commit is contained in:
Submodule CMSceneGraph updated: 65cefb3f12...dc1cd8a2d4
@@ -202,36 +202,34 @@ namespace
|
|||||||
Matrix4f l2w=GetLocalToWorldMatrix();
|
Matrix4f l2w=GetLocalToWorldMatrix();
|
||||||
Vector3f start;
|
Vector3f start;
|
||||||
Vector3f end;
|
Vector3f end;
|
||||||
|
Vector3f p_ray,p_ls;
|
||||||
float dist;
|
float dist;
|
||||||
|
float pixel_per_unit;
|
||||||
|
|
||||||
start=TransformPosition(l2w,Vector3f(0,0,0)); //将原点转换到世界坐标
|
start=TransformPosition(l2w,Vector3f(0,0,0)); //将原点转换到世界坐标
|
||||||
|
|
||||||
{
|
{
|
||||||
end=TransformPosition(l2w,Vector3f((GIZMO_CONE_LENGTH+GIZMO_CYLINDER_HALF_LENGTH)*20,0,0));
|
end=TransformPosition(l2w,Vector3f((GIZMO_CONE_LENGTH+GIZMO_CYLINDER_HALF_LENGTH)*20,0,0));
|
||||||
|
|
||||||
dist=ray.ToLineSegmentDistance(start,end);
|
//求射线与线段的最近点
|
||||||
|
ray.ClosestPoint(p_ray, //射线上的点
|
||||||
|
p_ls, //线段上的点
|
||||||
|
start,end); //线段
|
||||||
|
|
||||||
MaterialInstance *mi;
|
dist=glm::distance(p_ray,p_ls); //计算射线与线段的距离
|
||||||
|
|
||||||
if(dist<GIZMO_CYLINDER_RADIUS*10)
|
//求p_ls坐标相对屏幕空间象素的缩放比
|
||||||
{
|
pixel_per_unit=cc->GetPixelPerUnit(p_ls);
|
||||||
mi=GetGizmoMI3D(GizmoColor::Yellow);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mi=GetGizmoMI3D(GizmoColor::Red);
|
|
||||||
}
|
|
||||||
|
|
||||||
//MaterialInstance *mi=GetGizmoMI3D(dist<GIZMO_CYLINDER_RADIUS*100?GizmoColor::Yellow:GizmoColor::Red);
|
MaterialInstance *mi=GetGizmoMI3D(dist<GIZMO_CYLINDER_RADIUS*pixel_per_unit?GizmoColor::Yellow:GizmoColor::Red);
|
||||||
|
|
||||||
axis[size_t(AXIS::X)].cylinder->SetOverrideMaterial(mi);
|
axis[size_t(AXIS::X)].cylinder->SetOverrideMaterial(mi);
|
||||||
axis[size_t(AXIS::X)].cone->SetOverrideMaterial(mi);
|
axis[size_t(AXIS::X)].cone->SetOverrideMaterial(mi);
|
||||||
|
|
||||||
std::cout<<"Mouse: "<<mouse_coord.x<<","<<mouse_coord.y<<std::endl;
|
//std::cout<<"Mouse: "<<mouse_coord.x<<","<<mouse_coord.y<<std::endl;
|
||||||
// std::cout<<"CrossPoint: "<<cross_point.x<<","<<cross_point.y<<","<<cross_point.z<<std::endl;
|
//std::cout<<"Ray(Ori): "<<ray.origin.x<<","<<ray.origin.y<<","<<ray.origin.z<<")"<<std::endl;
|
||||||
std::cout<<"Ray(Ori): "<<ray.origin.x<<","<<ray.origin.y<<","<<ray.origin.z<<")"<<std::endl;
|
//std::cout<<"Ray(Dir): "<<ray.direction.x<<","<<ray.direction.y<<","<<ray.direction.z<<")"<<std::endl;
|
||||||
std::cout<<"Ray(Dir): "<<ray.direction.x<<","<<ray.direction.y<<","<<ray.direction.z<<")"<<std::endl;
|
//std::cout<<"Distance: "<<dist<<std::endl;
|
||||||
std::cout<<"Distance: "<<dist<<std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@@ -1,55 +1,50 @@
|
|||||||
#ifndef HGL_GRAPH_RENDER_LIST_INCLUDE
|
#pragma once
|
||||||
#define HGL_GRAPH_RENDER_LIST_INCLUDE
|
|
||||||
|
|
||||||
#include<hgl/graph/VK.h>
|
#include<hgl/graph/VK.h>
|
||||||
#include<hgl/graph/SceneNode.h>
|
#include<hgl/graph/SceneNode.h>
|
||||||
#include<hgl/graph/MaterialRenderMap.h>
|
#include<hgl/graph/MaterialRenderMap.h>
|
||||||
#include<hgl/graph/VKArrayBuffer.h>
|
#include<hgl/graph/VKArrayBuffer.h>
|
||||||
#include<hgl/graph/VKMaterial.h>
|
#include<hgl/graph/VKMaterial.h>
|
||||||
namespace hgl
|
namespace hgl::graph
|
||||||
{
|
{
|
||||||
namespace graph
|
/**
|
||||||
|
* 渲染对象列表<br>
|
||||||
|
* 该类会长期保存使用过的材质信息,避重新分配造成的时间和空间浪费。如需彻底清空列表请使用Clear()函数
|
||||||
|
*/
|
||||||
|
class RenderList
|
||||||
{
|
{
|
||||||
/**
|
protected:
|
||||||
* 渲染对象列表<br>
|
|
||||||
* 该类会长期保存使用过的材质信息,避重新分配造成的时间和空间浪费。如需彻底清空列表请使用Clear()函数
|
|
||||||
*/
|
|
||||||
class RenderList
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
|
|
||||||
VulkanDevice * device;
|
VulkanDevice * device;
|
||||||
|
|
||||||
CameraInfo * camera_info; ///<相机信息
|
CameraInfo * camera_info; ///<相机信息
|
||||||
|
|
||||||
uint renderable_count; ///<可渲染对象数量
|
uint renderable_count; ///<可渲染对象数量
|
||||||
MaterialRenderMap mrl_map; ///<按材质分类的渲染列表
|
MaterialRenderMap mrl_map; ///<按材质分类的渲染列表
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual bool ExpendNode(SceneNode *);
|
virtual bool ExpendNode(SceneNode *);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const CameraInfo *GetCameraInfo()const{return camera_info;}
|
const CameraInfo *GetCameraInfo()const{return camera_info;}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RenderList(VulkanDevice *);
|
RenderList(VulkanDevice *);
|
||||||
virtual ~RenderList()=default;
|
virtual ~RenderList()=default;
|
||||||
|
|
||||||
virtual void SetCameraInfo(CameraInfo *ci){camera_info=ci;} ///<设置相机信息
|
virtual void SetCameraInfo(CameraInfo *ci){camera_info=ci;} ///<设置相机信息
|
||||||
virtual bool Expend(SceneNode *); ///<展开场景树到渲染列表
|
virtual bool Expend(SceneNode *); ///<展开场景树到渲染列表
|
||||||
|
|
||||||
bool IsEmpty()const{return !renderable_count;} ///<是否是空的
|
bool IsEmpty()const{return !renderable_count;} ///<是否是空的
|
||||||
|
|
||||||
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
|
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
|
||||||
|
|
||||||
virtual void UpdateLocalToWorld(); ///<更新所有对象的变换数据
|
virtual void UpdateLocalToWorld(); ///<更新所有对象的变换数据
|
||||||
virtual void UpdateMaterialInstance(MeshComponent *); ///<有对象互换了材质实例
|
virtual void UpdateMaterialInstance(MeshComponent *); ///<有对象互换了材质实例
|
||||||
|
|
||||||
virtual void Clear(); ///<彻底清理
|
virtual void Clear(); ///<彻底清理
|
||||||
};//class RenderList
|
};//class RenderList
|
||||||
}//namespace graph
|
}//namespace hgl::graph
|
||||||
}//namespace hgl
|
|
||||||
#endif//HGL_GRAPH_RENDER_LIST_INCLUDE
|
|
||||||
|
Reference in New Issue
Block a user