Ecere SDK/eC Forums
http://ec-lang.org/community/
Print view

画三角形drawTriangle
http://ec-lang.org/community/viewtopic.php?f=30&t=39
Page 1 of 1
Author:  liqi98136 [ Wed Mar 10, 2010 8:38 am ]
Post subject:  画三角形drawTriangle

drawTriangle.rar
(2.64 KiB) Downloaded 5567 times

Code: Select all

import "ecere"
#define SIDES 3 

class Triangle : Object
{
public:
   bool Create(DisplaySystem displaySystem)
   {
      bool result = false;
      if(this)
      {
         InitializeMesh(displaySystem);

         if(mesh)
         {
            if(mesh.Allocate({ vertices = true, texCoords1 = true }, SIDES, displaySystem))
            {
               Vector3Df vertices[SIDES] =
               {
                   //{1,0,0},
                   //{-1,0,0}, 
                   //{0,-1,0}
                  { (float)size.x/2,     0,              0 },
                  {  -(float)size.x/2,   0,              0 },
                  {  0,                -(float)size.y/2, 0 }
               };

               uint16 indices[SIDES] = { 0, 2, 1};

               CopyBytes(mesh.vertices, vertices, sizeof(vertices));
               {
                  PrimitiveGroup group;
                  String name = "triangle"; 
                  Material material = displaySystem.AddNamedMaterial(name);
                  
                  if(material)
                  {
                     material.flags = { noFog = true, doubleSided = true, translucent = true };
                     material.opacity = 0.5f;
                     material.diffuse.r = material.diffuse.g = material.diffuse.b = 1;
                     material.ambient = material.diffuse;

                  }
                  group = mesh.AddPrimitiveGroup(triStrip, SIDES);
                  
                  if(group)
                  {
                     CopyBytes(group.indices, indices, sizeof(indices));
                     mesh.UnlockPrimitiveGroup(group);
                     group.material = material;
                  }
               }
               mesh.ComputeNormals();
               result = true;
               mesh.Unlock(0);
            }
            SetMinMaxRadius(true);
         }
      }
      return result;
   }

   property Vector3Df size { set { size = value; } };

private:
   Triangle()
   {
      size = { 1,1,0 };
   }

   Vector3Df size;
} 
Author:  liqi98136 [ Wed Mar 10, 2010 8:49 am ]
Post subject:  Re: 画圆drawCircle

画圆,变椭圆时,size={a,b,0}改变a,b的值
drawCircle

Code: Select all

import "ecere"

#define SIDE 50   //内切多边形的边数
class Model : Object     // 画圆
{
public:
   bool Create(DisplaySystem displaySystem)
   {
      bool result = false;
      if(this)
      {
         InitializeMesh(displaySystem);

         if(mesh)
         {
            if(mesh.Allocate({ vertices = true, texCoords1 = true }, SIDE*3, displaySystem))
            {
               Vector3Df vertices[SIDE*3] ;   // 圆上坐标点
               uint16 indices[SIDE][3];     //圆上坐标点的索引
               int c;
               {
                  int x;
                  int index=0;
                  for (x=0;x<SIDE;x++)
                     
                     {
                       Angle theta=x*2*Pi/SIDE;
                       Angle omega=(x+1)*2*Pi/SIDE;
                       vertices[index++]={0,-(float)size.y/2,(float)size.z/2};
                       vertices[index++]={(float)(size.x*sin(theta)/2),-(float)(size.y*cos(theta)/2),(float)size.z/2};
                       vertices[index++]={(float)(size.x*sin(omega)/2),-(float)(size.y*cos(omega)/2),(float)size.z/2};
 
                     }
               };

               
               {
                  int i,j;
                  int x=SIDE*3-1;
                  for (i=0;i<SIDE;i++)
                     {
                     for(j=0;j<3;j++)
                        indices[i][j]=(uint16)(x-j);
                     x=x-3;
                     }
               };

               

               CopyBytes(mesh.vertices, vertices, sizeof(vertices));



               {
                  PrimitiveGroup group;
                  Material material;
                  String name {};
                  sprintf(name, "Triangle Face"); 
                  material = displaySystem.AddNamedMaterial(name);
                  
                  if(material)
                  {
                     material.flags = { noFog = true, doubleSided = true, translucent = true };
                     material.opacity = 0.5f;

                     material.diffuse.r = material.diffuse.g = material.diffuse.b = 1;
                     material.ambient = material.diffuse;

                  }
                  group = mesh.AddPrimitiveGroup(triStrip, 3*SIDE);
                  
                  if(group)
                  {
                     CopyBytes(group.indices, indices, sizeof(indices));
                     mesh.UnlockPrimitiveGroup(group);
                     group.material = material;
                  }
               }
               mesh.ComputeNormals();
               result = true;
               mesh.Unlock(0);
            }
            SetMinMaxRadius(true);
         }
      }
      return result;
   }

   property Vector3Df size { set { size = value; } };

private:
   Model()
   {
      size = { 1,1,0 };
   }

   Vector3Df size;
}
All times are UTC-05:00 Page 1 of 1