public void paint(bool shadow, I3dsTaken c)
    {
        obj_type aux = null;

        foreach (obj_type o in objects.Values)
        {
            if (o.name == "glass")
            {
                aux = o;
            }
            else if (c.Actions(o, shadow, Rot, Trans, Scl))
            {
            }

            else
            {
                o.paint(shadow, Rot, Trans, Scl);
            }
        }

        if (aux != null)
        {
            if (c.Actions(aux, shadow, Rot, Trans, Scl))
            {
            }
            else
            {
                aux.paint(shadow, Rot, Trans, Scl);
            }
        }
    }
    public void ComputeNormals()
    {
        foreach (DictionaryEntry di in objects)
        {
            obj_type o = (obj_type)(di.Value);

            for (int i = 0; i < o.polygons_qty; i++)
            {
                o.polygon[i].normal = normals(o.vertex[o.polygon[i].c].point, o.vertex[o.polygon[i].b].point, o.vertex[o.polygon[i].a].point);
            }

            for (int i = 0; i < o.vertices_qty; i++)
            {
                vertex temp = new vertex();
                for (int j = 0; j < o.polygons_qty; j++)
                {
                    if (o.polygon[j].a == i || o.polygon[j].b == i || o.polygon[j].c == i)
                    {
                        temp = _3dsMath.sum(temp, o.polygon[j].normal);
                    }
                }
                //temp = o.polygon[j].normal;
                o.vertex[i].normal = _3dsMath.normalize(temp);
            }
        }
    }
예제 #3
0
 public virtual void set_obj_type(obj_type type)
 {
     set_argument(Arguments_type.type_obj, (int)type);
 }
예제 #4
0
 public abstract bool Actions(obj_type o, bool _shadow, int[] rot, float[] trans, float[] scl);
예제 #5
0
    public int Load3DS(string p_filename)
    {
        int i; //Index variable

            objects = new Hashtable();
            ambient = new Hashtable();
            diffuse = new Hashtable();
            specular = new Hashtable();
            shininess = new Hashtable();
            shininessST = new Hashtable();
            obj_type p_object = null;
            BinaryReader l_file; //File pointer

            ushort l_chunk_id; //Chunk identifier
            uint l_chunk_lenght; //Chunk lenght

            char l_char; //Char variable
            ushort l_qty; //Number of elements in each chunk

            ushort l_face_flags; //Flag that stores some face information
            bool l_end = false;

            string l_mat_name = "";
            color_typeF cl;
            float per;

            using (l_file = new BinaryReader(File.Open(p_filename, FileMode.Open, FileAccess.Read)))
            {
                while (!l_end) //Loop to scan the whole file
                {
                    try
                    {
                        l_chunk_id = l_file.ReadUInt16();
                        l_chunk_lenght = l_file.ReadUInt32();

                        switch (l_chunk_id)
                        {
                            //----------------- MAIN3DS -----------------
                            // Description: Main chunk, contains all the other chunks
                            // Chunk ID: 4d4d
                            // Chunk Lenght: 0 + sub chunks
                            //-------------------------------------------
                            case 0x4d4d:
                                break;

                            //----------------- EDIT3DS -----------------
                            // Description: 3D Editor chunk, objects layout info
                            // Chunk ID: 3d3d (hex)
                            // Chunk Lenght: 0 + sub chunks
                            //-------------------------------------------
                            case 0x3d3d:
                                break;

                            //--------------- EDIT_OBJECT ---------------
                            // Description: Object block, info for each object
                            // Chunk ID: 4000 (hex)
                            // Chunk Lenght: len(object name) + sub chunks
                            //-------------------------------------------
                            case 0x4000:
                                p_object = new obj_type();
                                p_object.name = "";
                                p_object.loader = this;
                                do
                                {
                                    l_char = l_file.ReadChar();
                                    if (l_char > 0)
                                        p_object.name = p_object.name + l_char;
                                } while (l_char != 0);
                                objects.Add(p_object.name, p_object);
                                break;

                            //--------------- OBJ_TRIMESH ---------------
                            // Description: Triangular mesh, contains chunks for 3d mesh info
                            // Chunk ID: 4100 (hex)
                            // Chunk Lenght: 0 + sub chunks
                            //-------------------------------------------
                            case 0x4100:
                                break;

                            //--------------- TRI_VERTEXL ---------------
                            // Description: Vertices list
                            // Chunk ID: 4110 (hex)
                            // Chunk Lenght: 1 x unsigned short (number of vertices)
                            //             + 3 x float (vertex coordinates) x (number of vertices)
                            //             + sub chunks
                            //-------------------------------------------
                            case 0x4110:
                                l_qty = l_file.ReadUInt16();
                                p_object.vertices_qty = l_qty;
                                p_object.vertex = new vertex_type[l_qty];
                                for (i = 0; i < l_qty; i++)
                                {
                                    p_object.vertex[i].point.x = l_file.ReadSingle();
                                    p_object.vertex[i].point.y = l_file.ReadSingle();
                                    p_object.vertex[i].point.z = l_file.ReadSingle();
                                }
                                break;

                            //--------------- TRI_FACEL1 ----------------
                            // Description: Polygons (faces) list
                            // Chunk ID: 4120 (hex)
                            // Chunk Lenght: 1 x unsigned short (number of polygons)
                            //             + 3 x unsigned short (polygon points) x (number of polygons)
                            //             + sub chunks
                            //-------------------------------------------
                            case 0x4120:
                                l_qty = l_file.ReadUInt16();
                                p_object.polygons_qty = l_qty;
                                p_object.polygon = new polygon_type[l_qty];
                                for (i = 0; i < l_qty; i++)
                                {
                                    p_object.polygon[i].a = l_file.ReadUInt16();
                                    p_object.polygon[i].b = l_file.ReadUInt16();
                                    p_object.polygon[i].c = l_file.ReadUInt16();
                                    l_face_flags = l_file.ReadUInt16();
                                }
                                break;

                            //------------------- MATERIAL ID -----------------
                            // Description: Material name asigned to the object
                            // Chunk ID: 4130 (hex)
                            // Chunk Length: len(mat_name)
                            //				 + 2 x unsigned short
                            //-------------------------------------------------
                            case 0x4130:
                                p_object.mat_name = "";
                                do
                                {
                                    l_char = l_file.ReadChar();
                                    if (l_char > 0)
                                        p_object.mat_name = p_object.mat_name + l_char;
                                } while (l_char != 0);
                                int entr = l_file.ReadUInt16();
                                int face;
                                for (i = 0; i < entr; i++)
                                    face = l_file.ReadUInt16();
                                break;

                            //------------- TRI_MAPPINGCOORS ------------
                            // Description: Vertices list
                            // Chunk ID: 4140 (hex)
                            // Chunk Lenght: 1 x unsigned short (number of mapping points)
                            //		       + 2 x float (mapping coordinates) x (number of mapping points)
                            //             + sub chunks
                            //-------------------------------------------
                            case 0x4140:
                                l_qty = l_file.ReadUInt16();
                                p_object.mapcoord = new mapcoord_type[l_qty];
                                for (i = 0; i < l_qty; i++)
                                {
                                    p_object.mapcoord[i].u = l_file.ReadSingle();
                                    p_object.mapcoord[i].v = l_file.ReadSingle();
                                }
                                break;

                            case 0xAFFF:
                                break;

                            case 0xA000:
                                l_mat_name = "";
                                do
                                {
                                    l_char = l_file.ReadChar();
                                    if (l_char > 0)
                                        l_mat_name = l_mat_name + l_char;
                                } while (l_char != 0);
                                break;

                            case 0xA010:
                                l_chunk_id = l_file.ReadUInt16();
                                l_chunk_lenght = l_file.ReadUInt32();

                                cl = new color_typeF();
                                cl.r = (l_file.ReadByte())/255.0f;
                                cl.g = (l_file.ReadByte())/255.0f;
                                cl.b = (l_file.ReadByte())/255.0f;
                                cl.a=1.0f;
                                ambient.Add(l_mat_name, cl);
                                break;

                            case 0xA020:
                                l_chunk_id = l_file.ReadUInt16();
                                l_chunk_lenght = l_file.ReadUInt32();

                                cl = new color_typeF();
                                cl.r = (l_file.ReadByte())/255.0f;
                                cl.g = (l_file.ReadByte())/255.0f;
                                cl.b = (l_file.ReadByte())/255.0f;
                                cl.a=1.0f;
                                diffuse.Add(l_mat_name, cl);
                                break;

                            case 0xA030:
                                l_chunk_id = l_file.ReadUInt16();
                                l_chunk_lenght = l_file.ReadUInt32();

                                cl = new color_typeF();
                                cl.r = (l_file.ReadByte())/255.0f;
                                cl.g = (l_file.ReadByte())/255.0f;
                                cl.b = (l_file.ReadByte())/255.0f;
                                cl.a=1.0f;
                                specular.Add(l_mat_name, cl);
                                break;

                            case 0xA040:
                                l_chunk_id = l_file.ReadUInt16();
                                l_chunk_lenght = l_file.ReadUInt32();

                                per = (l_file.ReadUInt16())/255.0f;

                                shininess.Add(l_mat_name, (float)per);
                                break;

                            case 0xA041:
                                l_chunk_id = l_file.ReadUInt16();
                                l_chunk_lenght = l_file.ReadUInt32();

                                per = (l_file.ReadUInt16())/255.0f;

                                shininessST.Add(l_mat_name,(float) per);
                                break;
                            //----------- Skip unknow chunks ------------
                            //We need to skip all the chunks that currently we don't use
                            //We use the chunk lenght information to set the file pointer
                            //to the same level next chunk
                            //-------------------------------------------
                            default:
                                l_file.BaseStream.Seek(l_chunk_lenght - 6, SeekOrigin.Current);
                                break;
                        }
                    }
                    catch (EndOfStreamException e)
                    {
                        l_end = true;
                    }
                }
            }
            return (1); // Returns ok
    }
예제 #6
0
    public override bool Actions(obj_type o, bool _shadow, int[] rot, float[] trans, float[] scl)
    {
        if (actList.Contains("maletero") && o.name == "trunk")
        {
            Gl.glPushMatrix();
            Gl.glTranslated((trans[0] - 0.4), trans[1] - 1.5, trans[2]);
            Gl.glRotated(-45, 0, 0, 1);
            Gl.glTranslated(-(trans[0] + 0.4), -(trans[1] + 1.5), -trans[2]);
            o.paint(_shadow, rot, trans, scl);
            Gl.glPopMatrix();

            return(true);
        }


        else if (actList.Contains("capo") && o.name == "hood")
        {
            Gl.glPushMatrix();
            Gl.glTranslated((trans[0] + 0.2), trans[1] - 1.2, trans[2]);
            Gl.glRotated(45, 0, 0, 1);
            Gl.glTranslated(-(trans[0] - 0.2), -(trans[1] + 1.2), -trans[2]);
            o.paint(_shadow, rot, trans, scl);
            Gl.glPopMatrix();
            return(true);
        }
        else if (actList.Contains("descapotable") && o.name == "glass")
        {
            Gl.glPushMatrix();
            Gl.glClipPlane(Gl.GL_CLIP_PLANE0, new double[] { 1, 1, 0, -2 });
            Gl.glEnable(Gl.GL_CLIP_PLANE0);
            o.paint(_shadow, rot, trans, scl);
            Gl.glDisable(Gl.GL_CLIP_PLANE0);
            Gl.glPopMatrix();
            return(true);
        }

        else if (actList.Contains("descapotable") && o.name == "trim")
        {
            Gl.glPushMatrix();
            Gl.glClipPlane(Gl.GL_CLIP_PLANE1, new double[] { 0, -1, 0, 0.5 });
            Gl.glEnable(Gl.GL_CLIP_PLANE1);
            o.paint(_shadow, rot, trans, scl);
            Gl.glDisable(Gl.GL_CLIP_PLANE1);
            Gl.glPopMatrix();
            return(true);
        }

        else if (actList.Contains("descapotable") && o.name == "roof")
        {
            Gl.glPushMatrix();
            Gl.glClipPlane(Gl.GL_CLIP_PLANE0, new double[] { 1, 0, 0, 3.5 });
            Gl.glClipPlane(Gl.GL_CLIP_PLANE1, new double[] { -1, 0, 0, -2.0 });
            Gl.glEnable(Gl.GL_CLIP_PLANE0);
            Gl.glEnable(Gl.GL_CLIP_PLANE1);
            Gl.glTranslated(-1.0, -0.7, 0);
            o.paint(_shadow, rot, trans, scl);
            Gl.glDisable(Gl.GL_CLIP_PLANE1);
            Gl.glDisable(Gl.GL_CLIP_PLANE0);
            Gl.glPopMatrix();
            return(true);
        }

        return(false);
    }
예제 #7
0
 public bool Actions(obj_type o,bool _shadow, int[] rot, float[] trans, float[] scl)
 {
     return false;
 }
예제 #8
0
 public abstract bool Actions(obj_type o,bool _shadow, int[] rot, float[] trans, float[] scl);
예제 #9
0
    public override bool Actions(obj_type o,bool _shadow, int[] rot, float[] trans, float[] scl)
    {
        if(actList.Contains("maletero") && o.name=="trunk")
            {
                Gl.glPushMatrix();
                Gl.glTranslated((trans[0]-0.4),trans[1]-1.5,trans[2]);
                Gl.glRotated(-45,0,0,1);
                Gl.glTranslated(-(trans[0]+0.4),- (trans[1]+1.5),-trans[2]);
                o.paint(_shadow, rot, trans, scl);
                Gl.glPopMatrix();

                return true;
            }

            else if(actList.Contains("capo") && o.name=="hood")
            {
                Gl.glPushMatrix();
                Gl.glTranslated((trans[0]+0.2),trans[1]-1.2,trans[2]);
                Gl.glRotated(45,0,0,1);
                Gl.glTranslated(-(trans[0]-0.2),- (trans[1]+1.2),-trans[2]);
                o.paint(_shadow, rot, trans, scl);
                Gl.glPopMatrix();
                return true;
            }
            else if(actList.Contains("descapotable") && o.name=="glass")
            {
                Gl.glPushMatrix();
                Gl.glClipPlane(Gl.GL_CLIP_PLANE0,new double[]{1,1,0,-2});
                Gl.glEnable(Gl.GL_CLIP_PLANE0);
                o.paint(_shadow, rot, trans, scl);
                Gl.glDisable(Gl.GL_CLIP_PLANE0);
                Gl.glPopMatrix();
            return true;
            }

            else if(actList.Contains("descapotable") && o.name=="trim")
            {
                Gl.glPushMatrix();
                Gl.glClipPlane(Gl.GL_CLIP_PLANE1,new double[]{0,-1,0,0.5});
                Gl.glEnable(Gl.GL_CLIP_PLANE1);
                o.paint(_shadow, rot, trans, scl);
                Gl.glDisable(Gl.GL_CLIP_PLANE1);
                Gl.glPopMatrix();
                return true;
            }

            else if(actList.Contains("descapotable") && o.name=="roof")
            {
                Gl.glPushMatrix();
                Gl.glClipPlane(Gl.GL_CLIP_PLANE0,new double[]{1,0,0,3.5});
                Gl.glClipPlane(Gl.GL_CLIP_PLANE1,new double[]{-1,0,0,-2.0});
                Gl.glEnable(Gl.GL_CLIP_PLANE0);
                Gl.glEnable(Gl.GL_CLIP_PLANE1);
                Gl.glTranslated(-1.0,-0.7,0);
                o.paint(_shadow, rot, trans, scl);
                Gl.glDisable(Gl.GL_CLIP_PLANE1);
                Gl.glDisable(Gl.GL_CLIP_PLANE0);
                Gl.glPopMatrix();
                return true;
            }

            return false;
    }
예제 #10
0
 public bool Actions(obj_type o, bool _shadow, int[] rot, float[] trans, float[] scl)
 {
     return(false);
 }
    public int Load3DS(string p_filename)
    {
        int i;                 //Index variable

        objects     = new Hashtable();
        ambient     = new Hashtable();
        diffuse     = new Hashtable();
        specular    = new Hashtable();
        shininess   = new Hashtable();
        shininessST = new Hashtable();
        obj_type     p_object = null;
        BinaryReader l_file;         //File pointer

        ushort l_chunk_id;           //Chunk identifier
        uint   l_chunk_lenght;       //Chunk lenght

        char   l_char;               //Char variable
        ushort l_qty;                //Number of elements in each chunk

        ushort l_face_flags;         //Flag that stores some face information
        bool   l_end = false;

        string      l_mat_name = "";
        color_typeF cl;
        float       per;

        using (l_file = new BinaryReader(File.Open(p_filename, FileMode.Open, FileAccess.Read)))
        {
            while (!l_end)                     //Loop to scan the whole file
            {
                try
                {
                    l_chunk_id     = l_file.ReadUInt16();
                    l_chunk_lenght = l_file.ReadUInt32();

                    switch (l_chunk_id)
                    {
                    //----------------- MAIN3DS -----------------
                    // Description: Main chunk, contains all the other chunks
                    // Chunk ID: 4d4d
                    // Chunk Lenght: 0 + sub chunks
                    //-------------------------------------------
                    case 0x4d4d:
                        break;

                    //----------------- EDIT3DS -----------------
                    // Description: 3D Editor chunk, objects layout info
                    // Chunk ID: 3d3d (hex)
                    // Chunk Lenght: 0 + sub chunks
                    //-------------------------------------------
                    case 0x3d3d:
                        break;

                    //--------------- EDIT_OBJECT ---------------
                    // Description: Object block, info for each object
                    // Chunk ID: 4000 (hex)
                    // Chunk Lenght: len(object name) + sub chunks
                    //-------------------------------------------
                    case 0x4000:
                        p_object        = new obj_type();
                        p_object.name   = "";
                        p_object.loader = this;
                        do
                        {
                            l_char = l_file.ReadChar();
                            if (l_char > 0)
                            {
                                p_object.name = p_object.name + l_char;
                            }
                        } while (l_char != 0);
                        objects.Add(p_object.name, p_object);
                        break;

                    //--------------- OBJ_TRIMESH ---------------
                    // Description: Triangular mesh, contains chunks for 3d mesh info
                    // Chunk ID: 4100 (hex)
                    // Chunk Lenght: 0 + sub chunks
                    //-------------------------------------------
                    case 0x4100:
                        break;

                    //--------------- TRI_VERTEXL ---------------
                    // Description: Vertices list
                    // Chunk ID: 4110 (hex)
                    // Chunk Lenght: 1 x unsigned short (number of vertices)
                    //             + 3 x float (vertex coordinates) x (number of vertices)
                    //             + sub chunks
                    //-------------------------------------------
                    case 0x4110:
                        l_qty = l_file.ReadUInt16();
                        p_object.vertices_qty = l_qty;
                        p_object.vertex       = new vertex_type[l_qty];
                        for (i = 0; i < l_qty; i++)
                        {
                            p_object.vertex[i].point.x = l_file.ReadSingle();
                            p_object.vertex[i].point.y = l_file.ReadSingle();
                            p_object.vertex[i].point.z = l_file.ReadSingle();
                        }
                        break;

                    //--------------- TRI_FACEL1 ----------------
                    // Description: Polygons (faces) list
                    // Chunk ID: 4120 (hex)
                    // Chunk Lenght: 1 x unsigned short (number of polygons)
                    //             + 3 x unsigned short (polygon points) x (number of polygons)
                    //             + sub chunks
                    //-------------------------------------------
                    case 0x4120:
                        l_qty = l_file.ReadUInt16();
                        p_object.polygons_qty = l_qty;
                        p_object.polygon      = new polygon_type[l_qty];
                        for (i = 0; i < l_qty; i++)
                        {
                            p_object.polygon[i].a = l_file.ReadUInt16();
                            p_object.polygon[i].b = l_file.ReadUInt16();
                            p_object.polygon[i].c = l_file.ReadUInt16();
                            l_face_flags          = l_file.ReadUInt16();
                        }
                        break;

                    //------------------- MATERIAL ID -----------------
                    // Description: Material name asigned to the object
                    // Chunk ID: 4130 (hex)
                    // Chunk Length: len(mat_name)
                    //				 + 2 x unsigned short
                    //-------------------------------------------------
                    case 0x4130:
                        p_object.mat_name = "";
                        do
                        {
                            l_char = l_file.ReadChar();
                            if (l_char > 0)
                            {
                                p_object.mat_name = p_object.mat_name + l_char;
                            }
                        } while (l_char != 0);
                        int entr = l_file.ReadUInt16();
                        int face;
                        for (i = 0; i < entr; i++)
                        {
                            face = l_file.ReadUInt16();
                        }
                        break;

                    //------------- TRI_MAPPINGCOORS ------------
                    // Description: Vertices list
                    // Chunk ID: 4140 (hex)
                    // Chunk Lenght: 1 x unsigned short (number of mapping points)
                    //		       + 2 x float (mapping coordinates) x (number of mapping points)
                    //             + sub chunks
                    //-------------------------------------------
                    case 0x4140:
                        l_qty             = l_file.ReadUInt16();
                        p_object.mapcoord = new mapcoord_type[l_qty];
                        for (i = 0; i < l_qty; i++)
                        {
                            p_object.mapcoord[i].u = l_file.ReadSingle();
                            p_object.mapcoord[i].v = l_file.ReadSingle();
                        }
                        break;

                    case 0xAFFF:
                        break;

                    case 0xA000:
                        l_mat_name = "";
                        do
                        {
                            l_char = l_file.ReadChar();
                            if (l_char > 0)
                            {
                                l_mat_name = l_mat_name + l_char;
                            }
                        } while (l_char != 0);
                        break;

                    case 0xA010:
                        l_chunk_id     = l_file.ReadUInt16();
                        l_chunk_lenght = l_file.ReadUInt32();

                        cl   = new color_typeF();
                        cl.r = (l_file.ReadByte()) / 255.0f;
                        cl.g = (l_file.ReadByte()) / 255.0f;
                        cl.b = (l_file.ReadByte()) / 255.0f;
                        cl.a = 1.0f;
                        ambient.Add(l_mat_name, cl);
                        break;

                    case 0xA020:
                        l_chunk_id     = l_file.ReadUInt16();
                        l_chunk_lenght = l_file.ReadUInt32();

                        cl   = new color_typeF();
                        cl.r = (l_file.ReadByte()) / 255.0f;
                        cl.g = (l_file.ReadByte()) / 255.0f;
                        cl.b = (l_file.ReadByte()) / 255.0f;
                        cl.a = 1.0f;
                        diffuse.Add(l_mat_name, cl);
                        break;

                    case 0xA030:
                        l_chunk_id     = l_file.ReadUInt16();
                        l_chunk_lenght = l_file.ReadUInt32();

                        cl   = new color_typeF();
                        cl.r = (l_file.ReadByte()) / 255.0f;
                        cl.g = (l_file.ReadByte()) / 255.0f;
                        cl.b = (l_file.ReadByte()) / 255.0f;
                        cl.a = 1.0f;
                        specular.Add(l_mat_name, cl);
                        break;

                    case 0xA040:
                        l_chunk_id     = l_file.ReadUInt16();
                        l_chunk_lenght = l_file.ReadUInt32();

                        per = (l_file.ReadUInt16()) / 255.0f;

                        shininess.Add(l_mat_name, (float)per);
                        break;

                    case 0xA041:
                        l_chunk_id     = l_file.ReadUInt16();
                        l_chunk_lenght = l_file.ReadUInt32();

                        per = (l_file.ReadUInt16()) / 255.0f;

                        shininessST.Add(l_mat_name, (float)per);
                        break;

                    //----------- Skip unknow chunks ------------
                    //We need to skip all the chunks that currently we don't use
                    //We use the chunk lenght information to set the file pointer
                    //to the same level next chunk
                    //-------------------------------------------
                    default:
                        l_file.BaseStream.Seek(l_chunk_lenght - 6, SeekOrigin.Current);
                        break;
                    }
                }
                catch (EndOfStreamException e)
                {
                    l_end = true;
                }
            }
        }
        return(1);                  // Returns ok
    }