public RopeTest() { const int N = 40; Vec2[] vertices = new Vec2[N]; float [] masses = new float [N]; for (int i = 0; i < N; ++i) { vertices[i].Set(0.0f, 20.0f - 0.25f * i); masses[i] = 1.0f; } masses[0] = 0.0f; masses[1] = 0.0f; RopeDef def = new RopeDef(); def.vertices = new List<Vec2>(vertices); def.count = N; def.gravity.Set(0.0f, -10.0f); def.masses = new List<float>(masses); def.damping = 0.1f; def.k2 = 1.0f; def.k3 = 0.5f; m_rope.Initialize(def); m_angle = 0.0f; m_rope.SetAngle(m_angle); }
/// public void Initialize(RopeDef def) { throw new NotImplementedException(); //Utilities.Assert(def.count >= 3); //m_count = def.count; //m_ps = (Vec2*)Alloc(m_count * sizeof(Vec2)); //m_p0s = (Vec2*)Alloc(m_count * sizeof(Vec2)); //m_vs = (Vec2*)Alloc(m_count * sizeof(Vec2)); //m_ims = (float*)Alloc(m_count * sizeof(float)); //for (int i = 0; i < m_count; ++i) //{ // m_ps[i] = def.vertices[i]; // m_p0s[i] = def.vertices[i]; // m_vs[i].SetZero(); // float m = def.masses[i]; // if (m > 0.0f) // { // m_ims[i] = 1.0f / m; // } // else // { // m_ims[i] = 0.0f; // } //} //int count2 = m_count - 1; //int count3 = m_count - 2; //m_Ls = (float*)Alloc(count2 * sizeof(float)); //m_as = (float*)Alloc(count3 * sizeof(float)); //for (int i = 0; i < count2; ++i) //{ // Vec2 p1 = m_ps[i]; // Vec2 p2 = m_ps[i+1]; // m_Ls[i] = Distance(p1, p2); //} //for (int i = 0; i < count3; ++i) //{ // Vec2 p1 = m_ps[i]; // Vec2 p2 = m_ps[i + 1]; // Vec2 p3 = m_ps[i + 2]; // Vec2 d1 = p2 - p1; // Vec2 d2 = p3 - p2; // float a = Utilities.Cross(d1, d2); // float b = Utilities.Dot(d1, d2); // m_as[i] = Atan2(a, b); //} //m_gravity = def.gravity; //m_damping = def.damping; //m_k2 = def.k2; //m_k3 = def.k3; }
/// public void Initialize(RopeDef def){ throw new NotImplementedException(); //Utilities.Assert(def.count >= 3); //m_count = def.count; //m_ps = (Vec2*)Alloc(m_count * sizeof(Vec2)); //m_p0s = (Vec2*)Alloc(m_count * sizeof(Vec2)); //m_vs = (Vec2*)Alloc(m_count * sizeof(Vec2)); //m_ims = (float*)Alloc(m_count * sizeof(float)); //for (int i = 0; i < m_count; ++i) //{ // m_ps[i] = def.vertices[i]; // m_p0s[i] = def.vertices[i]; // m_vs[i].SetZero(); // float m = def.masses[i]; // if (m > 0.0f) // { // m_ims[i] = 1.0f / m; // } // else // { // m_ims[i] = 0.0f; // } //} //int count2 = m_count - 1; //int count3 = m_count - 2; //m_Ls = (float*)Alloc(count2 * sizeof(float)); //m_as = (float*)Alloc(count3 * sizeof(float)); //for (int i = 0; i < count2; ++i) //{ // Vec2 p1 = m_ps[i]; // Vec2 p2 = m_ps[i+1]; // m_Ls[i] = Distance(p1, p2); //} //for (int i = 0; i < count3; ++i) //{ // Vec2 p1 = m_ps[i]; // Vec2 p2 = m_ps[i + 1]; // Vec2 p3 = m_ps[i + 2]; // Vec2 d1 = p2 - p1; // Vec2 d2 = p3 - p2; // float a = Utilities.Cross(d1, d2); // float b = Utilities.Dot(d1, d2); // m_as[i] = Atan2(a, b); //} //m_gravity = def.gravity; //m_damping = def.damping; //m_k2 = def.k2; //m_k3 = def.k3; }