|
// drawLine.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <osg/Drawable>
#include <osg/Geode>
#include <osgViewer/Viewer>
#include <iostream>
using namespace std;
typedef struct Point
{
GLint x;
GLint y;
GLint z;
}Pt;
class PolyLine
{
public:
Pt* p;
Pt* q;
int num;
PolyLine(){p=new Pt;q=new Pt;}
void get_vertices(Pt*s)
{
p=s;
}
void get_num_veitices(int s){num=s;}
};
void line(Pt *p1,Pt* p2)
{
glBegin(GL_LINE_LOOP );
glColor3f(0.0,1.0,0.0);
glVertex3d(p1->x,p1->y,p1->z);
glVertex3d(p2->x,p2->y,p2->z);
glEnd();
}
void line2i(PolyLine *s)//使用OpenGL函数进行划线,有六个参数,分别是起点的三个坐标和终点的三个坐标
{
int i=0;
cin>>s->num;
for(i=0;i<s->num;i++)
{
//cout<<(s->p+i)->x<<(s->p+i)->y<<cout<<(s->p+i)->z<<endl;
//cout<<(s->p+i+1)->x<<(s->p+i+1)->y<<cout<<(s->p+i+1)->z<<endl;
cin>>(s->p)->x>>(s->p)->y>>(s->p)->z;
if (i>0)
{line(s->q,s->p);}
(s->q)->x=(s->p)->x;
(s->q)->y=(s->p)->y;
(s->q)->z=(s->p)->z;
}
}
class DrawLine:public osg:rawable
{
public:
PolyLine *s;
DrawLine() {}
DrawLine(PolyLine *p) {s=p;}//构造函数
DrawLine(const DrawLine& teapot,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY)sg::Drawable(teapot,copyop) {} //复制构造函数
META_Object(myDrawLineApp,DrawLine); //这个是用来干什么的呢?
virtual void drawImplementation(osg::RenderInfo&) const
{
line2i(s);
}
virtual osg::BoundingBox computeBound() const
{
osg::BoundingBox bbox;
bbox.expandBy(osg::Vec3(0,0,0));
bbox.expandBy(osg::Vec3(10,10,10));
return bbox;
}
protected:
virtual ~DrawLine() {}
};
int _tmain(int argc, _TCHAR* argv[])
{
PolyLine *s= new PolyLine;
osgViewer::Viewer viewer;
osg::Geode* geode = new osg::Geode();
geode->addDrawable(new DrawLine(s));
// add model to viewer.
viewer.setSceneData( geode );
return viewer.run() ;
}
但不调试是正确的,但是一运行就死机,各位高手看看是怎么了
|
|