[Papervision3D] Problem and Solution with Dragging in 3D - The Right Way

Patrick Juchli patrick at lessrain.com
Mon Nov 3 18:44:06 PST 2008


Sorry, some correction of the code, removing the "segment" stuff.  
Please note, that this method is using a starting point and a  
direction (vector) to describe the line, not two points.


		public static function intersectLinePlane(lineStart:Number3D,  
lineDirection:Number3D, planePosition:Number3D, planeNormal:Number3D,  
result:Number3D):Number {
			
			var w:Number3D = Number3D.sub(lineStart, planePosition);
			var d:Number = Number3D.dot(planeNormal, lineDirection);
			var n:Number = -Number3D.dot(planeNormal, w);
			
			if (Math.abs(d) < 0.0000001) return 0;	
			
			var sI:Number = n / d;
			
			result.x = lineStart.x + (lineDirection.x * sI);
			result.y = lineStart.y + (lineDirection.y * sI);
			result.z = lineStart.z + (lineDirection.z * sI);

			return 1;	
		}		




On 04.11.2008, at 11:28, Patrick Juchli wrote:

>
> Hi Papervision
>
> I was following this (http://blog.zupko.info/?p=143) Tutorial by  
> Andy and had a problem. When I used the same plane normal as in the  
> example everything worked fine. But as soon as this normal became a  
> little bit less simple the provided method to intersect a line with  
> a plane didn't give the correct result.
>
> Instead of the plane normal (0, 1, 0) I used a plane which is always  
> perpendicular to the viewing direction by using this: (target.x -  
> camera.x, target.y - camera.y, target.z - camera.z) and normalizing  
> it.
>
> I didn't get the correct intersection and I wanted to know if I am  
> maybe doing something wrong or if anybody has had similar issues.
>
> Anyway, it works now using a different method for getting the  
> intersection of line and plane. I rewrote my method using Number3D,  
> hope it works, didn't test the translation :)
>
> Hope it helps
> Cheers
> patrick
>
>
> public static function intersectLinePlane(lineStart:Number3D,  
> lineDirection:Number3D, planePosition:Number3D,  
> planeNormal:Number3D, result:Number3D):Number {
> 			
> 			var w:Number3D = Number3D.sub(lineStart, planePosition);
> 			var d:Number = Number3D.dot(planeNormal, lineDirection);
> 			var n:Number = -Number3D.dot(planeNormal, w);
> 			
> 			if (Math.abs(d) < 0.0000001) {
> 				if (n == 0) return 2;			// segment is parallel to plane
> 				else return 0;					// segment lies in plane	
> 			}
> 			
> 			var sI:Number = n / d;
> 			
> 			result.x = lineStart.x + (lineDirection.x * sI);
> 			result.y = lineStart.y + (lineDirection.y * sI);
> 			result.z = lineStart.z + (lineDirection.z * sI);
>
> 			return 1;
> 			
> 		}		
>
>
>
>
>
>
> --
> Less Rain
> 201B IID
> 2-4-5 Ikejiri Setagaya-ku
> 154-0001 Tokyo / Japan
>
> T  03 6277 3340/41
> F  03 6277 3342
>
> www.lessrain.co.jp
>
>
>
>

--
Less Rain
201B IID
2-4-5 Ikejiri Setagaya-ku
154-0001 Tokyo / Japan

T  03 6277 3340/41
F  03 6277 3342

www.lessrain.co.jp







More information about the Papervision3D mailing list