diff options
author | Teravus Ovares | 2008-08-18 08:25:58 +0000 |
---|---|---|
committer | Teravus Ovares | 2008-08-18 08:25:58 +0000 |
commit | 2ef4ccf89edc591319d0b43915b02d7bc8b8e3c9 (patch) | |
tree | d849e35dbcf2b7bef6d38b1fb06f753d9ae6efaf /OpenSim/Region/Environment/Modules | |
parent | * Maptile prim volume drawing change from manually drawing the rectangles usi... (diff) | |
download | opensim-SC_OLD-2ef4ccf89edc591319d0b43915b02d7bc8b8e3c9.zip opensim-SC_OLD-2ef4ccf89edc591319d0b43915b02d7bc8b8e3c9.tar.gz opensim-SC_OLD-2ef4ccf89edc591319d0b43915b02d7bc8b8e3c9.tar.bz2 opensim-SC_OLD-2ef4ccf89edc591319d0b43915b02d7bc8b8e3c9.tar.xz |
* Slightly better implementation of prim volume drawing on the maptile using projection of an oriented bounding box. This isn't quite right yet. Experimental. It takes about 3 times longer then the previous version, however produces better results.
Diffstat (limited to 'OpenSim/Region/Environment/Modules')
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs | 187 |
1 files changed, 177 insertions, 10 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs b/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs index 52ee84d..6d51c88 100644 --- a/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs +++ b/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs | |||
@@ -42,10 +42,24 @@ using libsecondlife; | |||
42 | 42 | ||
43 | namespace OpenSim.Region.Environment.Modules.World.WorldMap | 43 | namespace OpenSim.Region.Environment.Modules.World.WorldMap |
44 | { | 44 | { |
45 | public struct RectangleDrawStruct | 45 | public enum DrawRoutine |
46 | { | 46 | { |
47 | Rectangle, | ||
48 | Polygon, | ||
49 | Ellipse | ||
50 | } | ||
51 | |||
52 | public struct face | ||
53 | { | ||
54 | public Point[] pts; | ||
55 | } | ||
56 | |||
57 | public struct DrawStruct | ||
58 | { | ||
59 | public DrawRoutine dr; | ||
47 | public Rectangle rect; | 60 | public Rectangle rect; |
48 | public SolidBrush brush; | 61 | public SolidBrush brush; |
62 | public face[] trns; | ||
49 | } | 63 | } |
50 | 64 | ||
51 | public class MapImageModule : IMapImageGenerator, IRegionModule | 65 | public class MapImageModule : IMapImageGenerator, IRegionModule |
@@ -361,7 +375,7 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap | |||
361 | tc = System.Environment.TickCount; | 375 | tc = System.Environment.TickCount; |
362 | m_log.Info("[MAPTILE]: Generating Maptile Step 2: Object Volume Profile"); | 376 | m_log.Info("[MAPTILE]: Generating Maptile Step 2: Object Volume Profile"); |
363 | List<EntityBase> objs = whichScene.GetEntities(); | 377 | List<EntityBase> objs = whichScene.GetEntities(); |
364 | Dictionary<uint, RectangleDrawStruct> z_sort = new Dictionary<uint, RectangleDrawStruct>(); | 378 | Dictionary<uint, DrawStruct> z_sort = new Dictionary<uint, DrawStruct>(); |
365 | //SortedList<float, RectangleDrawStruct> z_sort = new SortedList<float, RectangleDrawStruct>(); | 379 | //SortedList<float, RectangleDrawStruct> z_sort = new SortedList<float, RectangleDrawStruct>(); |
366 | List<float> z_sortheights = new List<float>(); | 380 | List<float> z_sortheights = new List<float>(); |
367 | List<uint> z_localIDs = new List<uint>(); | 381 | List<uint> z_localIDs = new List<uint>(); |
@@ -463,10 +477,15 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap | |||
463 | if (isBelow256AboveTerrain) | 477 | if (isBelow256AboveTerrain) |
464 | { | 478 | { |
465 | // Translate scale by rotation so scale is represented properly when object is rotated | 479 | // Translate scale by rotation so scale is represented properly when object is rotated |
466 | Vector3 scale = new Vector3(part.Shape.Scale.X, part.Shape.Scale.Y, part.Shape.Scale.Z); | 480 | Vector3 lscale = new Vector3(part.Shape.Scale.X, part.Shape.Scale.Y, part.Shape.Scale.Z); |
481 | Vector3 scale = new Vector3(); | ||
482 | Vector3 tScale = new Vector3(); | ||
483 | Vector3 axPos = new Vector3(pos.X,pos.Y,pos.Z); | ||
484 | |||
485 | |||
467 | LLQuaternion llrot = part.GetWorldRotation(); | 486 | LLQuaternion llrot = part.GetWorldRotation(); |
468 | Quaternion rot = new Quaternion(llrot.W, llrot.X, llrot.Y, llrot.Z); | 487 | Quaternion rot = new Quaternion(llrot.W, llrot.X, llrot.Y, llrot.Z); |
469 | scale = rot * scale; | 488 | scale = rot * lscale; |
470 | 489 | ||
471 | // negative scales don't work in this situation | 490 | // negative scales don't work in this situation |
472 | scale.x = Math.Abs(scale.x); | 491 | scale.x = Math.Abs(scale.x); |
@@ -485,13 +504,145 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap | |||
485 | || mapdrawendY > 255) | 504 | || mapdrawendY > 255) |
486 | continue; | 505 | continue; |
487 | 506 | ||
488 | int wy = 0; | 507 | #region obb face reconstruction part duex |
508 | Vector3[] vertexes = new Vector3[8]; | ||
509 | |||
510 | // float[] distance = new float[6]; | ||
511 | Vector3[] FaceA = new Vector3[6]; // vertex A for Facei | ||
512 | Vector3[] FaceB = new Vector3[6]; // vertex B for Facei | ||
513 | Vector3[] FaceC = new Vector3[6]; // vertex C for Facei | ||
514 | Vector3[] FaceD = new Vector3[6]; // vertex D for Facei | ||
515 | |||
516 | tScale = new Vector3(lscale.x, -lscale.y, lscale.z); | ||
517 | scale = ((rot * tScale)); | ||
518 | vertexes[0] = (new Vector3((pos.X + scale.x), (pos.Y + scale.y), (pos.Z + scale.z))); | ||
519 | // vertexes[0].x = pos.X + vertexes[0].x; | ||
520 | //vertexes[0].y = pos.Y + vertexes[0].y; | ||
521 | //vertexes[0].z = pos.Z + vertexes[0].z; | ||
522 | |||
523 | FaceA[0] = vertexes[0]; | ||
524 | FaceB[3] = vertexes[0]; | ||
525 | FaceA[4] = vertexes[0]; | ||
526 | |||
527 | tScale = lscale; | ||
528 | scale = ((rot * tScale)); | ||
529 | vertexes[1] = (new Vector3((pos.X + scale.x), (pos.Y + scale.y), (pos.Z + scale.z))); | ||
530 | |||
531 | // vertexes[1].x = pos.X + vertexes[1].x; | ||
532 | // vertexes[1].y = pos.Y + vertexes[1].y; | ||
533 | //vertexes[1].z = pos.Z + vertexes[1].z; | ||
534 | |||
535 | FaceB[0] = vertexes[1]; | ||
536 | FaceA[1] = vertexes[1]; | ||
537 | FaceC[4] = vertexes[1]; | ||
538 | |||
539 | tScale = new Vector3(lscale.x, -lscale.y, -lscale.z); | ||
540 | scale = ((rot * tScale)); | ||
541 | |||
542 | vertexes[2] = (new Vector3((pos.X + scale.x), (pos.Y + scale.y), (pos.Z + scale.z))); | ||
543 | |||
544 | //vertexes[2].x = pos.X + vertexes[2].x; | ||
545 | //vertexes[2].y = pos.Y + vertexes[2].y; | ||
546 | //vertexes[2].z = pos.Z + vertexes[2].z; | ||
547 | |||
548 | FaceC[0] = vertexes[2]; | ||
549 | FaceD[3] = vertexes[2]; | ||
550 | FaceC[5] = vertexes[2]; | ||
551 | |||
552 | tScale = new Vector3(lscale.x, lscale.y, -lscale.z); | ||
553 | scale = ((rot * tScale)); | ||
554 | vertexes[3] = (new Vector3((pos.X + scale.x), (pos.Y + scale.y), (pos.Z + scale.z))); | ||
555 | |||
556 | //vertexes[3].x = pos.X + vertexes[3].x; | ||
557 | // vertexes[3].y = pos.Y + vertexes[3].y; | ||
558 | // vertexes[3].z = pos.Z + vertexes[3].z; | ||
559 | |||
560 | FaceD[0] = vertexes[3]; | ||
561 | FaceC[1] = vertexes[3]; | ||
562 | FaceA[5] = vertexes[3]; | ||
563 | |||
564 | tScale = new Vector3(-lscale.x, lscale.y, lscale.z); | ||
565 | scale = ((rot * tScale)); | ||
566 | vertexes[4] = (new Vector3((pos.X + scale.x), (pos.Y + scale.y), (pos.Z + scale.z))); | ||
567 | |||
568 | // vertexes[4].x = pos.X + vertexes[4].x; | ||
569 | // vertexes[4].y = pos.Y + vertexes[4].y; | ||
570 | // vertexes[4].z = pos.Z + vertexes[4].z; | ||
571 | |||
572 | FaceB[1] = vertexes[4]; | ||
573 | FaceA[2] = vertexes[4]; | ||
574 | FaceD[4] = vertexes[4]; | ||
575 | |||
576 | tScale = new Vector3(-lscale.x, lscale.y, -lscale.z); | ||
577 | scale = ((rot * tScale)); | ||
578 | vertexes[5] = (new Vector3((pos.X + scale.x), (pos.Y + scale.y), (pos.Z + scale.z))); | ||
489 | 579 | ||
490 | bool breakYN = false; // If we run into an error drawing, break out of the | 580 | // vertexes[5].x = pos.X + vertexes[5].x; |
581 | // vertexes[5].y = pos.Y + vertexes[5].y; | ||
582 | // vertexes[5].z = pos.Z + vertexes[5].z; | ||
583 | |||
584 | FaceD[1] = vertexes[5]; | ||
585 | FaceC[2] = vertexes[5]; | ||
586 | FaceB[5] = vertexes[5]; | ||
587 | |||
588 | tScale = new Vector3(-lscale.x, -lscale.y, lscale.z); | ||
589 | scale = ((rot * tScale)); | ||
590 | vertexes[6] = (new Vector3((pos.X + scale.x), (pos.Y + scale.y), (pos.Z + scale.z))); | ||
591 | |||
592 | // vertexes[6].x = pos.X + vertexes[6].x; | ||
593 | // vertexes[6].y = pos.Y + vertexes[6].y; | ||
594 | // vertexes[6].z = pos.Z + vertexes[6].z; | ||
595 | |||
596 | FaceB[2] = vertexes[6]; | ||
597 | FaceA[3] = vertexes[6]; | ||
598 | FaceB[4] = vertexes[6]; | ||
599 | |||
600 | tScale = new Vector3(-lscale.x, -lscale.y, -lscale.z); | ||
601 | scale = ((rot * tScale)); | ||
602 | vertexes[7] = (new Vector3((pos.X + scale.x), (pos.Y + scale.y), (pos.Z + scale.z))); | ||
603 | |||
604 | // vertexes[7].x = pos.X + vertexes[7].x; | ||
605 | // vertexes[7].y = pos.Y + vertexes[7].y; | ||
606 | // vertexes[7].z = pos.Z + vertexes[7].z; | ||
607 | |||
608 | FaceD[2] = vertexes[7]; | ||
609 | FaceC[3] = vertexes[7]; | ||
610 | FaceD[5] = vertexes[7]; | ||
611 | #endregion | ||
612 | |||
613 | //int wy = 0; | ||
614 | |||
615 | //bool breakYN = false; // If we run into an error drawing, break out of the | ||
491 | // loop so we don't lag to death on error handling | 616 | // loop so we don't lag to death on error handling |
492 | RectangleDrawStruct ds = new RectangleDrawStruct(); | 617 | DrawStruct ds = new DrawStruct(); |
493 | ds.brush = new SolidBrush(mapdotspot); | 618 | ds.brush = new SolidBrush(mapdotspot); |
494 | ds.rect = new Rectangle(mapdrawstartX, (255 - mapdrawstartY), mapdrawendX - mapdrawstartX, mapdrawendY - mapdrawstartY); | 619 | //ds.rect = new Rectangle(mapdrawstartX, (255 - mapdrawstartY), mapdrawendX - mapdrawstartX, mapdrawendY - mapdrawstartY); |
620 | |||
621 | |||
622 | ds.trns = new face[FaceA.Length]; | ||
623 | |||
624 | |||
625 | |||
626 | for (int i = 0; i < FaceA.Length; i++) | ||
627 | { | ||
628 | |||
629 | Point[] working = new Point[5]; | ||
630 | working[0] = project(FaceA[i], axPos); | ||
631 | working[1] = project(FaceB[i], axPos); | ||
632 | working[2] = project(FaceD[i], axPos); | ||
633 | working[3] = project(FaceC[i], axPos); | ||
634 | working[4] = project(FaceA[i], axPos); | ||
635 | |||
636 | face workingface = new face(); | ||
637 | workingface.pts = working; | ||
638 | |||
639 | ds.trns[i] = workingface; | ||
640 | |||
641 | } | ||
642 | |||
643 | |||
644 | |||
645 | |||
495 | z_sort.Add(part.LocalId, ds); | 646 | z_sort.Add(part.LocalId, ds); |
496 | z_localIDs.Add(part.LocalId); | 647 | z_localIDs.Add(part.LocalId); |
497 | z_sortheights.Add(pos.Z); | 648 | z_sortheights.Add(pos.Z); |
@@ -541,8 +692,12 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap | |||
541 | 692 | ||
542 | if (z_sort.ContainsKey(sortedlocalIds[s])) | 693 | if (z_sort.ContainsKey(sortedlocalIds[s])) |
543 | { | 694 | { |
544 | RectangleDrawStruct rectDrawStruct = z_sort[sortedlocalIds[s]]; | 695 | DrawStruct rectDrawStruct = z_sort[sortedlocalIds[s]]; |
545 | g.FillRectangle(rectDrawStruct.brush , rectDrawStruct.rect); | 696 | for (int r = 0; r < rectDrawStruct.trns.Length; r++ ) |
697 | { | ||
698 | g.FillPolygon(rectDrawStruct.brush,rectDrawStruct.trns[r].pts); | ||
699 | } | ||
700 | //g.FillRectangle(rectDrawStruct.brush , rectDrawStruct.rect); | ||
546 | } | 701 | } |
547 | } | 702 | } |
548 | 703 | ||
@@ -553,6 +708,18 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap | |||
553 | m_log.Info("[MAPTILE]: Generating Maptile Step 2: Done in " + (System.Environment.TickCount - tc) + " ms"); | 708 | m_log.Info("[MAPTILE]: Generating Maptile Step 2: Done in " + (System.Environment.TickCount - tc) + " ms"); |
554 | return mapbmp; | 709 | return mapbmp; |
555 | } | 710 | } |
711 | private Point project(Vector3 point3d, Vector3 originpos) | ||
712 | { | ||
713 | Point returnpt = new Point(); | ||
714 | //originpos = point3d; | ||
715 | Vector3 topos = new Vector3(255, 255, 255);//(originpos.x * 256) / originpos.x); | ||
716 | float z = -point3d.z - topos.z; | ||
717 | returnpt.X = (int)((topos.x - point3d.x) / z * 255) + 255; | ||
718 | returnpt.Y = (int)(255 - (((topos.y - point3d.y) / z * 255) + 255)); | ||
719 | |||
720 | return returnpt; | ||
721 | |||
722 | } | ||
556 | 723 | ||
557 | // TODO: unused: | 724 | // TODO: unused: |
558 | // #region Deprecated Maptile Generation. Adam may update this | 725 | // #region Deprecated Maptile Generation. Adam may update this |