谁有用c++编写OpenGL实现圆与直线段相交的程序,跪求

谁有用c++编写OpenGL实现圆与直线段相交的程序,跪求,第1张

#include <iostream>

#include <cstdlib>

#include <ctime>

using namespace std

void main()

{

int n,*a

float aver

int i,j

int max,maxtimes

cout<<"n="

cin>>n

srand( (unsigned)time( NULL ) )

a=new int[n]

aver=0

for(i=0i<ni++)

{

int y=0

int cnt=0

while(y<5 &&y>-10)

{

if(rand()%2==1)

y++

else

y--

cnt++

}

a[i]=cnt

aver+=cnt

}

for(i=0i<ni++)

cout<<a[i]<<' '

cout<<endl

aver/=n

cout<<"a="<<aver<<endl

for(i=0i<n-1i++)

for(j=0j<n-i-1j++)

if(a[j]>a[j+1])

{

int temp=a[j]

a[j]=a[j+1]

a[j+1]=temp

}

maxtimes=0

i=0

while(i<n)

{

for(j=ia[j+1]==a[j]j++)

if(j-i+1>maxtimes)

{

maxtimes=j-i+1

max=a[j]

}

i=j+1

}

cout<<"m="<<max<<endl

}

由于算法的问题,我的程序在局数没有重复数字的情况下,输出的是最小值。

#include <iostream>

#include <windows.h>

#include <GL/glut.h>

using namespace std

void init(void)

{

glClearColor(0.0, 0.0, 0.0, 0.0)

glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0)

}

void display(void)

{

glClear(GL_COLOR_BUFFER_BIT)

glColor3f(1.0, 1.0, 1.0)

glBegin(GL_LINES)

glVertex3f(0.25, 0.25, 0.0)

glVertex3f(0.75, 0.25, 0.0)

glEnd()

glFlush()

}

int main(int argc, char **argv)

{

glutInit(&argc, argv)

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB)

glutInitWindowSize(200, 200)

glutCreateWindow("I love OpenGl")

init()

glutDisplayFunc(display)

glutMainLoop()

return 0

}

这个需要进行点击测试,即输入一个二维屏幕坐标,返回一个三维点坐标,然后用两个三维点坐标画线。伪代码:

Point2 p1, p2

Vector3 pt1 = HitTest(p1)

Vector3 pt2 = HitTest(p2)

glBegin( GL_LINE_STRIP)

glVertex3d(pt1.x, pt1.y, pt1.z)

glVertex3d(pt2.x, pt2.y, pt2.z)

glEnd()

其中HitTest需要自己写,一般视线是和地面(工作面,物体面)求交;


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8114725.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存