[Scummvm-git-logs] scummvm master -> d0edb79a101427c57689dc84eb3875aed0eed29e

peterkohaut peterkohaut at users.noreply.github.com
Thu Apr 18 22:15:27 CEST 2019


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
d0edb79a10 BLADERUNNER: Clarification of some math


Commit: d0edb79a101427c57689dc84eb3875aed0eed29e
    https://github.com/scummvm/scummvm/commit/d0edb79a101427c57689dc84eb3875aed0eed29e
Author: Peter Kohaut (peter.kohaut at gmail.com)
Date: 2019-04-18T22:14:43+02:00

Commit Message:
BLADERUNNER: Clarification of some math

Changed paths:
    engines/bladerunner/fog.cpp


diff --git a/engines/bladerunner/fog.cpp b/engines/bladerunner/fog.cpp
index 4856f1d..e6b6037 100644
--- a/engines/bladerunner/fog.cpp
+++ b/engines/bladerunner/fog.cpp
@@ -123,18 +123,25 @@ void FogSphere::read(Common::ReadStream *stream, int frameCount) {
 void FogSphere::calculateCoeficient(Vector3 position, Vector3 viewPosition, float *coeficient) {
 	*coeficient = 0.0f;
 
-	// ray - sphere intersection, where sphere center is always at 0, 0, 0 as everything else tranformed by the fog matrix
+	// Ray - sphere intersection, where sphere center is always at 0, 0, 0 as everything else tranformed by the fog matrix.
+	// Quadratic formula can and was simplified becasue rayDirection is normalized and hence a = 1.
+	// Explained on wikipedia https://en.wikipedia.org/wiki/Line%E2%80%93sphere_intersection
+
+	// There is also alternative approach which will end-up with this formula where plane is created from ray origin, ray destination
+	// and sphere center, then there is only need to solve two right triangles.
+	// Explained in book Andrew S. Glassner (1995), Graphics Gems I (p. 388-389)
+
 	Vector3 rayOrigin = _matrix * position;
 	Vector3 rayDestination = _matrix * viewPosition;
 	Vector3 rayDirection = (rayDestination - rayOrigin).normalize();
 
 	float b = Vector3::dot(rayDirection, rayOrigin);
 	float c = Vector3::dot(rayOrigin, rayOrigin) - (_radius * _radius);
-	float t = b * b - c;
+	float d = b * b - c;
 
-	if (t >= 0.0f) { // there is an interstection between ray and the sphere
-		Vector3 intersection1 = rayOrigin + (-b - sqrt(t)) * rayDirection;
-		Vector3 intersection2 = rayOrigin + (-b + sqrt(t)) * rayDirection;
+	if (d >= 0.0f) { // there is an interstection between ray and the sphere
+		Vector3 intersection1 = rayOrigin + (-b - sqrt(d)) * rayDirection;
+		Vector3 intersection2 = rayOrigin + (-b + sqrt(d)) * rayDirection;
 
 		Vector3 intersection1World = _inverted * intersection1;
 		Vector3 intersection2World = _inverted * intersection2;





More information about the Scummvm-git-logs mailing list