Пример #1
0
        public _3DModelViewer()
        {
            InitializeComponent();
            this.simpleOpenGlControl1.InitializeContexts();
            Init();
            try
            {
                file = new ThreeDSFile("./models/Airplane.3ds");
                model = file.Model;
                modelCenter = new Vector((file.MaxX - file.MinX) / 2 + file.MinX,
                                         (file.MaxY - file.MinY) / 2 + file.MinY,
                                         (file.MaxZ - file.MinZ) / 2 + file.MinZ);

                // move eye so model is entirely visible at startup
                modelRotation = new Vector(0, 0, 0);
                // center x/y at model's center x/y
                double width = file.MaxX - file.MinX;
                double height = file.MaxY - file.MinY;
                eye[0] = Convert.ToSingle(file.MinX + width / 2);
                eye[1] = Convert.ToSingle(file.MinY + height / 2);

                // use trigonometry to calculate the z value that exposes the model
                eye[2] = Convert.ToSingle(file.MaxZ + (width > height ? width : height / 2) /
                                          Math.Tan((Math.PI / 180) * 90 / 2));
            }
            catch (Exception ex)
            {

            }
        }
Пример #2
0
            public ThreeDSChunk(ThreeDSFile parent, BinaryReader reader)
            {
                streamStartPos = reader.BaseStream.Position;

                // 2 byte ID
                ID = (Groups)reader.ReadUInt16();
                Contract.Assert(ID >= Groups.C_VERSION && ID <= Groups.C_EDITKEYFRAME);

                // 4 byte length
                Length = reader.ReadUInt32();

                // = 6
                BytesRead = 6;

                parent.ModelLoadProgressEvent(this, new ProgressChangedEventArgs(streamStartPos * 100.0 / reader.BaseStream.Length));
            }
Пример #3
0
        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="argv">
        /// A <see cref="System.String"/>
        /// </param>
        public static void Main(string[] argv)
        {
            // instantiate GLUT for our windowing provider
            Glut.glutInit();
            //Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB | Glut.GLUT_ALPHA | Glut.GLUT_DEPTH);
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB | Glut.GLUT_DEPTH);
            Glut.glutInitWindowSize( winW, winH );
            Glut.glutCreateWindow("Salmon Viewer");

            // initialize our OpenGL parameters
            Init();

            // if no arguments, show message
            if (argv.Length <= 0)
            {
                Console.WriteLine("No file was specified.");

                return;
            }

            file = null;
            switch (Path.GetExtension(argv[0]).ToLower())
            {
                case ".3ds":

                    try
                    {
                        // Load our 3DS model from the command line argument
                        file =  new ThreeDSFile( argv[0] );
                        model = file.Model;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An Error occured: " + ex.Message);
                    }
                    break;

            //			case ".obj":
            //				new ObjFile(argv[0]);
            //				break;

                default:
                    Console.WriteLine("Not a supported file type.");
                    break;
            }

            modelCenter = new Vector((file.MaxX-file.MinX)/2+file.MinX,
                                     (file.MaxY-file.MinY)/2+file.MinY,
                                     (file.MaxZ-file.MinZ)/2+file.MinZ);

            // move eye so model is entirely visible at startup

            // center x/y at model's center x/y
            double width = file.MaxX-file.MinX;
            double height = file.MaxY-file.MinY;
            eye[0] = Convert.ToSingle(file.MinX+width/2);
            eye[1] = Convert.ToSingle(file.MinY+height/2);

            // use trigonometry to calculate the z value that exposes the model
            eye[2] = Convert.ToSingle(file.MaxZ + (width > height ? width : height / 2) /
                                      Math.Tan((Math.PI/180) * 90/2));

            // print viewer control keys to Console
            PrintInstructions();

            // instantiate GLUT event handlers
            Glut.glutDisplayFunc(new Glut.DisplayCallback(Display));
            Glut.glutIdleFunc(new Glut.IdleCallback (Idle) );
            Glut.glutKeyboardFunc(new Glut.KeyboardCallback(Keyboard));
            Glut.glutKeyboardUpFunc(new Glut.KeyboardUpCallback(KeyboardUp));
            Glut.glutReshapeFunc(new Glut.ReshapeCallback(Reshape));
            Glut.glutMotionFunc (new Glut.MotionCallback (Motion) );

            // start loop and wait for user input
            Glut.glutMainLoop();
        }
Пример #4
0
        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="argv">
        /// A <see cref="System.String"/>
        /// </param>
        public static void Main(string[] argv)
        {
            // instantiate GLUT for our windowing provider
            Glut.glutInit();
            //Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB | Glut.GLUT_ALPHA | Glut.GLUT_DEPTH);
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB | Glut.GLUT_DEPTH);
            Glut.glutInitWindowSize(winW, winH);
            Glut.glutCreateWindow("Salmon Viewer");

            // initialize our OpenGL parameters
            Init();

            // if no arguments, show message
            if (argv.Length <= 0)
            {
                Console.WriteLine("No file was specified.");

                return;
            }

            file = null;
            switch (Path.GetExtension(argv[0]).ToLower())
            {
            case ".3ds":

                try
                {
                    // Load our 3DS model from the command line argument
                    file  = new ThreeDSFile(argv[0]);
                    model = file.Model;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("An Error occured: " + ex.Message);
                }
                break;

            //			case ".obj":
            //				new ObjFile(argv[0]);
            //				break;

            default:
                Console.WriteLine("Not a supported file type.");
                break;
            }

            modelCenter = new Vector((file.MaxX - file.MinX) / 2 + file.MinX,
                                     (file.MaxY - file.MinY) / 2 + file.MinY,
                                     (file.MaxZ - file.MinZ) / 2 + file.MinZ);

            // move eye so model is entirely visible at startup

            // center x/y at model's center x/y
            double width  = file.MaxX - file.MinX;
            double height = file.MaxY - file.MinY;

            eye[0] = Convert.ToSingle(file.MinX + width / 2);
            eye[1] = Convert.ToSingle(file.MinY + height / 2);

            // use trigonometry to calculate the z value that exposes the model
            eye[2] = Convert.ToSingle(file.MaxZ + (width > height ? width : height / 2) /
                                      Math.Tan((Math.PI / 180) * 90 / 2));

            // print viewer control keys to Console
            PrintInstructions();

            // instantiate GLUT event handlers
            Glut.glutDisplayFunc(new Glut.DisplayCallback(Display));
            Glut.glutIdleFunc(new Glut.IdleCallback(Idle));
            Glut.glutKeyboardFunc(new Glut.KeyboardCallback(Keyboard));
            Glut.glutKeyboardUpFunc(new Glut.KeyboardUpCallback(KeyboardUp));
            Glut.glutReshapeFunc(new Glut.ReshapeCallback(Reshape));
            Glut.glutMotionFunc(new Glut.MotionCallback(Motion));

            // start loop and wait for user input
            Glut.glutMainLoop();
        }