aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
diff options
context:
space:
mode:
authorTeravus Ovares2007-11-23 05:56:35 +0000
committerTeravus Ovares2007-11-23 05:56:35 +0000
commit1ecd803e87119c0344b91798792130155a82859c (patch)
tree74cbd2102051d03acfa78f5763438fd0b0a19778 /OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
parentFixed Terrain rescale command (diff)
downloadopensim-SC_OLD-1ecd803e87119c0344b91798792130155a82859c.zip
opensim-SC_OLD-1ecd803e87119c0344b91798792130155a82859c.tar.gz
opensim-SC_OLD-1ecd803e87119c0344b91798792130155a82859c.tar.bz2
opensim-SC_OLD-1ecd803e87119c0344b91798792130155a82859c.tar.xz
* added some functions for use in raytracing. They're kind of crappy now, so they only display 'guesses' on the console when you rez a prim.
* any math gurus who'd like to improve rezzing need only to make the raytracer in SceneObjectPart work :D
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/SceneObjectPart.cs')
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneObjectPart.cs85
1 files changed, 85 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
index 7bab3b6..e68632b 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
@@ -535,6 +535,91 @@ namespace OpenSim.Region.Environment.Scenes
535 serializer.Serialize(xmlWriter, this); 535 serializer.Serialize(xmlWriter, this);
536 } 536 }
537 537
538 public EntityIntersection testIntersection(Ray iray, Quaternion parentrot)
539 {
540
541 //Sphere dummysphere = new Sphere();
542
543 EntityIntersection returnresult = new EntityIntersection();
544 Vector3 vAbsolutePosition = new Vector3(AbsolutePosition.X, AbsolutePosition.Y, AbsolutePosition.Z);
545 Vector3 vScale = new Vector3(Scale.X, Scale.Y, Scale.Z);
546 Quaternion qRotation = new Quaternion(RotationOffset.W, RotationOffset.X, RotationOffset.Y, RotationOffset.Z);
547
548
549
550 Quaternion worldRotation = (qRotation * parentrot);
551 Matrix3 worldRotM = worldRotation.ToRotationMatrix();
552
553
554
555 Vector3 rOrigin = iray.Origin;
556 Vector3 rDirection = iray.Direction;
557
558
559
560 Vector3 r2ndDirection = rDirection * rDirection;
561
562 float itestPart1 = r2ndDirection.x + r2ndDirection.y + r2ndDirection.z;
563
564 Vector3 tmVal2 = rOrigin - vAbsolutePosition;
565
566 Vector3 r2Direction = rDirection * 2.0f;
567 Vector3 tmVal3 = r2Direction * tmVal2;
568
569 float itestPart2 = tmVal3.x + tmVal3.y + tmVal3.z;
570
571 Vector3 tmVal4 = rOrigin * rOrigin;
572 Vector3 tmVal5 = vAbsolutePosition * vAbsolutePosition;
573
574 Vector3 tmVal6 = vAbsolutePosition * rOrigin;
575
576 float radius = 0f;
577 if (vScale.x > radius)
578 radius = vScale.x;
579 if (vScale.y > radius)
580 radius = vScale.y;
581 if (vScale.z > radius)
582 radius = vScale.z;
583
584 //radius = radius;
585
586 float itestPart3 = tmVal4.x + tmVal4.y + tmVal4.z + tmVal5.x + tmVal5.y + tmVal5.z -(2.0f * (tmVal6.x + tmVal6.y + tmVal6.z + (radius * radius)));
587
588 // Yuk Quadradrics
589 float rootsqr = (itestPart2 * itestPart2) - (4.0f * itestPart1 * itestPart3);
590 if (rootsqr < 0.0f)
591 {
592
593 return returnresult;
594 }
595 float root = ((-itestPart2) - (float)Math.Sqrt((double)rootsqr)) / (itestPart1 * 2.0f);
596
597 if (root < 0.0f)
598 {
599 // perform second quadratic root solution
600 root = ((-itestPart2) + (float)Math.Sqrt((double)rootsqr)) / (itestPart1 * 2.0f);
601
602 // is there any intersection?
603 if (root < 0.0f)
604 {
605
606 return returnresult;
607 }
608 }
609
610 Vector3 ipoint = new Vector3(iray.Origin.x + (iray.Direction.x * root),iray.Origin.y + (iray.Direction.y * root),iray.Origin.z + (iray.Direction.z * root));
611
612 returnresult.HitTF = true;
613 returnresult.ipoint = ipoint;
614 Vector3 normalpart = ipoint-vAbsolutePosition;
615 returnresult.normal = normalpart.Normalize();
616 returnresult.distance = ParentGroup.m_scene.m_innerScene.Vector3Distance(iray.Origin, ipoint);
617
618 return returnresult;
619 }
620
621
622
538 /// <summary> 623 /// <summary>
539 /// 624 ///
540 /// </summary> 625 /// </summary>