improved sample.
This commit is contained in:
parent
7f744d1207
commit
89b9735f99
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit a29a35eceaa9bc19f3e4a64ebebec0a2f6bd081f
|
||||
Subproject commit 2f93a1bb004cf0e99f51735dc2f65967a3ded1b8
|
@ -1 +1 @@
|
||||
Subproject commit f610497a6d403001303e15f474f9fa2a5bc0cc23
|
||||
Subproject commit 0c9bdb9fcd9b02a3c5b641285a059362163c94ac
|
@ -104,7 +104,7 @@ private:
|
||||
{
|
||||
Add(material_instance,scale(PLANE_SIZE,PLANE_SIZE,1));
|
||||
|
||||
camera->pos=Vector3f(PLANE_SIZE/2,PLANE_SIZE/4,PLANE_SIZE/2);
|
||||
camera->pos=Vector3f(PLANE_SIZE/2,PLANE_SIZE/2,PLANE_SIZE/4);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
|
@ -39,10 +39,13 @@ private:
|
||||
|
||||
private: //sphere
|
||||
|
||||
Material * mtl_sun_light =nullptr;
|
||||
MaterialInstance * mi_sphere =nullptr;
|
||||
Pipeline * p_sphere =nullptr;
|
||||
Material * mtl_blinnphong =nullptr;
|
||||
MaterialInstance * mi_blinnphong =nullptr;
|
||||
Pipeline * p_blinnphong =nullptr;
|
||||
|
||||
Primitive * prim_sphere =nullptr;
|
||||
Primitive * prim_cone =nullptr;
|
||||
Primitive * prim_cylinder =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
@ -80,11 +83,11 @@ private:
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
mtl_sun_light=db->LoadMaterial("Std3D/BlinnPhong/SunLightPureColor",&cfg);
|
||||
if(!mtl_sun_light)return(false);
|
||||
mtl_blinnphong=db->LoadMaterial("Std3D/BlinnPhong/SunLightPureColor",&cfg);
|
||||
if(!mtl_blinnphong)return(false);
|
||||
|
||||
mtl_sun_light->BindUBO(DescriptorSetType::Global,"sun",ubo_sun);
|
||||
mtl_sun_light->Update();
|
||||
mtl_blinnphong->BindUBO(DescriptorSetType::Global,"sun",ubo_sun);
|
||||
mtl_blinnphong->Update();
|
||||
|
||||
float mi_data[4]=
|
||||
{
|
||||
@ -92,31 +95,16 @@ private:
|
||||
4 //gloss
|
||||
};
|
||||
|
||||
mi_sphere=db->CreateMaterialInstance(mtl_sun_light,nullptr,&mi_data);
|
||||
if(!mi_sphere)return(false);
|
||||
mi_blinnphong=db->CreateMaterialInstance(mtl_blinnphong,nullptr,&mi_data);
|
||||
if(!mi_blinnphong)return(false);
|
||||
|
||||
p_sphere=CreatePipeline(mtl_sun_light,InlinePipeline::Solid3D,Prim::Triangles);
|
||||
p_blinnphong=CreatePipeline(mtl_blinnphong,InlinePipeline::Solid3D,Prim::Triangles);
|
||||
|
||||
if(!p_sphere)
|
||||
if(!p_blinnphong)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,mi,p);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Create Renderable failed."));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
render_root.CreateSubNode(ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
@ -136,17 +124,56 @@ private:
|
||||
}
|
||||
|
||||
//Sphere
|
||||
prim_sphere=CreateSphere(db,mi_blinnphong->GetVIL(),16);
|
||||
|
||||
//Cone
|
||||
{
|
||||
prim_sphere=CreateSphere(db,mi_sphere->GetVIL(),32);
|
||||
struct ConeCreateInfo cci;
|
||||
|
||||
cci.radius =1; //圆锥半径
|
||||
cci.halfExtend =1; //圆锤一半高度
|
||||
cci.numberSlices=16; //圆锥底部分割数
|
||||
cci.numberStacks=8; //圆锥高度分割数
|
||||
|
||||
prim_cone=CreateCone(db,mi_blinnphong->GetVIL(),&cci);
|
||||
}
|
||||
|
||||
//Cyliner
|
||||
{
|
||||
struct CylinderCreateInfo cci;
|
||||
|
||||
cci.halfExtend =4; //圆柱一半高度
|
||||
cci.numberSlices=16; //圆柱底部分割数
|
||||
cci.radius =0.25f; //圆柱半径
|
||||
|
||||
prim_cylinder=CreateCylinder(db,mi_blinnphong->GetVIL(),&cci);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,mi,p);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Create Renderable failed."));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(prim_plane_grid,mi_plane_grid,p_line);
|
||||
Add(prim_sphere,mi_sphere,p_sphere);
|
||||
Add(prim_plane_grid,mi_plane_grid,p_line,Identity4f);
|
||||
|
||||
Add(prim_sphere, mi_blinnphong,p_blinnphong,translate(Vector3f(0,0,2)));
|
||||
Add(prim_cone, mi_blinnphong,p_blinnphong,Identity4f);
|
||||
Add(prim_cylinder, mi_blinnphong,p_blinnphong,translate(Vector3f(0,0,-5)));
|
||||
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
|
@ -712,7 +712,7 @@ namespace hgl
|
||||
// NOTE: cos (2PIx) = cos (x) and sin (2PIx) = sin (x) so, we can use this formula
|
||||
// normal = {cos(2PIs)cos(2PIt) , sin(2PIs)cos(2PIt) ,sin(2PIt)}
|
||||
*np = +cos2PIs * cos2PIt; ++np;
|
||||
*np = -sin2PIt; ++np;
|
||||
*np = +sin2PIt; ++np;
|
||||
*np = +sin2PIs * cos2PIt; ++np;
|
||||
}
|
||||
|
||||
@ -943,7 +943,7 @@ namespace hgl
|
||||
if(np)
|
||||
{
|
||||
*np = cos(currentAngle); ++np;
|
||||
*np = sin(currentAngle); ++np;
|
||||
*np = -sin(currentAngle); ++np;
|
||||
*np = 0.0f; ++np;
|
||||
}
|
||||
|
||||
@ -1112,7 +1112,7 @@ namespace hgl
|
||||
if(np)
|
||||
{
|
||||
*np = h / l * cos(currentAngle); ++np;
|
||||
*np = h / l * sin(currentAngle); ++np;
|
||||
*np =-h / l * sin(currentAngle); ++np;
|
||||
*np = r / l; ++np;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user