在c#中wpf应用程序项目中建立一个opengl绘画窗口。知道的请帮我一下。也可加993505118细谈。非常感谢。
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
1个回答
展开全部
opengl有wpf版本和winform版本,注意下载的是不是正确的,添加控件之后
OpenGL gl = GlArea.OpenGL;
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
gl.LoadIdentity();
gl.Translate(0f, 0.0f, -3.0f);
gl.Rotate(rotateAngleXAxis, 1.0f, 0f, 0f);
gl.Rotate(rotateAngleYAxis, 0f, 1.0f, 0f);
gl.Rotate(rotateAngleZAxis, 0f, 0f, 1.0f);
//DrawArc(gl, 0.1f, 0.1f, 0.5f, 0f, 3.14f, 20);
#region 绘制坐标轴
//TODO: 增加X,Y,Z轴端点标记显示
gl.LineWidth(2);
gl.Begin(OpenGL.GL_LINES);
gl.Color(0f, 0f, 1.0f);
gl.Vertex(0.0f, 0f, 0f);
gl.Vertex(0.0f, 1.0f, 0f);
gl.Color(1f, 0f, 0f);
gl.Vertex(0.0f, 0f, 0f);
gl.Vertex(0.0f, 0f, 1.0f);
gl.Color(0f, 1f, 0f);
gl.Vertex(0.0f, 0f, 0f);
gl.Vertex(1.0f, 0f, 0f);
gl.End();
GlInited = true;
#endregion
gl.Color(1f, 1f, 1f);
//DRAW A POINT
gl.PointSize(2f);
gl.Color(1.0f, 1.0f, 1.0f);
gl.Begin(OpenGL.GL_POINTS);
gl.Vertex(AxisNumbers[0].Value / glRangeNum, AxisNumbers[1].Value / glRangeNum, AxisNumbers[2].Value / glRangeNum);
gl.End();
if (loadReady)
{
if (moveInfoList != null)
{
OnRotating = false;
var array = moveInfoList.ToArray();
for (int i = 0; i < array.Length - 1; i++)
{
if (array[i].Type == 1)
{
gl.Begin(OpenGL.GL_LINES);
if (array[i].Position[2] == 0 || array[i + 1].Position[2] == 0)
gl.Color((float)(0x68) / 255.0, (float)(0x7a) / 255.0, (float)(0xcc) / 255.0);
else
gl.Color((float)(0x255) / 255.0, (float)(0x2a) / 255.0, (float)(0x2c) / 255.0);
gl.Vertex(array[i].Position[0] / glRangeNum, array[i].Position[1] / glRangeNum, array[i].Position[2] / glRangeNum);
gl.Vertex(array[i + 1].Position[0] / glRangeNum, array[i + 1].Position[1] / glRangeNum, array[i + 1].Position[2] / glRangeNum);
gl.End();
}
}
}
}
gl.Flush();
前面是配置,后面可看可不看
OpenGL gl = GlArea.OpenGL;
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
gl.LoadIdentity();
gl.Translate(0f, 0.0f, -3.0f);
gl.Rotate(rotateAngleXAxis, 1.0f, 0f, 0f);
gl.Rotate(rotateAngleYAxis, 0f, 1.0f, 0f);
gl.Rotate(rotateAngleZAxis, 0f, 0f, 1.0f);
//DrawArc(gl, 0.1f, 0.1f, 0.5f, 0f, 3.14f, 20);
#region 绘制坐标轴
//TODO: 增加X,Y,Z轴端点标记显示
gl.LineWidth(2);
gl.Begin(OpenGL.GL_LINES);
gl.Color(0f, 0f, 1.0f);
gl.Vertex(0.0f, 0f, 0f);
gl.Vertex(0.0f, 1.0f, 0f);
gl.Color(1f, 0f, 0f);
gl.Vertex(0.0f, 0f, 0f);
gl.Vertex(0.0f, 0f, 1.0f);
gl.Color(0f, 1f, 0f);
gl.Vertex(0.0f, 0f, 0f);
gl.Vertex(1.0f, 0f, 0f);
gl.End();
GlInited = true;
#endregion
gl.Color(1f, 1f, 1f);
//DRAW A POINT
gl.PointSize(2f);
gl.Color(1.0f, 1.0f, 1.0f);
gl.Begin(OpenGL.GL_POINTS);
gl.Vertex(AxisNumbers[0].Value / glRangeNum, AxisNumbers[1].Value / glRangeNum, AxisNumbers[2].Value / glRangeNum);
gl.End();
if (loadReady)
{
if (moveInfoList != null)
{
OnRotating = false;
var array = moveInfoList.ToArray();
for (int i = 0; i < array.Length - 1; i++)
{
if (array[i].Type == 1)
{
gl.Begin(OpenGL.GL_LINES);
if (array[i].Position[2] == 0 || array[i + 1].Position[2] == 0)
gl.Color((float)(0x68) / 255.0, (float)(0x7a) / 255.0, (float)(0xcc) / 255.0);
else
gl.Color((float)(0x255) / 255.0, (float)(0x2a) / 255.0, (float)(0x2c) / 255.0);
gl.Vertex(array[i].Position[0] / glRangeNum, array[i].Position[1] / glRangeNum, array[i].Position[2] / glRangeNum);
gl.Vertex(array[i + 1].Position[0] / glRangeNum, array[i + 1].Position[1] / glRangeNum, array[i + 1].Position[2] / glRangeNum);
gl.End();
}
}
}
}
gl.Flush();
前面是配置,后面可看可不看
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询