コード例 #1
0
ファイル: Plane.hpp プロジェクト: KasumiL5x/hadan
	static Plane constructFromPointNormal( const cc::Vec3f& point, const cc::Vec3f& normal ) {
		Plane result;
		const cc::Vec3f normalizedNormal = normal.normalized();
		result.normal = normalizedNormal;
		result.constant = -point.dot(normalizedNormal);
		return result;
	}
コード例 #2
0
ファイル: Plane.cpp プロジェクト: MarkSkyzoid/ciri
	Plane::Plane( const cc::Vec3f& a, const cc::Vec3f& b, const cc::Vec3f& c ) {
		const cc::Vec3f ab = b - a;
		const cc::Vec3f ac = c - a;
		const cc::Vec3f cross = ab.cross(ac);
		_normal = cross.normalized();
		_d = -_normal.dot(a);
	}
コード例 #3
0
ファイル: OpenCloth.cpp プロジェクト: KasumiL5x/ciri
void OpenCloth::computeForces( float deltaTime ) {
	for( int i = 0; i < _totalPoints; ++i ) {
		_forces[i].x = _forces[i].y = _forces[i].z = 0.0f;
		const cc::Vec3f velocity = getVerletVelocity(_positions[i], _lastPositions[i], deltaTime);
		if( (i != 0) && (i != _divsX) ) {
			_forces[i] += _gravity * _mass;
		}
		_forces[i] += _damping * velocity;
	}

	for( int i = 0; i < _springCount; ++i ) {
		const cc::Vec3f& p1 = _positions[_springs[i].p1];
		const cc::Vec3f& p1Last = _lastPositions[_springs[i].p1];
		const cc::Vec3f& p2 = _positions[_springs[i].p2];
		const cc::Vec3f& p2Last = _lastPositions[_springs[i].p2];

		const cc::Vec3f v1 = getVerletVelocity(p1, p1Last, deltaTime);
		const cc::Vec3f v2 = getVerletVelocity(p2, p2Last, deltaTime);

		const cc::Vec3f deltaP = p1 - p2;
		const cc::Vec3f deltaV = v1 - v2;
		const float dist = deltaP.magnitude();

		const float leftTerm = -_springs[i].ks * (dist - _springs[i].restLength);
		const float rightTerm = _springs[i].kd * (deltaV.dot(deltaP) / dist);
		const cc::Vec3f springForce = (leftTerm + rightTerm) * deltaP.normalized();

		if( _springs[i].p1 != 0 && _springs[i].p1 != _divsX ) {
			_forces[_springs[i].p1] += springForce;
		}
		if( _springs[i].p2 != 0 && _springs[i].p2 != _divsX ) {
			_forces[_springs[i].p2] -= springForce;
		}
	}
}