consistency
This commit is contained in:
		| @@ -39,12 +39,17 @@ public: | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	bool IsDragging() const | ||||
| 	{ | ||||
| 		return m_shape != nullptr; | ||||
| 	} | ||||
|  | ||||
| 	bool StartDragging() | ||||
| 	{ | ||||
| 		B3_ASSERT(m_mouseJoint == nullptr); | ||||
|  | ||||
| 		b3RayCastSingleOutput out; | ||||
| 		if (m_world->RayCastSingle(&out, m_ray->A(), m_ray->B()) == false) | ||||
| 		b3ShapeRayCastSingleOutput out; | ||||
| 		if (m_world->RayCastSingleShape(&out, m_ray->A(), m_ray->B()) == false) | ||||
| 		{ | ||||
| 			return false; | ||||
| 		} | ||||
| @@ -88,12 +93,6 @@ public: | ||||
| 		m_shape = nullptr; | ||||
| 	} | ||||
|  | ||||
| 	bool IsSelected() const | ||||
| 	{ | ||||
| 		return m_mouseJoint != nullptr; | ||||
| 	} | ||||
|  | ||||
|  | ||||
| 	b3Ray3* GetRay() const | ||||
| 	{ | ||||
| 		return m_ray; | ||||
|   | ||||
| @@ -21,18 +21,21 @@ | ||||
|  | ||||
| #include <bounce/collision/collision.h> | ||||
| #include <bounce/dynamics/cloth/cloth.h> | ||||
| #include <bounce/dynamics/cloth/cloth_mesh.h> | ||||
| #include <bounce/dynamics/cloth/particle.h> | ||||
| #include <bounce/dynamics/cloth/spring_force.h> | ||||
| #include <bounce/dynamics/cloth/cloth_mesh.h> | ||||
| #include <bounce/dynamics/world.h> | ||||
|  | ||||
| // A cloth triangle dragger. | ||||
| class b3ClothDragger | ||||
| { | ||||
| public: | ||||
| 	b3ClothDragger(b3Ray3* ray, b3Cloth*& cloth) : m_ray(ray), m_cloth(cloth) | ||||
| 	b3ClothDragger(b3Ray3* ray, b3World* world)  | ||||
| 	{ | ||||
| 		m_isSelected = false; | ||||
| 		m_spring = false; | ||||
| 		m_ray = ray; | ||||
| 		m_world = world; | ||||
| 		m_cloth = nullptr; | ||||
| 	} | ||||
|  | ||||
| 	~b3ClothDragger() | ||||
| @@ -40,57 +43,29 @@ public: | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	bool IsSelected() const | ||||
| 	bool IsDragging() const | ||||
| 	{ | ||||
| 		return m_isSelected; | ||||
| 	} | ||||
|  | ||||
| 	b3Vec3 GetPointA() const | ||||
| 	{ | ||||
| 		B3_ASSERT(m_isSelected); | ||||
|  | ||||
| 		b3ClothMesh* m = m_cloth->GetMesh(); | ||||
| 		b3ClothMeshTriangle* t = m->triangles + m_selection; | ||||
|  | ||||
| 		b3Vec3 A = m->vertices[t->v1]; | ||||
| 		b3Vec3 B = m->vertices[t->v2]; | ||||
| 		b3Vec3 C = m->vertices[t->v3]; | ||||
|  | ||||
| 		return m_u * A + m_v * B + (1.0f - m_u - m_v) * C; | ||||
| 	} | ||||
|  | ||||
| 	b3Vec3 GetPointB() const | ||||
| 	{ | ||||
| 		B3_ASSERT(m_isSelected); | ||||
| 		return (1.0f - m_x) * m_ray->A() + m_x * m_ray->B(); | ||||
| 		return m_cloth != nullptr; | ||||
| 	} | ||||
|  | ||||
| 	bool StartDragging() | ||||
| 	{ | ||||
| 		B3_ASSERT(m_isSelected == false); | ||||
| 		B3_ASSERT(IsDragging() == false); | ||||
|  | ||||
| 		b3RayCastInput rayIn; | ||||
| 		rayIn.p1 = m_ray->A(); | ||||
| 		rayIn.p2 = m_ray->B(); | ||||
| 		rayIn.maxFraction = B3_MAX_FLOAT; | ||||
|  | ||||
| 		b3ClothRayCastOutput rayOut; | ||||
| 		if (m_cloth->RayCast(&rayOut, &rayIn) == false) | ||||
| 		b3ClothRayCastSingleOutput rayOut; | ||||
| 		if (m_world->RayCastSingleCloth(&rayOut, m_ray->A(), m_ray->B()) == false) | ||||
| 		{ | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		m_isSelected = true; | ||||
|  | ||||
| 		m_selection = rayOut.triangle; | ||||
| 		m_cloth = rayOut.cloth; | ||||
| 		m_mesh = m_cloth->GetMesh(); | ||||
| 		m_triangle = m_mesh->triangles + rayOut.triangle; | ||||
| 		m_x = rayOut.fraction; | ||||
|  | ||||
| 		b3ClothMesh* m = m_cloth->GetMesh(); | ||||
| 		b3ClothMeshTriangle* t = m->triangles + m_selection; | ||||
|  | ||||
| 		b3Particle* p1 = m->particles[t->v1]; | ||||
| 		b3Particle* p2 = m->particles[t->v2]; | ||||
| 		b3Particle* p3 = m->particles[t->v3]; | ||||
| 		b3Particle* p1 = m_mesh->particles[m_triangle->v1]; | ||||
| 		b3Particle* p2 = m_mesh->particles[m_triangle->v2]; | ||||
| 		b3Particle* p3 = m_mesh->particles[m_triangle->v3]; | ||||
|  | ||||
| 		b3Vec3 v1 = p1->GetPosition(); | ||||
| 		b3Vec3 v2 = p2->GetPosition(); | ||||
| @@ -163,10 +138,7 @@ public: | ||||
|  | ||||
| 	void Drag() | ||||
| 	{ | ||||
| 		B3_ASSERT(m_isSelected); | ||||
|  | ||||
| 		b3ClothMesh* m = m_cloth->GetMesh(); | ||||
| 		b3ClothMeshTriangle* t = m->triangles + m_selection; | ||||
| 		B3_ASSERT(IsDragging() == true); | ||||
|  | ||||
| 		b3Vec3 A = GetPointA(); | ||||
| 		b3Vec3 B = GetPointB(); | ||||
| @@ -179,22 +151,22 @@ public: | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			b3Particle* p1 = m->particles[t->v1]; | ||||
| 			b3Particle* p1 = m_mesh->particles[m_triangle->v1]; | ||||
| 			p1->ApplyTranslation(dx); | ||||
|  | ||||
| 			b3Particle* p2 = m->particles[t->v2]; | ||||
| 			b3Particle* p2 = m_mesh->particles[m_triangle->v2]; | ||||
| 			p2->ApplyTranslation(dx); | ||||
|  | ||||
| 			b3Particle* p3 = m->particles[t->v3]; | ||||
| 			b3Particle* p3 = m_mesh->particles[m_triangle->v3]; | ||||
| 			p3->ApplyTranslation(dx); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	void StopDragging() | ||||
| 	{ | ||||
| 		B3_ASSERT(m_isSelected); | ||||
| 		B3_ASSERT(IsDragging() == true); | ||||
|  | ||||
| 		m_isSelected = false; | ||||
| 		m_cloth = nullptr; | ||||
|  | ||||
| 		if (m_spring) | ||||
| 		{ | ||||
| @@ -205,28 +177,42 @@ public: | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			b3ClothMesh* m = m_cloth->GetMesh(); | ||||
| 			b3ClothMeshTriangle* t = m->triangles + m_selection; | ||||
|  | ||||
| 			b3Particle* p1 = m->particles[t->v1]; | ||||
| 			b3Particle* p1 = m_mesh->particles[m_triangle->v1]; | ||||
| 			p1->SetType(m_t1); | ||||
|  | ||||
| 			b3Particle* p2 = m->particles[t->v2]; | ||||
| 			b3Particle* p2 = m_mesh->particles[m_triangle->v2]; | ||||
| 			p2->SetType(m_t2); | ||||
|  | ||||
| 			b3Particle* p3 = m->particles[t->v3]; | ||||
| 			b3Particle* p3 = m_mesh->particles[m_triangle->v3]; | ||||
| 			p3->SetType(m_t3); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| private: | ||||
| 	bool m_isSelected; | ||||
| 	b3Vec3 GetPointA() const | ||||
| 	{ | ||||
| 		B3_ASSERT(IsDragging() == true); | ||||
| 		 | ||||
| 		b3Vec3 A = m_mesh->vertices[m_triangle->v1]; | ||||
| 		b3Vec3 B = m_mesh->vertices[m_triangle->v2]; | ||||
| 		b3Vec3 C = m_mesh->vertices[m_triangle->v3]; | ||||
|  | ||||
| 		return m_u * A + m_v * B + (1.0f - m_u - m_v) * C; | ||||
| 	} | ||||
|  | ||||
| 	b3Vec3 GetPointB() const | ||||
| 	{ | ||||
| 		B3_ASSERT(IsDragging() == true); | ||||
| 		 | ||||
| 		return (1.0f - m_x) * m_ray->A() + m_x * m_ray->B(); | ||||
| 	} | ||||
| private: | ||||
| 	b3Ray3* m_ray; | ||||
| 	float32 m_x; | ||||
|  | ||||
| 	b3Cloth*& m_cloth; | ||||
| 	u32 m_selection; | ||||
| 	b3World* m_world; | ||||
| 	b3Cloth* m_cloth; | ||||
| 	b3ClothMesh* m_mesh; | ||||
| 	b3ClothMeshTriangle* m_triangle; | ||||
| 	float32 m_u, m_v; | ||||
|  | ||||
| 	bool m_spring; | ||||
|   | ||||
| @@ -34,15 +34,10 @@ struct b3ForceDef; | ||||
|  | ||||
| struct b3ClothMesh; | ||||
|  | ||||
| struct b3RayCastInput; | ||||
| class b3RayCastListener; | ||||
|  | ||||
| struct b3ClothRayCastOutput | ||||
| { | ||||
| 	u32 triangle; // intersected triangle | ||||
| 	b3Vec3 point; // intersection point on surface | ||||
| 	b3Vec3 normal; // surface normal of intersection | ||||
| 	float32 fraction; // time of intersection on segment | ||||
| }; | ||||
| struct b3RayCastInput; | ||||
| struct b3ClothRayCastSingleOutput; | ||||
|  | ||||
| // Cloth definition | ||||
| // This requires defining a cloth mesh which is typically bound to a render mesh | ||||
| @@ -94,11 +89,14 @@ public: | ||||
| 	// Destroy a given force. | ||||
| 	void DestroyForce(b3Force* force); | ||||
|  | ||||
| 	// Perform a ray cast with the cloth. | ||||
| 	bool RayCast(b3ClothRayCastOutput* output, const b3RayCastInput* input) const; | ||||
|  | ||||
| 	// Perform a ray cast with a given cloth mesh triangle. | ||||
| 	bool RayCast(b3ClothRayCastOutput* output, const b3RayCastInput* input, u32 triangleIndex) const; | ||||
| 	bool RayCast(b3ClothRayCastSingleOutput* output, const b3RayCastInput* input, u32 triangleIndex) const; | ||||
|  | ||||
| 	// Perform a ray cast with the cloth. | ||||
| 	void RayCast(b3RayCastListener* listener, const b3RayCastInput* input) const; | ||||
|  | ||||
| 	// Perform a ray cast with the cloth. | ||||
| 	bool RayCastSingle(b3ClothRayCastSingleOutput* output, const b3Vec3& p1, const b3Vec3& p2) const; | ||||
|  | ||||
| 	// Return the cloth mesh proxy. | ||||
| 	b3ClothMesh* GetMesh() const; | ||||
|   | ||||
| @@ -36,7 +36,7 @@ class b3RayCastListener; | ||||
| class b3ContactListener; | ||||
| class b3ContactFilter; | ||||
|  | ||||
| struct b3RayCastSingleOutput | ||||
| struct b3ShapeRayCastSingleOutput | ||||
| { | ||||
| 	b3Shape* shape; // shape | ||||
| 	b3Vec3 point; // intersection point on surface | ||||
| @@ -44,6 +44,15 @@ struct b3RayCastSingleOutput | ||||
| 	float32 fraction; // time of intersection on segment | ||||
| }; | ||||
|  | ||||
| struct b3ClothRayCastSingleOutput | ||||
| { | ||||
| 	b3Cloth* cloth; // cloth | ||||
| 	u32 triangle; // triangle | ||||
| 	b3Vec3 point; // intersection point on surface | ||||
| 	b3Vec3 normal; // surface normal of intersection | ||||
| 	float32 fraction; // time of intersection on segment | ||||
| }; | ||||
|  | ||||
| // Use a physics world to create/destroy rigid bodies, execute ray cast and volume queries. | ||||
| class b3World | ||||
| { | ||||
| @@ -92,13 +101,6 @@ public: | ||||
| 	// The function parameters are the ammount of time to simulate,  | ||||
| 	// and the number of constraint solver iterations. | ||||
| 	void Step(float32 dt, u32 velocityIterations, u32 positionIterations); | ||||
| 	 | ||||
| 	// Perform a ray cast with the world. | ||||
| 	// If the ray doesn't intersect with a shape in the world then return false. | ||||
| 	// The ray cast output is the intercepted shape, the intersection  | ||||
| 	// point in world space, the face normal on the shape associated with the point,  | ||||
| 	// and the intersection fraction. | ||||
| 	bool RayCastSingle(b3RayCastSingleOutput* output, const b3Vec3& p1, const b3Vec3& p2) const; | ||||
|  | ||||
| 	// Perform a ray cast with the world. | ||||
| 	// The given ray cast listener will be notified when a ray intersects a shape  | ||||
| @@ -106,7 +108,29 @@ public: | ||||
| 	// The ray cast output is the intercepted shape, the intersection  | ||||
| 	// point in world space, the face normal on the shape associated with the point,  | ||||
| 	// and the intersection fraction. | ||||
| 	void RayCast(b3RayCastListener* listener, const b3Vec3& p1, const b3Vec3& p2) const; | ||||
| 	void RayCastShape(b3RayCastListener* listener, const b3Vec3& p1, const b3Vec3& p2) const; | ||||
|  | ||||
| 	// Perform a ray cast with the world. | ||||
| 	// If the ray doesn't intersect with a shape in the world then return false. | ||||
| 	// The ray cast output is the intercepted shape, the intersection  | ||||
| 	// point in world space, the face normal on the shape associated with the point,  | ||||
| 	// and the intersection fraction. | ||||
| 	bool RayCastSingleShape(b3ShapeRayCastSingleOutput* output, const b3Vec3& p1, const b3Vec3& p2) const; | ||||
|  | ||||
| 	// Perform a ray cast with the world. | ||||
| 	// The given ray cast listener will be notified when a ray intersects a shape  | ||||
| 	// in the world.  | ||||
| 	// The ray cast output is the intercepted cloth, the intersection  | ||||
| 	// point in world space, the face normal on the cloth associated with the point,  | ||||
| 	// and the intersection fraction. | ||||
| 	void RayCastCloth(b3RayCastListener* listener, const b3Vec3& p1, const b3Vec3& p2) const; | ||||
|  | ||||
| 	// Perform a ray cast with the world. | ||||
| 	// If the ray doesn't intersect with a cloth in the world then return false. | ||||
| 	// The ray cast output is the intercepted cloth, the intersection  | ||||
| 	// point in world space, the face normal on the cloth associated with the point,  | ||||
| 	// and the intersection fraction. | ||||
| 	bool RayCastSingleCloth(b3ClothRayCastSingleOutput* output, const b3Vec3& p1, const b3Vec3& p2) const; | ||||
|  | ||||
| 	// Perform a AABB query with the world. | ||||
| 	// The query listener will be notified when two shape AABBs are overlapping. | ||||
|   | ||||
| @@ -22,6 +22,7 @@ | ||||
| #include <bounce/common/math/math.h> | ||||
|  | ||||
| class b3Shape; | ||||
| class b3Cloth; | ||||
| class b3Contact; | ||||
|  | ||||
| class b3QueryListener  | ||||
| @@ -46,6 +47,12 @@ public: | ||||
| 	// the intersection point on the shape, the surface normal associated with the point, and the  | ||||
| 	// intersection fraction for the ray. | ||||
| 	virtual float32 ReportShape(b3Shape* shape, const b3Vec3& point, const b3Vec3& normal, float32 fraction) = 0; | ||||
|  | ||||
| 	// Report that a cloth was hit by the ray to this contact listener. | ||||
| 	// The reported information are the shape hit by the ray, | ||||
| 	// the intersection point on the cloth, the surface normal associated with the point, the  | ||||
| 	// intersection fraction for the ray, and the triangle. | ||||
| 	virtual float32 ReportCloth(b3Cloth* cloth, const b3Vec3& point, const b3Vec3& normal, float32 fraction, u32 triangle) = 0; | ||||
| }; | ||||
|  | ||||
| class b3ContactListener  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user