~mulder-nebulon/openracing/cleaned

« back to all changes in this revision

Viewing changes to src/ode/OdeSimulator.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:
63
63
//                  mOdeMesh = OdeMesh.FromOBJ(objname); // Reference SHOULD be kept
64
64
                    mOdeMesh = OdeMesh.FromMeshXML(objname);    // Reference SHOULD be kept
65
65
                    Console.Out.WriteLine("OdeSimulator: Create TriMesh Geometry");
 
66
                    
 
67
                    for (int i=0;i<mOdeMesh.SceneObjects.Count;i++)
 
68
                        {
 
69
                            SceneObject sobject = (SceneObject) mOdeMesh.SceneObjects[i];
 
70
                            Console.Out.WriteLine("Generating mesh: {0}", i);
 
71
                            mGroundTriMeshData = Ode.dGeomTriMeshDataCreate();
 
72
                            Ode.dGeomTriMeshDataBuildSimple(mGroundTriMeshData, 
 
73
                                                            sobject.Vertices, 
 
74
                                                            sobject.vertexCount, 
 
75
                                                            sobject.Faces,
 
76
                                                            sobject.faceCount);
 
77
                            mGroundGeom = Ode.dCreateTriMesh(mGroundSpace, mGroundTriMeshData, null, null, null);
 
78
                            Console.Out.WriteLine("     done");
 
79
                            
 
80
                        }
 
81
/*                      
66
82
                    mGroundTriMeshData = Ode.dGeomTriMeshDataCreate();
67
83
                    Console.Out.WriteLine("OdeSimulator: Build TriMesh Geometry");
68
84
                    Ode.dGeomTriMeshDataBuildSimple(mGroundTriMeshData, mOdeMesh.Vertices, mOdeMesh.VertexCount, mOdeMesh.Indices, mOdeMesh.IndexCount);
69
85
                    Console.Out.WriteLine("OdeSimulator: Create TriMesh");
70
86
                    mGroundGeom = Ode.dCreateTriMesh(mGroundSpace, mGroundTriMeshData, null,null,null);
 
87
*/                  
71
88
                }
72
89
            //mGroundGeom = Ode.dCreatePlane(IntPtr.Zero, 0, 1, 0, 1.2345f);
73
90
            CreateRayTrace();
91
108
        // return height of the first polygon point hit by a ray casted down from x,y,z.
92
109
        float RaytraceGroundDown(float x, float y, float z) 
93
110
        {
94
 
            return 0.0f; // IMRE: for now we do not use ODE
95
 
                        // TODO: use ODE instead of Ogre mesh
96
 
            
97
 
            if (x<=0 || z<=0 || y<=0) return 1.0f;
 
111
//          return 0.0f; // IMRE: for now we do not use ODE
 
112
//          TODO: use ODE instead of Ogre mesh
 
113
//          if (x<=0 || z<=0 || y<=0) return 1.0f;
98
114
            float ret = 0.0f;
99
115
 
100
116
            Ode.dGeomRaySet(mHeightRayId, x, z+1, -y, 0,-1,0);
101
117
            int numContacts = Ode.dCollide(mHeightRayId,  mGroundGeom, mContacts.Length, mContacts, Marshal.SizeOf(mContacts[0]));
102
 
            if (numContacts < 1) {
103
 
                // Console.Out.WriteLine("ODE-RAYCAST ERROR {0} {1} {2} {3}", x,y,z,Marshal.SizeOf(mContacts[0]));
104
 
                ret = mOdeMesh.RaytraceDown(x,z,-y);
105
 
            }
106
 
            else {
107
 
                // Console.Out.WriteLine("ODE-SOURCE : {0} {1} {2}", x, z, -y);
108
 
                // Console.Out.WriteLine("ODE-HIT    : {0} {1} {2}", mContacts[0].pos.X, mContacts[0].pos.Y, mContacts[0].pos.Z);
109
 
                ret = mContacts[0].pos.Y;
110
 
            }
111
 
 
112
 
            //Console.Out.WriteLine("RAYCAST({0}, {1}, {2}) = {3}", x,y,z,ret);
113
 
            //Console.Out.WriteLine();
 
118
            if (numContacts < 1) 
 
119
                {
 
120
                    Console.Out.WriteLine("ODE-RAYCAST ERROR {0} {1} {2} {3}", x,y,z,Marshal.SizeOf(mContacts[0]));
 
121
                    // ret = mOdeMesh.RaytraceDown(x,z,-y);
 
122
                    ret = 0.0f;
 
123
                }
 
124
            else 
 
125
                {
 
126
                    Console.Out.WriteLine("ODE-SOURCE : {0} {1} {2}                             {3}             {4} {5} {6}", x, z, -y, mContacts[0].pos.Y, mContacts[0].normal.X,   mContacts[0].normal.Y,  mContacts[0].normal.Z );
 
127
//                    Console.Out.WriteLine("ODE-HIT    : {0} {1} {2}", mContacts[0].pos.X, mContacts[0].pos.Y, mContacts[0].pos.Z);
 
128
                    ret = mContacts[0].pos.Y;
 
129
                }
114
130
            if (ret < 1.0f) ret = 1.0f;
115
131
            return ret;
116
132
        }