文章 "如何在 MetaTrader 5 中利用 DirectX 创建 3D 图形"

 

新文章 如何在 MetaTrader 5 中利用 DirectX 创建 3D 图形已发布:

3D 图形为大数据分析提供了完美的方案,它可以直观透视隐藏的形态。 这些任务能以 MQL5 直接解决,而 DireсtX 函数允许创建三维物体。 故其能够为 MetaTrader 5 创建任意复杂度的程序,甚至 3D 游戏。 学习 3D 图形,从绘制简单的三维形状开始。

按照三角形每个顶点的坐标定义来创建物体的三维模型,如此,即便物体移动或观察者的位置发生变化,也可以进一步计算物体每个点的坐标。 所以,我们要处理的是顶点,连接顶点的边线,以及由边线形成的表面。 如果知道三角形的位置,则可以利用线性代数定律来创建切面法线(法线是垂直于表面的向量)。 如此即可计算出切面如何光照,以及光线如何从切面反射。


简单物体的顶点、边线、切面和法线的示例。 法线是红色箭头。

物体模型能够以不同方式来创建。 拓扑学描述了多边形如何形成 3D 网模。 良好的拓扑结构允许利用最少数量的多边形来描绘对象,并可令物体的移动和旋转更加容易。

两种拓扑中的球面模型

两种拓扑中的球面模型。

作者:MetaQuotes

 

Sir:

the code in this article cnn not run !  Please check and help me . 

for Canva.mql code:  I add some Print(...) code for trace error, see bellow:

line 328:

bool CCanvas::CreateBitmapLabel(const long chart_id,const int subwin,const string name,
                                const int x,const int y,const int width,const int height,
                                ENUM_COLOR_FORMAT clrfmt)
  {
//--- create canvas
       Print("At CCanvas Create BitmapLabel 1  ",width,"  ",name,"   ",height,"  ",clrfmt);   //I add
       bool xx= Create(name,width,height,clrfmt);     
       Print("CCanvas Create return  ",xx,"   ",GetLastError());   //I add
 //  if(Create(name,width,height,clrfmt))    // I change
   if (xx)
     {
       Print("CCanvas Create  2  ",chart_id,"  ",name,"   ",subwin);
..................

for Canva.mql code:     

xx= Create(name,width,height,clrfmt);    will call function bellow:

line 250:

bool CCanvas::Create(const string name,const int width,const int height,ENUM_COLOR_FORMAT clrfmt)
  {
   Destroy();
//--- prepare data array
   if(width>0 && height>0 && ArrayResize(m_pixels,width*height)>0)
     {
      //--- generate resource name
      m_rcname="::"+name+(string)ChartID()+(string)(GetTickCount()+MathRand());
      
      //--- initialize data with zeros
      ArrayInitialize(m_pixels,0);
      //--- create dynamic resource
       Print("Before CCanvas ResourceCreate 0  ",m_rcname);         //I add
      if(ResourceCreate(m_rcname,m_pixels,width,height,0,0,0,clrfmt))
        {

         //--- successfully created
         //--- complete initialization
         m_width =width;
         m_height=height;
         m_format=clrfmt;
         //--- succeed
       Print("then CCanvas ResourceCreate OK  ",m_rcname);     //I add
         return(true);
        }
     }
.............................


For sample 3D-surface.mq5

line 40:

   //| Create                                                           |
   //+------------------------------------------------------------------+
   virtual bool      Create(const int width,const int height)
     {
      //--- save canvas dimensions
      m_width=width;
      m_height=height;
      //--- reset input data
      m_mouse_x=m_mouse_y=-1;
      //--- set default parameters for the camera
      m_camera_distance=10.0f;
      m_camera_angles.x=DX_PI_DIV6;
      m_camera_angles.y=DX_PI_DIV3;
      //--- create a canvas to render a 3D scene
      ResetLastError();
      if(!m_canvas.CreateBitmapLabel("3D Surface",0,0,m_width,m_height,COLOR_FORMAT_ARGB_NORMALIZE))
       { 
         Print("CreateBitmapLabel fail 3D surface ?");   // I add this line
         Print("Error creating canvas: ",GetLastError());
         return(false);
         }
..........................


Run 3D-Surface.mq5, received: 

2023.05.05 11:32:46.180 3D_Surface (EURUSD,M1)  At CCanvas Create BitmapLabel 1  604  3D Surface   392  2
2023.05.05 11:32:46.180 3D_Surface (EURUSD,M1)  Before CCanvas ResourceCreate 0  ::3D Surface1332772457869319469285704
2023.05.05 11:32:46.180 3D_Surface (EURUSD,M1)  then CCanvas ResourceCreate OK  ::3D Surface1332772457869319469285704
2023.05.05 11:32:46.185 3D_Surface (EURUSD,M1)  CCanvas Create return  false   5151
2023.05.05 11:32:46.185 3D_Surface (EURUSD,M1)  CreateBitmapLabel fail 3D surface ?
2023.05.05 11:32:46.185 3D_Surface (EURUSD,M1)  Error creating canvas: 5151
then CCanvas ResourceCreate OK 
BUR BUT But....

    
CCanvas Create return  false   5151

Why? what's wrong?

What is 5151 ??

 

my display adapter is Nivada FX 1700--- an old product.  only support feture-level 10.0


So use DXcpl.exe to set Force WRAP for MT , then all run OK.

原因: