third person character update

This commit is contained in:
Turanszki Janos
2020-04-19 22:22:50 +01:00
parent 4cbe366ac9
commit c2d639a2fc
4 changed files with 13 additions and 12 deletions
+7 -6
View File
@@ -2735,7 +2735,7 @@ namespace wiScene
{
SceneIntersectSphereResult result;
XMVECTOR vCenter = XMLoadFloat3(&sphere.center);
XMVECTOR vRadius = XMVectorReplicatePtr(&sphere.radius);
XMVECTOR vRadius = XMVectorReplicate(sphere.radius);
XMVECTOR RadiusSq = XMVectorMultiply(vRadius, vRadius);
if (scene.objects.GetCount() > 0)
@@ -2822,10 +2822,10 @@ namespace wiScene
// Find the nearest feature on the triangle to the sphere.
XMVECTOR Dist = XMVector3Dot(XMVectorSubtract(vCenter, p0), N);
if (XMVectorGetX(Dist) > 0)
{
continue;
}
//if (XMVectorGetX(Dist) > 0)
//{
// continue;
//}
// If the center of the sphere is farther from the plane of the triangle than
// the radius of the sphere, then there cannot be an intersection.
@@ -2890,12 +2890,13 @@ namespace wiScene
bool intersects = XMVector4EqualInt(XMVectorAndCInt(Intersection, NoIntersection), XMVectorTrueInt());
if (intersects && bestDist < result.distance_to_polygon)
if (intersects)
{
result.entity = entity;
result.depth = sphere.radius - XMVectorGetX(XMVector3Length(vCenter - bestPoint));
XMStoreFloat3(&result.position, bestPoint);
XMStoreFloat3(&result.normal, XMVector3Normalize(vCenter - bestPoint));
return result;
}
}
subsetCounter++;
-1
View File
@@ -1360,7 +1360,6 @@ namespace wiScene
XMFLOAT3 position = XMFLOAT3(0, 0, 0);
XMFLOAT3 normal = XMFLOAT3(0, 0, 0);
float depth = 0;
float distance_to_polygon = FLT_MAX;
};
SceneIntersectSphereResult SceneIntersectSphere(const SPHERE& sphere, uint32_t renderTypeMask = RENDERTYPE_OPAQUE, uint32_t layerMask = ~0, const Scene& scene = GetScene());
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wiVersion
// minor features, major updates
const int minor = 39;
// minor bug fixes, alterations, refactors, updates
const int revision = 72;
const int revision = 73;
long GetVersion()
+5 -4
View File
@@ -194,14 +194,15 @@ Character = {
self.state_prev = self.state
-- gravity:
self.force = vector.Add(self.force, Vector(0,-9.8 * 10,0))
self.force = vector.Add(self.force, Vector(0,-9.8 * 20,0))
-- apply force:
self.velocity = vector.Add(self.velocity, vector.Multiply(self.force, 0.016))
self.force = Vector(0,0,0,0)
-- Sphere collider for character:
local sphere = Sphere(vector.Add(model_transform.GetPosition(), Vector(0,1.1)), 1)
local radius = 0.7
local sphere = Sphere(vector.Add(model_transform.GetPosition(), Vector(0,radius)), radius)
local pp = sphere.GetCenter()
local intersection = false
local ccd = 0
@@ -225,13 +226,13 @@ Character = {
self.velocity = vector.Multiply(desiredMotion, velocityLen)
intersection = true
sphere.SetCenter(prevpos)
sphere.SetCenter(vector.Add(sphere.GetCenter(), vector.Multiply(n2, depth))) -- remove penetration
end
end
--DrawPoint(sphere.GetCenter(), 0.5, Vector(0,1,0,1))
if intersection then
self.velocity = vector.Multiply(self.velocity, 0.8) -- ground friction
self.velocity = vector.Multiply(self.velocity, 0.87) -- ground friction
else
self.velocity = vector.Multiply(self.velocity, 0.94) -- air friction
end