private void InitElements(Scene scene) { // This implements free rotation(with translation and rotation). var camera = GetCamera(); objectArcBallEffect = new ArcBallEffect( camera.Position.X, camera.Position.Y, camera.Position.Z, camera.Target.X, camera.Target.Y, camera.Target.Z, camera.UpVector.X, camera.UpVector.Y, camera.UpVector.Z); //objectRoot.AddEffect(objectArcBallEffect); axisArcBallEffect = new ArcBallEffect(camera.Position.X, camera.Position.Y, camera.Position.Z, camera.Target.X, camera.Target.Y, camera.Target.Z, camera.UpVector.X, camera.UpVector.Y, camera.UpVector.Z); //axisRoot.AddEffect(axisArcBallEffect); InitLight(sceneControl1.Scene.SceneContainer); var grid = new Grid() { Name = "网格" }; grid.AddEffect(objectArcBallEffect); sceneControl1.Scene.SceneContainer.AddChild(grid); Axies axies = new Axies() { Name = "坐标系" }; axies.AddEffect(objectArcBallEffect); sceneControl1.Scene.SceneContainer.AddChild(axies); }
public void RenderRetainedMode(SharpGL.OpenGL openGL) { var axies = new Axies(); axies.Render(openGL, RenderMode.Design); if (DrawAll == true) { foreach (var mesh in MainWindowViewModel.Meshes) { mesh.Draw(openGL); } } else { if (MainWindowViewModel.SelectedMesh != null) { MainWindowViewModel.SelectedMesh.Draw(openGL); MainWindowViewModel.SelectedMesh.Transformation.TranslateX = TranslateX; MainWindowViewModel.SelectedMesh.Transformation.TranslateY = TranslateY; MainWindowViewModel.SelectedMesh.Transformation.TranslateZ = TranslateZ; MainWindowViewModel.SelectedMesh.Transformation.RotateX = RotateX; MainWindowViewModel.SelectedMesh.Transformation.RotateY = RotateY; MainWindowViewModel.SelectedMesh.Transformation.RotateZ = RotateZ; MainWindowViewModel.SelectedMesh.Transformation.Depth = Depth; } } }
public void RenderRetainedMode(SharpGL.OpenGL openGL) { var axies = new Axies(); axies.Render(openGL, RenderMode.Design); if (DrawAll == true) { foreach (var mesh in Meshes) { mesh.Draw(openGL); } if (SelectedMesh != null) { EditMesh(); } } else { if (SelectedMesh != null) { SelectedMesh.Draw(openGL); EditMesh(); } } }
private void 坐标系ToolStripMenuItem_Click(object sender, EventArgs e) { Axies axies = new Axies() { Name = "坐标系" }; axies.AddEffect(axisArcBallEffect); sceneControl1.Scene.SceneContainer.AddChild(axies); treeView1.Nodes.Clear(); AddElementToTree(sceneControl1.Scene.SceneContainer, treeView1.Nodes); }
/// <summary> /// /// </summary> /// <param name="camera">if null, please set camera for result's orthoArcBallEffect.Camera property later.</param> /// <returns></returns> public static OrthoAxisElement Create(LookAtCamera camera = null) { OrthoAxisElement element = new OrthoAxisElement() { Name = "orthogonal axis element" }; // Create a set of scene attributes. OpenGLAttributesEffect sceneAttributes = new OpenGLAttributesEffect() { Name = "Scene Attributes" }; // Specify the scene attributes. sceneAttributes.EnableAttributes.EnableDepthTest = true; sceneAttributes.EnableAttributes.EnableNormalize = true; sceneAttributes.EnableAttributes.EnableLighting = false; //sceneAttributes.EnableAttributes.EnableTexture2D = true; //sceneAttributes.EnableAttributes.EnableBlend = true; //sceneAttributes.ColorBufferAttributes.BlendingSourceFactor = BlendingSourceFactor.SourceAlpha; //sceneAttributes.ColorBufferAttributes.BlendingDestinationFactor = BlendingDestinationFactor.OneMinusSourceAlpha; //sceneAttributes.LightingAttributes.TwoSided = true; //sceneAttributes.TransformAttributes.MatrixMode = MatrixMode.Projection; element.AddEffect(sceneAttributes); OrthoArcBallEffect orthoAxisArcBallEffect = new OrthoArcBallEffect(camera); element.AddEffect(orthoAxisArcBallEffect); Axies axies = new Axies(); element.AddChild(axies); LinearTransformationEffect transform = new LinearTransformationEffect(); transform.LinearTransformation.ScaleX = 10; transform.LinearTransformation.ScaleY = 10; transform.LinearTransformation.ScaleZ = 10; axies.AddEffect(transform); //Grid grid = new Grid(); //element.AddChild(grid); //LinearTransformationEffect transform = new LinearTransformationEffect(); //transform.LinearTransformation.ScaleX = 0.1f; //transform.LinearTransformation.ScaleY = 0.1f; //transform.LinearTransformation.ScaleZ = 0.1f; //grid.AddEffect(transform); element.orthoArcBallEffect = orthoAxisArcBallEffect; return(element); }
public SceneModel() { WorldAxies = new Axies(); OrientationGrid = new Grid() { IsEnabled = true, }; SceneObjectModels = new ObservableCollection <SceneObjectModel>(); Errors = new ObservableCollection <MessageViewModel>(); // [RS] Set translation as initial object transformation tool. SwitchToTranslationCommand.Execute(null); }
/// <summary> /// Construct a new scene, optionally enableing post-processing, if available. /// </summary> /// <param name="postprocessingEnabled">Whether or not to enable post-processing; defaults to false</param> public Scene(OpenGL gl, Size viewportSize) { this.gl = gl; this.viewportSize = viewportSize; model = null; postprocessingEnabled = false; ClearColor = Color.Black; camera = new MovingLookAtCamera() { Position = new Vertex(10f, 0f, 0f), Target = new Vertex(0f, 0f, 0f), UpVector = new Vertex(0f, 0f, 1f), Near = 0, Far = 250, HorizontalTheta = 0.785f, VerticalTheta = -0.785f }; RenderGrid = true; RenderAxies = true; grid = new Grid(); grid.Size = 150; axies = new Axies(); axies.Size = 150; //Set attributes attrs = new OpenGLAttributesEffect(); attrs.EnableAttributes.EnableDepthTest = true; attrs.EnableAttributes.EnableNormalize = true; attrs.EnableAttributes.EnableLighting = true; attrs.EnableAttributes.EnableTexture2D = true; attrs.LightingAttributes.TwoSided = false; Color col = Color.FromArgb(40, 40, 40); // Nice soft-ish lighting Light light = new Light(OpenGL.GL_LIGHT0) { Position = new Vertex(-9, -9, 11), Ambient = Color.Black, Diffuse = col, Specular = col }; this.Children.Add(light); light = new Light(OpenGL.GL_LIGHT1) { Position = new Vertex(9, -9, 11), Ambient = Color.Black, Diffuse = col, Specular = col }; this.Children.Add(light); light = new Light(OpenGL.GL_LIGHT2) { Position = new Vertex(0, 15, 15), Ambient = Color.Black, Diffuse = col, Specular = col }; this.Children.Add(light); }
private void openGLControl1_OpenGLDraw(object sender, SharpGL.RenderEventArgs args) { float u = 0; float v = 0; float deltaU = 0.01f; float deltaV = 0.01f; float step = 0.1f; float endU = 1.0f; float endV = 1.0f; float c = 0.2f; float x = 0, y = 0, z = 0; float b = 0.5f, a = 1.0f, p = 3.0f; float[] light_specular_color = { 1.0f, 1.0f, 1.0f, 1.0f }; float[] light_ambient_color = { 0.0f, 0.39f, 0.0f, 1.0f }; float[] light_diffuse_color = { 1.0f, 1.0f, 1.0f, 1.0f }; float[] light_position = { 100.0f, 2.0f, -100.0f, 0.0f }; float[] positional_light = { 10.0f, 100.0f, -20.0f }; Vector vecColorM = new Vector(1.0f, 0.0f, 0.0f); //blue Vector vecColorL = new Vector(1.0f, 1.0f, 1.0f); //white //Vector vecLight = new Vector(50.0f, 1.0f, 0.0f); Vector vecViewer = new Vector(-20.0f, 4.0f, -10.0f); Vector normal; Vector light; Vector vecReflected; Vector vecLight = new Vector(0, 0, 0); float shining = 1.0f; OpenGL gl = this.openGLControl1.OpenGL; gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); gl.LoadIdentity(); gl.Color(0.0, 0.0, 1.0); gl.Translate(0, 2.0, -20); gl.Rotate(angx, 0, angx); gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Filled); angx += 0.5f; //gl.Enable(OpenGL.GL_LIGHTING); //gl.Enable(OpenGL.GL_LIGHT0); //gl.Enable(OpenGL.GL_NORMALIZE); //gl.Light(SharpGL.Enumerations.LightName.Light0, SharpGL.Enumerations.LightParameter.Ambient, light_ambient_color); //gl.Light(SharpGL.Enumerations.LightName.Light0, SharpGL.Enumerations.LightParameter.Diffuse, light_diffuse_color); //gl.Light(SharpGL.Enumerations.LightName.Light0, SharpGL.Enumerations.LightParameter.Specular, light_specular_color); //gl.Light(SharpGL.Enumerations.LightName.Light0, SharpGL.Enumerations.LightParameter.Position, light_position); for (u = 0; u <= 4.0 * Math.PI; u += step) { gl.Begin(OpenGL.GL_TRIANGLE_STRIP); float f = 0; for (v = 5.0f; v <= 7.0f; v += step) { x = (v * (float)Math.Cos(u)); y = (v * (float)Math.Sin(u)); z = b * u + a * (float)Math.Sin(p * u); normal = VectorOperations.GetNormal(u, v, deltaU, deltaV, a, b, p); //gl.Normal(normal.X, normal.Y, normal.Z); vecReflected = calculateReflectedVec(vecLight, normal); vecLight.X = (x - positional_light[0]); vecLight.Y = (y - positional_light[1]); vecLight.Z = (z - positional_light[2]); light = calculateLightCos(vecColorM, vecColorL, vecLight, normal, vecReflected, vecViewer, shining); gl.Color(light.X, light.Y, light.Z); gl.Vertex(x, y, z); x = (v * (float)Math.Cos(u + step)); y = (v * (float)Math.Sin(u + step)); z = b * (u + step) + a * (float)Math.Sin(p * (u + step)); normal = VectorOperations.GetNormal((u + step), v, deltaU, deltaV, a, b, p); //gl.Normal(normal.X, normal.Y, normal.Z); vecReflected = calculateReflectedVec(vecLight, normal); vecLight.X = (x - positional_light[0]); vecLight.Y = (y - positional_light[1]); vecLight.Z = (z - positional_light[2]); light = calculateLightCos(vecColorM, vecColorL, vecLight, normal, vecReflected, vecViewer, shining); gl.Color(light.X, light.Y, light.Z); gl.Vertex(x, y, z); } gl.End(); } Axies ax = new Axies(); ax.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Design); gl.Flush(); }