Added CreateCircle2D/3D,CreateCircle3DByIndexTriangles functions.
This commit is contained in:
parent
e35abf0051
commit
cf2efd69b9
@ -48,9 +48,9 @@ namespace hgl
|
||||
{
|
||||
Vector2f center; ///<圆心坐标
|
||||
Vector2f radius; ///<半径
|
||||
uint field_count=8; ///<分段次数
|
||||
uint field_count=8; ///<分段数量
|
||||
|
||||
bool has_color =false;
|
||||
bool has_center; ///<是否有圆心点
|
||||
|
||||
Vector4f center_color; ///<圆心颜色
|
||||
Vector4f border_color; ///<边缘颜色
|
||||
@ -59,7 +59,17 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个2D圆形(扇形/线圈)
|
||||
*/
|
||||
Primitive *CreateCircle(PrimitiveCreater *pc,const CircleCreateInfo *cci);
|
||||
Primitive *CreateCircle2D(PrimitiveCreater *pc,const CircleCreateInfo *cci);
|
||||
|
||||
/**
|
||||
* 创建一个3D圆形(扇形/圆形,XY,Z永远为0)
|
||||
*/
|
||||
Primitive *CreateCircle3D(PrimitiveCreater *pc,const CircleCreateInfo *cci);
|
||||
|
||||
/**
|
||||
* 创建一个使用三角形绘制的3D圆形(扇形/圆形,XY,Z永远为0)
|
||||
*/
|
||||
Primitive *CreateCircle3DByIndexTriangles(PrimitiveCreater *pc,const CircleCreateInfo *cci);
|
||||
|
||||
/**
|
||||
* 平面网格创建信息<br>
|
||||
|
@ -113,14 +113,14 @@ namespace hgl
|
||||
return pc->Create();
|
||||
}
|
||||
|
||||
Primitive *CreateCircle(PrimitiveCreater *pc,const CircleCreateInfo *cci)
|
||||
Primitive *CreateCircle2D(PrimitiveCreater *pc,const CircleCreateInfo *cci)
|
||||
{
|
||||
if(!pc)return(nullptr);
|
||||
|
||||
uint edge;
|
||||
uint vertex_count;
|
||||
|
||||
if(cci->has_color)
|
||||
if(cci->has_center)
|
||||
{
|
||||
edge=cci->field_count+1;
|
||||
vertex_count=cci->field_count+2;
|
||||
@ -139,12 +139,11 @@ namespace hgl
|
||||
if(!vertex.IsValid())
|
||||
return(nullptr);
|
||||
|
||||
if(cci->has_color)
|
||||
if(cci->has_center)
|
||||
{
|
||||
if(!color.IsValid())
|
||||
return(nullptr);
|
||||
|
||||
vertex->Write(cci->center);
|
||||
|
||||
if(color.IsValid())
|
||||
color->Write(cci->center_color);
|
||||
}
|
||||
|
||||
@ -157,13 +156,158 @@ namespace hgl
|
||||
|
||||
vertex->Write(x,y);
|
||||
|
||||
if(cci->has_color)
|
||||
if(color.IsValid())
|
||||
color->Write(cci->border_color);
|
||||
}
|
||||
|
||||
return pc->Create();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void WriteIBO(T *p,const T start,const T count)
|
||||
{
|
||||
for(T i=start;i<start+count;i++)
|
||||
{
|
||||
*p=i;
|
||||
++p;
|
||||
}
|
||||
}
|
||||
|
||||
Primitive *CreateCircle3D(PrimitiveCreater *pc,const CircleCreateInfo *cci)
|
||||
{
|
||||
if(!pc)return(nullptr);
|
||||
|
||||
uint edge;
|
||||
uint vertex_count;
|
||||
|
||||
if(cci->has_center)
|
||||
{
|
||||
edge=cci->field_count+1;
|
||||
vertex_count=cci->field_count+2;
|
||||
}
|
||||
else
|
||||
{
|
||||
edge=cci->field_count;
|
||||
vertex_count=cci->field_count;
|
||||
}
|
||||
|
||||
bool has_index=pc->hasIndex();
|
||||
|
||||
if(!pc->Init("Circle",vertex_count,has_index?vertex_count:0))return(nullptr);
|
||||
|
||||
VABMap3f vertex(pc->GetVABMap(VAN::Position));
|
||||
VABMap4f color(pc->GetVABMap(VAN::Color));
|
||||
VABMap3f normal(pc->GetVABMap(VAN::Normal));
|
||||
|
||||
if(!vertex.IsValid())
|
||||
return(nullptr);
|
||||
|
||||
if(cci->has_center)
|
||||
{
|
||||
vertex->Write(cci->center.x,cci->center.y,0);
|
||||
|
||||
if(color.IsValid())
|
||||
color->Write(cci->center_color);
|
||||
|
||||
if(normal.IsValid())
|
||||
normal->Write(AxisVector::Z);
|
||||
}
|
||||
|
||||
for(uint i=0;i<edge;i++)
|
||||
{
|
||||
float ang=float(i)/float(cci->field_count)*360.0f;
|
||||
|
||||
float x=cci->center.x+sin(deg2rad(ang))*cci->radius.x;
|
||||
float y=cci->center.y+cos(deg2rad(ang))*cci->radius.y;
|
||||
|
||||
vertex->Write(x,y,0);
|
||||
|
||||
if(color.IsValid())
|
||||
color->Write(cci->border_color);
|
||||
|
||||
if(normal.IsValid())
|
||||
normal->Write(AxisVector::Z);
|
||||
}
|
||||
|
||||
if(has_index)
|
||||
{
|
||||
IBMap *ib_map=pc->GetIBMap();
|
||||
|
||||
if(pc->GetIndexType()==IndexType::U16)WriteIBO<uint16>((uint16 *)(ib_map->Map()),0,vertex_count);else
|
||||
if(pc->GetIndexType()==IndexType::U32)WriteIBO<uint32>((uint32 *)(ib_map->Map()),0,vertex_count);else
|
||||
if(pc->GetIndexType()==IndexType::U8 )WriteIBO<uint8 >((uint8 *)(ib_map->Map()),0,vertex_count);
|
||||
|
||||
ib_map->Unmap();
|
||||
}
|
||||
|
||||
return pc->Create();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void WriteCircleIBO(T *ibo,const uint edge_count)
|
||||
{
|
||||
T *p=ibo;
|
||||
|
||||
for(T i=1;i<edge_count;i++)
|
||||
{
|
||||
*p=0; ++p;
|
||||
*p=i+1;++p;
|
||||
*p=i; ++p;
|
||||
}
|
||||
|
||||
*p=0; ++p;
|
||||
*p=1; ++p;
|
||||
*p=edge_count;
|
||||
}
|
||||
|
||||
Primitive *CreateCircle3DByIndexTriangles(PrimitiveCreater *pc,const CircleCreateInfo *cci)
|
||||
{
|
||||
if(!pc)return(nullptr);
|
||||
|
||||
uint vertex_count;
|
||||
uint index_count;
|
||||
|
||||
vertex_count=cci->field_count;
|
||||
index_count=(vertex_count-2)*3;
|
||||
|
||||
if(!pc->Init("Circle",vertex_count,index_count))return(nullptr);
|
||||
|
||||
VABMap3f vertex(pc->GetVABMap(VAN::Position));
|
||||
VABMap4f color(pc->GetVABMap(VAN::Color));
|
||||
VABMap3f normal(pc->GetVABMap(VAN::Normal));
|
||||
|
||||
if(!vertex.IsValid())
|
||||
return(nullptr);
|
||||
|
||||
for(uint i=0;i<cci->field_count+1;i++)
|
||||
{
|
||||
float ang=float(i)/float(cci->field_count)*360.0f;
|
||||
|
||||
float x=cci->center.x+sin(deg2rad(ang))*cci->radius.x;
|
||||
float y=cci->center.y+cos(deg2rad(ang))*cci->radius.y;
|
||||
|
||||
vertex->Write(x,y,0);
|
||||
|
||||
if(color.IsValid())
|
||||
color->Write(cci->border_color);
|
||||
|
||||
if(normal.IsValid())
|
||||
normal->Write(AxisVector::Z);
|
||||
}
|
||||
|
||||
{
|
||||
IBMap *ib_map=pc->GetIBMap();
|
||||
|
||||
if(pc->GetIndexType()==IndexType::U16)WriteCircleIBO<uint16>((uint16 *)(ib_map->Map()),cci->field_count);else
|
||||
if(pc->GetIndexType()==IndexType::U32)WriteCircleIBO<uint32>((uint32 *)(ib_map->Map()),cci->field_count);else
|
||||
if(pc->GetIndexType()==IndexType::U8 )WriteCircleIBO<uint8 >((uint8 *)(ib_map->Map()),cci->field_count);
|
||||
|
||||
ib_map->Unmap();
|
||||
}
|
||||
|
||||
return pc->Create();
|
||||
}
|
||||
|
||||
Primitive *CreatePlaneGrid2D(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci)
|
||||
{
|
||||
if(!pc->Init("PlaneGrid",((pgci->grid_size.Width()+1)+(pgci->grid_size.Height()+1))*2,0))
|
||||
|
Loading…
x
Reference in New Issue
Block a user