~mulder-nebulon/openracing/cleaned

« back to all changes in this revision

Viewing changes to src/ode/OdeMesh.cs

  • Committer: Nagy Imre
  • Date: 2009-04-03 13:07:42 UTC
  • Revision ID: mulder@codenode-20090403130742-q70y336xbuzzx63a
ODS-ODE raycast working! (although safety blocks are in)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
using System.IO;
3
3
using Tao.Ode;
4
4
using System.Xml;
 
5
using System.Collections;
5
6
 
6
7
namespace Torcs
7
8
{
11
12
        private int[] indices;
12
13
        private int indexCount;
13
14
 
14
 
        public Ode.dVector3[] Vertices { get { return vertices; } }
15
 
        public int VertexCount { get { return vertexCount; } }
16
 
        public int[] Indices { get { return indices; } }
17
 
        public int IndexCount { get { return indexCount; } }
 
15
//        public Ode.dVector3[] Vertices { get { return vertices; } }
 
16
//        public int VertexCount { get { return vertexCount; } }
 
17
//        public int[] Indices { get { return indices; } }
 
18
//        public int IndexCount { get { return indexCount; } }
 
19
        public ArrayList SceneObjects;
18
20
 
19
 
        OdeMesh() {}
 
21
        OdeMesh() 
 
22
            {
 
23
                SceneObjects = new ArrayList();
 
24
            }
20
25
 
21
26
        static public OdeMesh FromOBJ(String filename) 
22
27
        {
49
54
                    {
50
55
                        if (reader.NodeType==XmlNodeType.Element)
51
56
                            {
52
 
                                Console.Out.WriteLine("TAGNAME: "+reader.Name);
 
57
//                              Console.Out.WriteLine("TAGNAME: "+reader.Name);
53
58
                                if (reader.Name=="submesh")
54
59
                                    {
55
60
                                        reader.MoveToContent();
56
61
                                        material                = reader.GetAttribute("material");
57
62
                                        useSharedVertices       = reader.GetAttribute("usesharedvertices");
58
63
                                        sobject                 = new SceneObject();
 
64
                                        SceneObjects.Add(sobject);
59
65
                                        fcount                  = 0;
60
66
                                        vcount                  = 0;
61
67
                                    }
62
68
                                else if (reader.Name=="faces")
63
69
                                    {
64
 
                                        sobject.faceCount = Convert.ToInt32(reader.GetAttribute("count"));
 
70
                                        sobject.setFacesCount(Convert.ToInt32(reader.GetAttribute("count")));
65
71
                                        Console.Out.WriteLine(" # of allocated faces: " +sobject.faceCount);
66
 
                                        sobject.faces     = new Face[sobject.faceCount];
67
 
                                        for (int i=0;i<sobject.faceCount;i++) sobject.faces[i] = new Face();
68
 
                                        // allocate face array here
69
72
                                    }
70
73
                                else if (reader.Name=="face")
71
74
                                    {
72
 
                                        if (fcount<sobject.faceCount-1)
73
 
                                            {
74
 
                                                sobject.faces[fcount].iv1 = Convert.ToInt32(reader.GetAttribute("v1"));
75
 
                                                sobject.faces[fcount].iv2 = Convert.ToInt32(reader.GetAttribute("v2"));;
76
 
                                                sobject.faces[fcount].iv3 = Convert.ToInt32(reader.GetAttribute("v3"));;
77
 
                                                fcount++;
78
 
                                            }
 
75
                                        sobject.Faces[fcount] = Convert.ToInt32(reader.GetAttribute("v1")); fcount++;
 
76
                                        sobject.Faces[fcount] = Convert.ToInt32(reader.GetAttribute("v2")); fcount++;
 
77
                                        sobject.Faces[fcount] = Convert.ToInt32(reader.GetAttribute("v3")); fcount++;
 
78
                                        
79
79
                                    }
80
80
                                else if (reader.Name=="geometry")
81
81
                                    {
82
 
                                        sobject.vertexCount = Convert.ToInt32(reader.GetAttribute("vertexcount"));
83
 
                                        sobject.vertex = new Math3D.Vector3[sobject.vertexCount];
 
82
                                        sobject.setVerticesCount(Convert.ToInt32(reader.GetAttribute("vertexcount")));
84
83
                                        Console.Out.WriteLine(" # of allocated vertices: " +sobject.vertexCount);
85
 
                                        for (int i=0;i<sobject.vertexCount;i++) sobject.vertex[i] = new Math3D.Vector3();
86
84
                                    }
87
85
                                else if (reader.Name=="vertexbuffer")
88
86
                                    {
92
90
                                    }
93
91
                                else if (reader.Name=="position")
94
92
                                    {
95
 
                                        if (vcount<sobject.vertexCount-1)
96
 
                                            {
97
 
                                                sobject.vertex[vcount].x = Convert.ToSingle(reader.GetAttribute("x"));
98
 
                                                sobject.vertex[vcount].y = Convert.ToSingle(reader.GetAttribute("y"));
99
 
                                                sobject.vertex[vcount].z = Convert.ToSingle(reader.GetAttribute("z"));
100
 
                                                vcount++;
101
 
                                            }
 
93
                                        sobject.Vertices[vcount].X = Convert.ToSingle(reader.GetAttribute("x"));
 
94
                                        sobject.Vertices[vcount].Y = Convert.ToSingle(reader.GetAttribute("y"));
 
95
                                        sobject.Vertices[vcount].Z = Convert.ToSingle(reader.GetAttribute("z"));
 
96
                                        vcount++;
102
97
                                    }
103
98
                                else if (reader.Name=="normal")
104
99
                                    {