Globe中是用OpenGL绘制图形实例

只贴源码:就不加说明啦

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.GlobeCore;
using ESRI.ArcGIS.Analyst3D;
using CsGL.OpenGL;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Carto;

namespace CSharpOpenGL
{
    public partial class Form2 : Form
    {
        private IGlobeDisplayEvents_Event globeDisplayEvent = null;
        public Form2()
        {
            InitializeComponent();
            globeDisplayEvent = this.axGlobeControl1.GlobeDisplay as IGlobeDisplayEvents_Event;
            if (globeDisplayEvent != null)
            {
                globeDisplayEvent.AfterDraw += new IGlobeDisplayEvents_AfterDrawEventHandler(globeDisplayEvent_AfterDraw);
            }
        }
        void globeDisplayEvent_AfterDraw(ISceneViewer pViewer)
        {
            render();
        }

        private void render()
        {

            //在这里写opengl代码。
            //指定画点x和y经纬度           
            double m_srcX = 121;           
            double m_srcY = 40;//Convert the mouse coordinate into a geocentric (OpenGL) coordinate system.           
            double glX, glY, glZ;
            IGlobeViewUtil m_globeViewUtil = axGlobeControl1.GlobeCamera as IGlobeViewUtil;
            m_globeViewUtil.GeographicToGeocentric(m_srcX, m_srcY, 20, out glX, out glY, out glZ);
            double radius=1000;
            double radio = radius / 637000;
            GL.glPushMatrix();
            GL.glTranslated(glX, glY, glZ);
            GL.glScaled(radio, radio, radio);
            drawradar(glX, glY, glZ);
            GL.glPopMatrix();
        }
        private void drawradar(double x, double y, double z)
        {
            GL.glRotated(45, 1.0, 0.0, 0.0);
            GL.glPushMatrix();
            GL.glTranslated(0, 0.5, 0);
            GL.glColor3d(0.0, 1.0, 0.2);
            GLUT.glutSolidCube(1);
            GL.glTranslated(0.0, 0.8, 0.0);
            GL.glColor3d(0.0, 0.0, 1.0);
            GLUT.glutSolidCube(0.7);
            GL.glPopMatrix();
            GL.glPushMatrix();
            GL.glTranslated(0 - 0.5, 2.2, 0);
            GL.glRotated(90, 0.0, 1.0, 0.0);
            //=======================================
            GL.glColor3d(1.0, 1.0, 1.0);
            GL.glRotated(45, 1.0, 0.0, 0.0);
            GLUT.glutWireCone(1.5, 0.6, 10, 10);
            //=======================================
            GL.glRotated(180, 1.0, 0.0, 0.0);
            GL.glTranslated(0.0, 0.0, -0.7);
            GLUT.glutWireCone(0.2, 2, 10, 10);
            Random ran = new Random();
            double color = ran.NextDouble();
            GL.glColor3d(color, 0, 0);
            GL.glTranslated(0.0, 0.0, 2.0);
            GLUT.glutWireSphere(0.1, 10, 10);
            GL.glColor3d(1, 0, 0);
            //GLUT.glutWireCone(1.5, 200, 10, 10);
            GL.glPopMatrix();
            GL.glPushMatrix();
            GL.glTranslated(0 - 0.5, 2.2, 0);
            GL.glRotated(135, 0.0, 0.0, 1.0);
            DrawYuanTai(500, 1.5, 10);
            GL.glPopMatrix();
        }
        private void DrawYuanTai(double Distance, double sRadius, double bRadius)
        {
            double step = Math.PI / 50;
            GL.glBegin(GL.GL_LINE_LOOP);
            for (double i = 0; i < 2 * Math.PI; i += step)
            {
                GL.glVertex3d(0, sRadius * Math.Sin(i), sRadius * Math.Cos(i));
            }
            GL.glEnd();
            GL.glBegin(GL.GL_LINE_LOOP);
            for (double i = 0; i < 2 * Math.PI; i += step)
            {
                GL.glVertex3d(Distance, bRadius * Math.Sin(i), bRadius * Math.Cos(i));
            }
            GL.glEnd();
            GL.glBegin(GL.GL_LINES);
            for (double i = 0; i < 2 * Math.PI; i += step)
            {
                GL.glVertex3d(0, sRadius * Math.Sin(i), sRadius * Math.Cos(i));
                GL.glVertex3d(Distance, bRadius * Math.Sin(i), bRadius * Math.Cos(i));
            }
            GL.glEnd();
        }
    }
}

 

注:例子中使用了,OPenGL的C#版的插件csgl.1.4.1可以在网上下载。本人的资源里也可以找到

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值