急求 vc++6.0下的opengl 利用橡皮筋技术画圆和椭圆形的完整代码 验证正确后采纳

作者&投稿:旁腾 (若有异议请与网页底部的电邮联系)
用vc6.0在mfc中调用opengl如何画三次B样条曲线,求操作步骤和程序代码。谢谢!~

#include

#include
#pragma comment(lib,"glut32.lib")

//

#if 0
// the points of the curve - these are the same as the bezier curve
// points demonstrated in the bezier curve example.

float Points[4][3] = {
{ 10,10,0 },
{ 5,10,2 },
{ -5,0,0 },
{-10,5,-2}
};

#define NUM_POINTS 4

// The following sets of 4 indices are the curves that need to
// be drawn to create a clamped cubic b-spline. In total there
// are 5 curve segments to draw.
//
// 0 0 0 1
// 0 0 1 2
// 0 1 2 3
// 1 2 3 3
// 2 3 3 3
//
// Remember this when trying to understand knot vectors!!
//

#else

float Points[9][3] = {
{ 10,5,0 },
{ 5,10,0 },
{ -5,15,0 },
{ -10,-5,0 },
{ 4,-4,0 },
{ 10,5,0 },
{ 5,10,0 },
{ -5,15,0 },
{ -10,-5,0 }
};

#define NUM_POINTS 9

//若绘制过首尾控制点的曲线
// 0 0 0 1
// 0 0 1 2
// 0 1 2 3
// 1 2 3 4
// 2 3 4 5
// 3 4 5 6
// 4 5 6 6
// 5 6 6 6
//
// Remember this when trying to understand knot vectors!!
//
//若绘制首尾相接的平滑曲线 ,即为当前绘制
// 0 1 2 3
// 1 2 3 4
// 2 3 4 5
// 3 4 5 6
#endif

// the level of detail for the curve
unsigned int LOD=20;

#define NUM_SEGMENTS (NUM_POINTS-3)
//

float* GetPoint(int i)
{
// return 1st point
if (i<0)
{
return Points[0];
}

if (i<NUM_POINTS)
{
return Points[i];
}
// return last point

return Points[NUM_POINTS-1];
}

//------------------------------------------------------------ OnKeyPress()
void myIdle(void)
{
glutPostRedisplay();
}

//------------------------------------------------------------ OnDraw()
void OnDraw()
{
// clear the screen & depth buffer
glClear(GL_COLOR_BUFFER_BIT);
// clear the previous transform
glLoadIdentity();
// set the camera position
// gluLookAt( 1,10,30, // eye pos
// 0,0,0, // aim point
// 0,1,0); // up direction
// glColor3f(0.5,0.2,0);
glPointSize(3);
//
// // draw curve hull
glColor3f(0.3,0,0.5);
glBegin(GL_LINE_STRIP);
for(int i=0;i!=NUM_POINTS;++i)
{
glVertex3fv( Points[i] );
}
glEnd();

glColor3f(0,1,0);

// begin drawing our curve
glBegin(GL_LINE_STRIP);

for(int start_cv=0,j=0;j<NUM_SEGMENTS;j++,start_cv++)
{
// for each section of curve, draw LOD number of divisions
for(int i=0;i!=LOD;++i)
{
// use the parametric time value 0 to 1 for this curve
// segment.
float t = (float)i/LOD;
// the t value inverted
float it = 1.0f-t;

// calculate blending functions for cubic bspline
float b0 = it*it*it/6.0f;
float b1 = (3*t*t*t - 6*t*t +4)/6.0f;
float b2 = (-3*t*t*t +3*t*t + 3*t + 1)/6.0f;
float b3 = t*t*t/6.0f;

// calculate the x,y and z of the curve point
float x = b0 * GetPoint( start_cv + 0 )[0] +
b1 * GetPoint( start_cv + 1 )[0] +
b2 * GetPoint( start_cv + 2 )[0] +
b3 * GetPoint( start_cv + 3 )[0] ;

float y = b0 * GetPoint( start_cv + 0 )[1] +
b1 * GetPoint( start_cv + 1 )[1] +
b2 * GetPoint( start_cv + 2 )[1] +
b3 * GetPoint( start_cv + 3 )[1] ;

float z = b0 * GetPoint( start_cv + 0 )[2] +
b1 * GetPoint( start_cv + 1 )[2] +
b2 * GetPoint( start_cv + 2 )[2] +
b3 * GetPoint( start_cv + 3 )[2] ;

// specify the point

glVertex2f( x,y );
}
}

// we need to specify the last point on the curve
//glVertex3fv( Points[NUM_POINTS-1] );
glEnd();

// draw CV's
glBegin(GL_POINTS);
for(int i=0;i!=NUM_POINTS;++i)
{
glVertex3fv( Points[i] );
}
glEnd();

// currently we've been drawing to the back buffer, we need
// to swap the back buffer with the front one to make the image visible
glutSwapBuffers();
}

//------------------------------------------------------------ OnInit()
void OnInit()
{
//glClearColor(1,1,1,0);
}

//------------------------------------------------------------ OnExit()
void OnExit()
{
}


//------------------------------------------------------------ OnReshape()
void OnReshape(int w, int h)
{
// prevents division by zero when minimising window
if (h==0)
{
h=1;
}

// set the drawable region of the window
glViewport(0,0,w,h);
// set up the projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// just use a perspective projection
//gluPerspective(45,(float)w/h,0.1,100);
if(w<=h)
{
glOrtho(-20.0,20.0,-20.0*(GLfloat)h/(GLfloat)w,20.0*(GLfloat)h/(GLfloat)w,0.0,100.0);
}
else
{
glOrtho(-20.0,20.0,-20.0*(GLfloat)h/(GLfloat)w,20.0*(GLfloat)h/(GLfloat)w,0.0,100.0);
}
// go back to modelview matrix so we can move the objects about
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

//------------------------------------------------------------ main()
int main(int argc,char** argv)
{
// initialise glut
glutInit(&argc,argv);
// request a depth buffer, RGBA display mode, and we want double buffering
glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE);
// set the initial window size
glutInitWindowSize(640,480);
// create the window
glutCreateWindow("Clamped B-Spline Curve");
// run our custom initialisation
OnInit();
// set the function to use to draw our scene
glutDisplayFunc(OnDraw);

涂料加盟
// set the function to handle changes in screen size
glutReshapeFunc(OnReshape);
glutIdleFunc(&myIdle);
// set the function to be called when we exit
atexit(OnExit);
// this function runs a while loop to keep the program running.
glutMainLoop();

return 0;

}

C3DN论坛里有很多OpenGL动画程序,都是可以正常运行的,在【资源下载】版块里。比如《OpenGL导入模型》、《3ds模型汽车视景仿真》、《3D多米诺牌》、《国产3D仿CS程序》、《CS仿真程序(最酷的OpenGL程序)》.............

/* 这是我自己编写的一个小程序,我也是刚学opengl,懂得不多,现学现卖,不做指出,望多见谅,在我的电脑上vc++6.0,是能够运行的,画出了一个红色的圆,白色的背景。希望能帮到你。*/
#include<GL/glut.h>
#include<math.h>
#define PI 3.141592f
void init(void)
{
glClearColor(1.0,1.0,1.0,0.0);//窗口背景为白色
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,200.0,0.0,150.0);//投影范围
}
void lineSegment(void)
{
GLfloat x,y,z,angle;
z=0.0f;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin( GL_LINES);
for(angle=0.0f;angle<=PI;angle+=(PI/1000000.0f))
{
x=100+50.0f*sin(angle);
y=60+50.0f*cos(angle);
glVertex3f(x,y,z);
x=100+50.0f*sin(angle+PI);
y=60+50.0f*cos(angle+PI);
glVertex3f(x,y,z);
}
glEnd();
glFlush();

}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE );
glutInitWindowPosition(0,0);//设置显示窗口左上的坐标值
glutInitWindowSize(1000,700);//设置显示窗口的宽和高
glutCreateWindow("An example OpenGL Program");
init();
glutDisplayFunc(lineSegment);
glutMainLoop();

}

百度把


铅山县17768614339: 在vc++6.0怎么建立一个关于OpenGL的工程 -
检冉瑞奇: 首先需要配置环境 在 http://www.xmission.com/~nate/glut/glut-3.7.6-bin.zip中下载最新的glut.h glut32.lib glut32.dll. 第一步:将glut32.dll按路径:windows\system32\放入, 第二步:将glut32.lib按路径:Microsoft Visual Studio\vc98\lib\放入 第三步:...

铅山县17768614339: 如何在VC++6.0上搭建OpenGL开发环境 -
检冉瑞奇: 在 Windows7 下安装Visual C++ 6.0 要注意: 1在安装或者使用 Visual C++ 6.0 时,凡是出现兼容性问题提示对话框,一律按以下方式处理 把"不再显示此消息"打上勾,然后选择"运行程序". 2在安装 VC 的时候,选择"custom(自定义安装)";接下来就要注意了

铅山县17768614339: 如何在vc6.0配置opengl -
检冉瑞奇: 第一步:选择一个编译环境现在Windows系统的主流编译环境有VisualStudio,BrolandC++Builder,Dev-C++等,它们都是支持OpenGL的. 但这里选择VC++6.0作为学习OpenGL的环境. 第二步:安装GLUT工具包GLUT不是OpenGL所必须的...

铅山县17768614339: win7系统,求在VC++6.0中配置openGL的方法! -
检冉瑞奇: 扩展库的配置吧 (1)“d:\Program Files\Microsoft Visual Studio\VC98\include\GL文件夹”.把扩展库头文件放这里,比如glut.h glew.h (2)“d:\Program Files\Microsoft Visual Studio\VC98\lib文件夹”.把lib文件放这里,比如glut.lib glut32.lib (3)“C:\Windows\System32”.把dll文件放在这里,比如glut.dll glut32.dll

铅山县17768614339: vc ++6.0下 opengl系统开发环境文字 -
检冉瑞奇: 嘿嘿,我帮你凑一章出来第三章 开发环境及相关技术的介绍3.1 C语言特点 1. C是中级语言.它把高级语言的基本结构和语句与低级语言的实用性结合起来.C 语言可以像汇编语言一样对位、字节和地址进行操作, 而这三者是计算机最基本的工...

铅山县17768614339: 急求一个VC++6.0下的opengl动画代码,,画什么都行,但是不要太过简单,要完整的代码.谢谢啦! -
检冉瑞奇: C3DN论坛里有很多OpenGL动画程序,都是可以正常运行的,在【资源下载】版块里.比如《OpenGL导入模型》、《3ds模型汽车视景仿真》、《3D多米诺牌》、《国产3D仿CS程序》、《CS仿真程序(最酷的OpenGL程序)》.............

铅山县17768614339: 求一个VC++6.0环境下的OPENGL三维视角转换程序源码 -
检冉瑞奇: 要做好后直接发过来的,做的好的话(3)continue表示不再继续往下执行~此时k==4.然后判断c

铅山县17768614339: 急求:vc++6.0问题的解决办法(哪位高人帮帮我) -
检冉瑞奇: 打开vc界面 点击VC“TOOLS(工具)”—>“Option(选择)” —>“Directories(目录)”重新设置“Excutable Fils、Include Files、 Library Files、Source File...

铅山县17768614339: Vc6.0 opengl -
检冉瑞奇: 看一下你的代码中的include语句,再检查VC include目录的配置,两者要一致

铅山县17768614339: 我的电脑是WIN7系统的,下载了vC++编程器无法兼容怎么办,急..求一个可以兼容的下载地址. -
检冉瑞奇: win7对于C++6.0是不大兼容,建议用studio 2008 或者2010,2005貌似也可以.微软官网有的下载.给你一个2008的下载网址,厄,...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网