public void Visit(Box3D box)
        {
            Shape3DComposite composite = new Shape3DComposite();
            composite.CoordinateSystem = box.CoordinateSystem;

            float dx = box.Width / 2;
            float dy = box.Height / 2;
            float dz = box.Depth / 2;

            var top = new Rectangle3D {
                A = new Vector3D(-dx, -dy, -dz),
                B = new Vector3D(-dx, -dy, +dz),
                C = new Vector3D(+dx, -dy, -dz),
                Material = box.Material
            };

            var bottom = new Rectangle3D {
                A = new Vector3D(-dx, +dy, -dz),
                B = new Vector3D(-dx, +dy, +dz),
                C = new Vector3D(+dx, +dy, -dz),
                Material = box.Material
            };

            var left = new Rectangle3D {
                A = new Vector3D(-dx, -dy, -dz),
                B = new Vector3D(-dx, +dy, -dz),
                C = new Vector3D(-dx, -dy, +dz),
                Material = box.Material
            };

            var right = new Rectangle3D {
                A = new Vector3D(+dx, -dy, -dz),
                B = new Vector3D(+dx, +dy, -dz),
                C = new Vector3D(+dx, -dy, +dz),
                Material = box.Material
            };

            var front = new Rectangle3D {
                A = new Vector3D(-dx, -dy, -dz),
                B = new Vector3D(-dx, +dy, -dz),
                C = new Vector3D(+dx, -dy, -dz),
                Material = box.Material
            };

            var back = new Rectangle3D {
                A = new Vector3D(-dx, -dy, +dz),
                B = new Vector3D(-dx, +dy, +dz),
                C = new Vector3D(+dx, -dy, +dz),
                Material = box.Material
            };

            composite.Add(top);
            composite.Add(bottom);
            composite.Add(left);
            composite.Add(right);
            composite.Add(front);
            composite.Add(back);

            Visit(composite);
        }
Beispiel #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            _scene = new Scene3D();
            _scene = new VrmlToG3DConverter().Convert(@"D:\dev\graph3d\Graph3D.Vrml.Test\Ant.wrl");
            _scene.Shapes.First().CoordinateSystem.Translate(new Vector3D(-0.2f, 0.3f, 0.2f)).Scale(2, 2, 2).RotateV(0.2f).RotateU(0.1f).Translate(new Vector3D(0, 0, -0.2f));
            PreciseColor color = new PreciseColor(0.6f, 0.3f, 0.3f) * 0.8f;
            const float shininess = 0;
            var b = new Box3D {
                Material = { DiffuseColor = color, Shininess = shininess },
                Width = 40,
                Height = 40,
                Depth = 120
            };
            _scene.Shapes.Add(b);

            _scene.Shapes.Add(new Sphere3D {
                CoordinateSystem = { Position = new Vector3D(0, 14, -2) },
                Radius = 6.0f,
                Material = {
                    DiffuseColor = new PreciseColor(0.0f, 0.1f, 0.0f) * 2.99f,
                    AmbientIntensity = 0.9f,
                    Shininess = 0.1f
                }
            });

            _scene.Shapes.Add(new Sphere3D {
                CoordinateSystem = { Position = new Vector3D(9, 14, -2) },
                Radius = 6.0f,
                Material = {
                    DiffuseColor = new PreciseColor(0.0f, 0.0f, 1.0f) * 0.19f,
                    AmbientIntensity = 0.95f,
                    Shininess = 0.05f
                }
            });

            //_scene.Shapes.Add(new Box3D {
            //    CoordinateSystem = { Position = new Vector3D(3, 14, -6) },
            //    Width = 4,
            //    Height = 4,
            //    Depth = 4,
            //    Material = {
            //        DiffuseColor = new PreciseColor(0.0f, 0.0f, 1.0f) * 0.50f,
            //        AmbientIntensity = 0.2f,
            //        Shininess = 0.1f
            //    }
            //});

            const int omniCount = 5;
            for (int i = 0; i < omniCount; i++) {
                float angle = 2 * (float)System.Math.PI * i / omniCount;
                const float radius = 16;
                float x = 0 + radius * (float)System.Math.Cos(angle);
                float y = -19.5f;
                float z = -7 + radius * (float)System.Math.Sin(angle);
                _scene.Lights.Add(new OmniLight3D {
                    Position = new Vector3D(x, y, z),
                    Color = new PreciseColor(1.0f, 1.0f, 1.0f),
                    Power = 1500.0f / omniCount
                });
            }
        }