无法将类型“double”隐式转换为“float”。存在一个显式转换(是否缺少强制转换?)
如题,出错处加了float结果还是一样,C#与OpenGL的结合,刚开始学习,求解!
-------------------------------------
原代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CsGL.OpenGL;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
namespace OpenGL_nn1
{
class OpenGLBase:OpenGLControl
{
private const double PI = 3.1415926;
private float x, y, z, angle;
private float xRot, yRot;
Timer Timer_GLupdate = new Timer();//窗口重绘计时器
public OpenGLBase()
{
#region OpenGL屏幕刷新计时器
this.Timer_GLupdate.Tick += new EventHandler(Timer_GLupdate_Tick);
this.Timer_GLupdate.Interval = 10;
this.Timer_GLupdate.Start();
#endregion
}
private void Timer_GLupdate_Tick(Object sender, EventArgs e)//创建屏幕刷新计时器回调函数,每10ms刷新一次OpenGL窗口
{
this.Invalidate();
}
#region 窗体重绘
/// <summary>
/// 视口改变大小时重新设置视口和绘图
/// </summary>
/// <param name="e"></param>
protected override void OnSizeChanged(EventArgs e)
{
GL.glViewport(0, 0, this.Bounds.Width, this.Bounds.Height);//根据窗口大小设置视口
/*重置投影矩阵堆栈 */
GL.glMatrixMode(GL.GL_PROJECTION);
GL.glLoadIdentity();
GL.gluPerspective(40.0f, (float)this.Bounds.Width / (float)this.Bounds.Height, 0.1f, 500.0f);
GL.glMatrixMode(GL.GL_MODELVIEW);//重置模型视图矩阵
GL.glLoadIdentity();
}
#endregion
/* OpenGL初始化*/
protected override void InitGLContext()
{
base.InitGLContext();
GL.glMatrixMode(GL.GL_PROJECTION);//选择投影矩阵
GL.glLoadIdentity();//重设投影矩阵
GL.gluPerspective(40.0, ((double)(this.Width) / (double)(this.Height)), 1.0, 1000.0);//调整视口大小
GL.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);//黑色背景
GL.glMatrixMode(GL.GL_MODELVIEW);//选择模型观察矩阵
GL.glLoadIdentity();//重置模型观察矩阵
GL.glShadeModel(GL.GL_SMOOTH); // 启用阴影平滑
}
public override void glDraw()
{
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // 清除屏幕及深度缓存
GL.glLoadIdentity(); //重置当前模型视图矩阵
GL.glColor3f(0.0f, 1.0f, 0.0f);//绘图颜色设置为绿色
GL.glPushMatrix();//保存矩阵状态并进行旋转
GL.glRotatef(xRot, 1.0f, 0.0f, 0.0f);
GL.glRotatef(yRot, 0.0f, 1.0f, 0.0f);
GL.glBegin(GL.GL_POINTS);//对所有剩余的点只调用一次
GL.glEnd();
GL.glFlush(); //刷新绘图命令
}
public void glConstruclist()
{
float z =-50.0f;
for (angle = 0.0f; angle <= (2.0f * Math.PI) * 3.0f; angle += 0.1f)
{
x = 50.0f* Math.Sin(angle);////提示出错
y = 50.0f* Math.Cos(angle);