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 Form1() { InitializeComponent(); SceneContainer sceneContainer = new SceneContainer();// paint container addRoomObjects(sceneContainer); sceneContainer.AddChild(new Axies()); // paints the x,y and z axis arcBallEffect = new ArcBallEffect(sceneControl1.Scene.CurrentCamera as LookAtCamera); // implements rotation per mouse move sceneContainer.AddEffect(arcBallEffect); sceneControl1.Scene.SceneContainer.AddChild(sceneContainer); arcBallEffect.SetViewMode(ViewMode.NO);// look diagonaly on the object // Hide bounding box toolStripButtonShowBoundingVolumes_Click(this, new EventArgs()); }
private void Create3DObject(object sender, EventArgs e) { try { int nx = this.ToInt(this.tbNX); int ny = this.ToInt(this.tbNY); int nz = this.ToInt(this.tbNZ); float radius = this.ToFloat(this.tbRadius); float minValue = this.ToFloat(this.tbRangeMin); float maxValue = this.ToFloat(this.tbRangeMax); if (minValue >= maxValue) { throw new ArgumentException("min value equal or equal to maxValue"); } //生成需要画的模型 ColorVertexes colorVertexes = ColorVertexesFactory.Create(nx, ny, nz, radius, minValue, maxValue); ColorVertexesElement visualElement = new ColorVertexesElement(colorVertexes); //output(particles); Rect3D rect3D = colorVertexes.Bounds; Scene scene = new Scene(); this.arcBallEffect = new ArcBallEffect(); //initialize Scene3D InitializeModelScene(scene, colorVertexes.Bounds, this.sceneControl1, this.arcBallEffect); this.sceneControl1.Scene = scene; scene.SceneContainer.AddChild(visualElement); visualElement.AddEffect(this.arcBallEffect); this.sceneControl1.Invalidate(); } catch (Exception error) { MessageBox.Show(error.Message); } }
private void iniCameraEffect() { 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); 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); foreach (var e in sceneControl1.Scene.SceneContainer.Traverse()) { if (!isPolygon(e)) { e.AddEffect(axisArcBallEffect); } } }
private void InitElements(Scene scene) { var objectRoot = new SharpGL.SceneGraph.Primitives.Folder() { Name = "Root" }; scene.SceneContainer.AddChild(objectRoot); // 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); var axisRoot = new SharpGL.SceneGraph.Primitives.Folder() { Name = "axis root" }; scene.SceneContainer.AddChild(axisRoot); axisArcBallEffect = new Figures.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); InitAxis(objectRoot); InitAxis(axisRoot); InitFrameElement(1, 1, 1, objectRoot); InitGridElement(-5, -5, 0, 10, 10, objectRoot); }
private void InitializeModelScene(Scene scene, Rect3D rect3D, OpenGLControl sceneControl, ArcBallEffect arcBallEffect) { float centerX = rect3D.X + rect3D.Size.x / 2.0f; float centerY = rect3D.Y + rect3D.Size.y / 2.0f; float centerZ = rect3D.Z + rect3D.Size.z / 2.0f; //scene.CreateInContext(scenContor); Vertex center = new Vertex(centerX, centerY, centerZ); Vertex position = center + new Vertex(0.0f, 0.0f, 1.0f) * (rect3D.Size.z * 2); Vertex PositionNear = center + new Vertex(0.0f, 0.0f, 1.0f) * (rect3D.Size.z * 0.52f); //arcBallEffect. var lookAtCamera = new LookAtCamera() { Position = position, Target = center, UpVector = new Vertex(0f, 1f, 0f), FieldOfView = 60, AspectRatio = 1.0f, Near = (PositionNear - center).Z, Far = float.MaxValue }; scene.CurrentCamera = lookAtCamera; Vertex lightPosition = center; Light light1 = new Light() { Name = "Light 1", On = true, Position = lightPosition, GLCode = OpenGL.GL_LIGHT0 }; /* * Light light2 = new Light() * { * Name = "Light 2", * On = true, * Position = center + new Vertex(1.0f,0.0f,0.0f)* rect3D.Size.x, * GLCode = OpenGL.GL_LIGHT1 * }; * * Light light3 = new Light() * { * Name = "Light 3", * On = true, * Position = center + new Vertex(0.0f,1.0f,0.0f)*rect3D.Size.y, * GLCode = OpenGL.GL_LIGHT2 * }; */ var folder = new Folder() { Name = "Lights" }; folder.AddChild(light1); //folder.AddChild(light2); //folder.AddChild(light3); scene.SceneContainer.AddChild(folder); // 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 = true; sceneAttributes.EnableAttributes.EnableTexture2D = true; sceneAttributes.EnableAttributes.EnableBlend = true; sceneAttributes.ColorBufferAttributes.BlendingSourceFactor = BlendingSourceFactor.SourceAlpha; sceneAttributes.ColorBufferAttributes.BlendingDestinationFactor = BlendingDestinationFactor.OneMinusSourceAlpha; sceneAttributes.LightingAttributes.TwoSided = true; scene.SceneContainer.AddEffect(sceneAttributes); sceneControl.OpenGL.SetDimensions(sceneControl.Width, sceneControl.Height); scene.Resize(sceneControl.Width, sceneControl.Height); }