Esempio n. 1
0
        public Position getCurrentPosition()
        {
            if (this.sceneController == null)
            {
                return(null);
            }

            PickedObjectList pol = this.getSceneController().getPickedObjectList();

            if (pol == null || pol.size() < 1)
            {
                return(null);
            }

            Position     p   = null;
            PickedObject top = pol.getTopPickedObject();

            if (top != null && top.hasPosition())
            {
                p = top.getPosition();
            }
            else if (pol.getTerrainObject() != null)
            {
                p = pol.getTerrainObject().getPosition();
            }

            return(p);
        }
Esempio n. 2
0
        /// <summary>
        /// Performs raycast picking with the given near and far points.
        /// </summary>
        /// <param name="nearPoint">The near point of the pick ray</param>
        /// <param name="farPoint">The far point of the pick ray</param>
        /// <returns>A list of picked objects</returns>
        public List <PickedObject> PickRayCast(Vector3 nearPoint, Vector3 farPoint)
        {
            pickedObjects.Clear();

            Vector3 rayDirection = (farPoint - nearPoint);

            rayDirection.Normalize();
            scene.UpdatePhysicsObjectsIntersectedByRay(ref nearPoint, ref rayDirection, 0, false);
            int objectsCollided = scene.IntersectedPhysicsObjectsCount;

            Vector3 hitPosition = Vector3.Zero;

            for (int i = 0; i < objectsCollided; i++)
            {
                MataliPhysicsObject obj = scene.GetIntersectedPhysicsObject(i, ref hitPosition);

                IPhysicsObject physObj = GetIPhysicsObject(obj);
                if (physObj != null && physObj.Pickable)
                {
                    PickedObject pickedObject = new PickedObject(physObj, i);
                    pickedObjects.Add(pickedObject);
                }
            }

            return(pickedObjects);
        }
Esempio n. 3
0
        private static List <PickedObject> ParseSelectBuffer(int[] SelectBuffer)
        {
            List <PickedObject> PickedObjects = new List <PickedObject>();
            int Position = 0;

            try
            {
                while (Position < SelectBuffer.Length)
                {
                    if (SelectBuffer[Position] == 0)
                    {
                        break;
                    }
                    PickedObject Object = new PickedObject();
                    Object.NameDepth = SelectBuffer[Position++];
                    Object.MinDepth  = (double)SelectBuffer[Position++] / int.MaxValue;
                    Object.MaxDepth  = (double)SelectBuffer[Position++] / int.MaxValue;
                    Object.Names     = new int[Object.NameDepth];
                    for (int i = 0; i < Object.NameDepth; i++)
                    {
                        Object.Names[i] = SelectBuffer[Position++];
                    }
                    PickedObjects.Add(Object);
                }
                return(PickedObjects);
            }
            catch (IndexOutOfRangeException)
            {
                if (Position >= SelectBuffer.Length)
                {
                    return(PickedObjects);
                }
                throw;
            }
        }
Esempio n. 4
0
        protected PickedObject createPickedObject(DrawContext dc, Color pickColor)
        {
            PickedObject po = super.createPickedObject(dc, pickColor);

            // Add the KMLPlacemark to the picked object as the context of the picked object.
            po.setValue(AVKey.CONTEXT, this.parent);
            return(po);
        }
Esempio n. 5
0
        protected PickedObject createPickedObject(int colorCode)
        {
            PickedObject po = super.createPickedObject(colorCode);

            // Add the KMLPlacemark to the picked object as the context of the picked object.
            po.setValue(AVKey.CONTEXT, this.parent);
            return(po);
        }
        /**
         * Adds the specified picked object to this context's the collection of pick candidates. This collection can be
         * accessed by calling {@link #getPickCandidates()}.
         *
         * @param pickedObject the object to add.
         *
         * @throws ArgumentException if the object is null.
         */
        public void addPickCandidate(PickedObject pickedObject)
        {
            if (null == pickedObject)
            {
                String msg = Logging.getMessage("nullValue.PickedObject");
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

            this.pickCandidates.add(pickedObject);
        }
Esempio n. 7
0
        /**
         * Detects the locations of the sector geometries in this list that intersect a specified screen point.
         * <p/>
         * Note: Prior to calling this method, {@link #beginRendering(gov.nasa.worldwind.render.DrawContext)} must be
         * called.
         *
         * @param dc        the current draw context.
         * @param pickPoint the screen point to test.
         */
        public void pick(DrawContext dc, java.awt.Point pickPoint)
        {
            if (dc == null)
            {
                String message = Logging.getMessage("nullValue.DrawContextIsNull");
                Logging.logger().severe(message);
                throw new IllegalStateException(message);
            }

            if (pickPoint == null)
            {
                return;
            }

            this.pickSupport.clearPickList();
            this.pickSupport.beginPicking(dc);

            GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

            gl.glShadeModel(GL2.GL_FLAT);

            try
            {
                // render each sector in unique color
                this.beginRendering(dc);
                foreach (SectorGeometry sector in this)
                {
                    Color color = dc.getUniquePickColor();
                    gl.glColor3ub((byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue());
                    sector.render(dc);
                    // lat/lon/elevation not used in this case
                    this.pickSupport.addPickableObject(color.getRGB(), sector, Position.ZERO, true);
                }

                PickedObject pickedSector = this.pickSupport.getTopObject(dc, pickPoint);
                if (pickedSector == null || pickedSector.getObject() == null)
                {
                    return; // no sector picked
                }
                this.beginSectorGeometryPicking(dc);
                SectorGeometry sector = (SectorGeometry)pickedSector.getObject();
                sector.pick(dc, pickPoint);
            }
            finally
            {
                this.endSectorGeometryPicking(dc);
                this.endRendering(dc);
                gl.glShadeModel(GL2.GL_SMOOTH); // restore to default explicitly to avoid more expensive pushAttrib

                this.pickSupport.endPicking(dc);
                this.pickSupport.clearPickList();
            }
        }
Esempio n. 8
0
        protected PickedObject getCurrentSelection()
        {
            if (this.sceneController == null)
            {
                return(null);
            }

            PickedObjectList pol = this.getSceneController().getPickedObjectList();

            if (pol == null || pol.size() < 1)
            {
                return(null);
            }

            PickedObject top = pol.getTopPickedObject();

            return(top.isTerrain() ? null : top);
        }
Esempio n. 9
0
        private static List <PickedObject> ParseSelectBuffer(int[] selectBuffer)
        {
            List <PickedObject> pickedObjects = new List <PickedObject>();
            int position = 0;

            try
            {
                while (position < selectBuffer.Length)
                {
                    if (selectBuffer[position] == 0)
                    {
                        break;
                    }

                    PickedObject pickedObject = new PickedObject
                    {
                        NameDepth = selectBuffer[position++],
                        MinDepth  = (double)selectBuffer[position++] / int.MaxValue,
                        MaxDepth  = (double)selectBuffer[position++] / int.MaxValue
                    };
                    pickedObject.Names = new int[pickedObject.NameDepth];

                    for (int i = 0; i < pickedObject.NameDepth; i++)
                    {
                        pickedObject.Names[i] = selectBuffer[position++];
                    }

                    pickedObjects.Add(pickedObject);
                }

                return(pickedObjects);
            }
            catch (IndexOutOfRangeException)
            {
                if (position >= selectBuffer.Length)
                {
                    return(pickedObjects);
                }

                throw;
            }
        }
Esempio n. 10
0
    public void ApplySideEffect(GameObject npc, GameObject pc, int lineNumber, out string originalScript)
    {
        switch (lineNumber)
        {
        case 1:
        case 580:
            originalScript = "game.global_flags[1] = 1";
            SetGlobalFlag(1, true);
            break;

        case 6:
        case 7:
        case 93:
        case 94:
            originalScript = "game.global_flags[18] = 1; game.global_flags[67] = 1";
            SetGlobalFlag(18, true);
            SetGlobalFlag(67, true);
            ;
            break;

        case 8:
        case 9:
            originalScript = "game.global_flags[19] = 1";
            SetGlobalFlag(19, true);
            break;

        case 16:
        case 17:
            originalScript = "party_transfer_to( npc, 12900 )";
            Utilities.party_transfer_to(npc, 12900);
            break;

        case 27:
        case 28:
            originalScript = "game.global_flags[18] = 1";
            SetGlobalFlag(18, true);
            break;

        case 41:
            originalScript = "game.global_vars[2] = game.global_vars[2] + 100;  pc.money_adj(-10000)";
            SetGlobalVar(2, GetGlobalVar(2) + 100);
            pc.AdjustMoney(-10000);
            ;
            break;

        case 42:
            originalScript = "game.global_vars[2] = game.global_vars[2] + 20; pc.money_adj(-2000)";
            SetGlobalVar(2, GetGlobalVar(2) + 20);
            pc.AdjustMoney(-2000);
            ;
            break;

        case 43:
            originalScript = "game.global_vars[2] = game.global_vars[2] + 5; pc.money_adj(-500)";
            SetGlobalVar(2, GetGlobalVar(2) + 5);
            pc.AdjustMoney(-500);
            ;
            break;

        case 44:
            originalScript = "game.global_vars[2] = game.global_vars[2] + 1; pc.money_adj(-100)";
            SetGlobalVar(2, GetGlobalVar(2) + 1);
            pc.AdjustMoney(-100);
            ;
            break;

        case 100:
            originalScript = "game.quests[4].state = qs_mentioned";
            SetQuestState(4, QuestState.Mentioned);
            break;

        case 140:
        case 150:
            originalScript = "game.global_flags[23] = 1";
            SetGlobalFlag(23, true);
            break;

        case 170:
            originalScript = "game.global_flags[3] = 1";
            SetGlobalFlag(3, true);
            break;

        case 230:
            originalScript = "game.global_flags[8] = 1";
            SetGlobalFlag(8, true);
            break;

        case 270:
        case 310:
            originalScript = "game.global_flags[13] = 1";
            SetGlobalFlag(13, true);
            break;

        case 323:
            originalScript = "game.areas[2] = 1; game.story_state = 1; game.quests[72].state = qs_mentioned";
            MakeAreaKnown(2);
            StoryState = 1;
            SetQuestState(72, QuestState.Mentioned);
            ;
            break;

        case 324:
        case 325:
            originalScript = "game.quests[72].state = qs_accepted; game.global_vars[562] = 4; game.worldmap_travel_by_dialog(2)";
            SetQuestState(72, QuestState.Accepted);
            SetGlobalVar(562, 4);
            WorldMapTravelByDialog(2);
            break;

        case 326:
        case 327:
            originalScript = "game.quests[72].state = qs_accepted; game.global_vars[562] = 4";
            SetQuestState(72, QuestState.Accepted);
            SetGlobalVar(562, 4);
            ;
            break;

        case 336:
            originalScript = "game.quests[5].state = qs_completed";
            SetQuestState(5, QuestState.Completed);
            break;

        case 346:
            originalScript = "game.quests[26].state = qs_completed; game.quests[72].state = qs_completed; game.global_vars[562] = 6";
            SetQuestState(26, QuestState.Completed);
            SetQuestState(72, QuestState.Completed);
            SetGlobalVar(562, 6);
            ;
            break;

        case 358:
            originalScript = "game.areas[3] = 1; game.story_state = 3";
            MakeAreaKnown(3);
            StoryState = 3;
            ;
            break;

        case 359:
        case 360:
            originalScript = "game.worldmap_travel_by_dialog(3)";
            WorldMapTravelByDialog(3);
            break;

        case 390:
            originalScript = "game.picker( npc, spell_remove_disease, should_heal_disease_on, [ 450, 370, 400 ] )";
            // FIXME: picker;
            break;

        case 401:
        case 403:
            originalScript = "pc.money_adj(-21000); npc.cast_spell( spell_remove_disease, picker_obj )";
            pc.AdjustMoney(-21000);
            npc.CastSpell(WellKnownSpells.RemoveDisease, PickedObject);
            ;
            break;

        case 405:
        case 485:
        case 720:
            originalScript = "npc.spells_pending_to_memorized()";
            npc.PendingSpellsToMemorized();
            break;

        case 410:
            originalScript = "game.picker( npc, spell_neutralize_poison, should_heal_poison_on, [ 450, 370, 420 ] )";
            // FIXME: picker;
            break;

        case 421:
        case 423:
            originalScript = "pc.money_adj(-21000); npc.cast_spell( spell_neutralize_poison, picker_obj )";
            pc.AdjustMoney(-21000);
            npc.CastSpell(WellKnownSpells.NeutralizePoison, PickedObject);
            ;
            break;

        case 434:
            originalScript = "game.picker( npc, spell_cure_light_wounds, should_heal_hp_on, [ 450, 370, 436 ] )";
            // FIXME: picker;
            break;

        case 437:
        case 439:
            originalScript = "pc.money_adj(-7000); npc.cast_spell( spell_cure_light_wounds, picker_obj )";
            pc.AdjustMoney(-7000);
            npc.CastSpell(WellKnownSpells.CureLightWounds, PickedObject);
            ;
            break;

        case 460:
            originalScript = "game.picker( npc, spell_cure_serious_wounds, should_heal_hp_on, [ 450, 370, 462 ] )";
            // FIXME: picker;
            break;

        case 463:
        case 465:
            originalScript = "pc.money_adj(-30000); npc.cast_spell( spell_cure_serious_wounds, picker_obj )";
            pc.AdjustMoney(-30000);
            npc.CastSpell(WellKnownSpells.CureSeriousWounds, PickedObject);
            ;
            break;

        case 470:
            originalScript = "game.picker( npc, spell_remove_disease, should_heal_disease_on, [ 450, 370, 480 ] )";
            // FIXME: picker;
            break;

        case 481:
        case 483:
            originalScript = "pc.money_adj(-25000); npc.cast_spell( spell_remove_disease, picker_obj )";
            pc.AdjustMoney(-25000);
            npc.CastSpell(WellKnownSpells.RemoveDisease, PickedObject);
            ;
            break;

        case 490:
            originalScript = "game.picker( npc, spell_neutralize_poison, should_heal_poison_on, [ 450, 370, 500 ] )";
            // FIXME: picker;
            break;

        case 501:
        case 503:
            originalScript = "pc.money_adj(-25000); npc.cast_spell( spell_neutralize_poison, picker_obj )";
            pc.AdjustMoney(-25000);
            npc.CastSpell(WellKnownSpells.NeutralizePoison, PickedObject);
            ;
            break;

        case 514:
            originalScript = "game.picker( npc, spell_cure_light_wounds, should_heal_hp_on, [ 450, 370, 516 ] )";
            // FIXME: picker;
            break;

        case 517:
        case 519:
            originalScript = "pc.money_adj(-10000); npc.cast_spell( spell_cure_light_wounds, picker_obj )";
            pc.AdjustMoney(-10000);
            npc.CastSpell(WellKnownSpells.CureLightWounds, PickedObject);
            ;
            break;

        case 540:
            originalScript = "game.picker( npc, spell_cure_serious_wounds, should_heal_hp_on, [ 450, 370, 542 ] )";
            // FIXME: picker;
            break;

        case 543:
        case 545:
            originalScript = "pc.money_adj(-35000); npc.cast_spell( spell_cure_serious_wounds, picker_obj )";
            pc.AdjustMoney(-35000);
            npc.CastSpell(WellKnownSpells.CureSeriousWounds, PickedObject);
            ;
            break;

        case 560:
        case 570:
            originalScript = "game.picker( npc, spell_reincarnation, should_resurrect_on, [ 450, 370, 562 ] )";
            // FIXME: picker;
            break;

        case 563:
        case 565:
            originalScript = "pc.money_adj(-22500); npc.cast_spell( spell_reincarnation, picker_obj )";
            pc.AdjustMoney(-22500);
            npc.CastSpell(WellKnownSpells.Reincarnation, PickedObject);
            ;
            break;

        case 573:
        case 575:
            originalScript = "pc.money_adj(-27500); npc.cast_spell( spell_reincarnation, picker_obj )";
            pc.AdjustMoney(-27500);
            npc.CastSpell(WellKnownSpells.Reincarnation, PickedObject);
            ;
            break;

        case 651:
        case 652:
            originalScript = "game.global_flags[855] = 1";
            SetGlobalFlag(855, true);
            break;

        case 660:
            originalScript = "game.picker( npc, spell_reincarnation, should_resurrect_on, [ 690, 640, 710 ] )";
            // FIXME: picker;
            break;

        case 683:
        case 684:
            originalScript = "amii_dies_due_to_dont_give_a_damn_dialog(npc,pc)";
            amii_dies_due_to_dont_give_a_damn_dialog(npc, pc);
            break;

        case 710:
            originalScript = "game.global_vars[523] = game.global_vars[523] + 1";
            SetGlobalVar(523, GetGlobalVar(523) + 1);
            break;

        case 711:
            originalScript = "npc.cast_spell( spell_reincarnation, picker_obj )";
            npc.CastSpell(WellKnownSpells.Reincarnation, PickedObject);
            break;

        case 730:
            originalScript = "game.picker( npc, spell_cure_serious_wounds, should_heal_hp_on, [ 690, 640, 740 ] )";
            // FIXME: picker;
            break;

        case 740:
            originalScript = "game.global_vars[524] = game.global_vars[524] + 1";
            SetGlobalVar(524, GetGlobalVar(524) + 1);
            break;

        case 741:
            originalScript = "npc.cast_spell( spell_cure_serious_wounds, picker_obj )";
            npc.CastSpell(WellKnownSpells.CureSeriousWounds, PickedObject);
            break;

        case 861:
            originalScript = "run_off(npc,pc)";
            run_off(npc, pc);
            break;

        case 971:
        case 980:
        case 981:
            originalScript = "game.global_vars[455] |= 2**7";
            SetGlobalVar(455, GetGlobalVar(455) | 0x80);
            break;

        case 1000:
            originalScript = "game.picker( npc, spell_reincarnation, should_clear_spell_on, [ 1045, 370, 1562 ] )";
            // FIXME: picker;
            break;

        case 1562:
            originalScript = "game.global_vars[753] = picker_obj.stat_level_get(stat_experience); kill_picked(picker_obj, npc)";
            SetGlobalVar(753, PickedObject.GetStat(Stat.experience));
            kill_picked(PickedObject, npc);
            ;
            break;

        case 1575:
            originalScript = "picker_obj.stat_base_set(stat_experience, game.global_vars[753]); npc.spells_pending_to_memorized()";
            PickedObject.SetBaseStat(Stat.experience, GetGlobalVar(753));
            npc.PendingSpellsToMemorized();
            ;
            break;

        default:
            originalScript = null;
            return;
        }
    }
Esempio n. 11
0
        /// <summary>
        /// Performs raycast picking with the given near and far points.
        /// </summary>
        /// <param name="nearPoint">The near point of the pick ray</param>
        /// <param name="farPoint">The far point of the pick ray</param>
        /// <returns>A list of picked objects</returns>
        public List<PickedObject> PickRayCast(Vector3 nearPoint, Vector3 farPoint)
        {
            pickedObjects.Clear();

            Vector3 rayDirection = (farPoint - nearPoint);
            rayDirection.Normalize();
            scene.UpdatePhysicsObjectsIntersectedByRay(ref nearPoint, ref rayDirection, 0, false);
            int objectsCollided = scene.IntersectedPhysicsObjectsCount;

            Vector3 hitPosition = Vector3.Zero;

            for (int i = 0; i < objectsCollided; i++)
            {

                MataliPhysicsObject obj = scene.GetIntersectedPhysicsObject(i, ref hitPosition);

                IPhysicsObject physObj = GetIPhysicsObject(obj);
                if (physObj != null && physObj.Pickable)
                {
                    PickedObject pickedObject = new PickedObject(physObj, i);
                    pickedObjects.Add(pickedObject);
                }
            }

            return pickedObjects;
        }
Esempio n. 12
0
        /// <summary>
        /// Creates an instance of the Newton physics simulation engine.
        /// </summary>
        public NewtonPhysics()
        {
            gravity = 9.8f;
            gravityDir = Vector3Helper.Get(0, -1, 0);
            useBoundingBox = false;
            worldSize = new BoundingBox(Vector3.One * -100, Vector3.One * 100);

            objectIDs = new Dictionary<IPhysicsObject, IntPtr>();
            scaleTable = new Dictionary<IntPtr, Vector3>();
            reverseIDs = new Dictionary<IntPtr, IPhysicsObject>();
            collisionCallbacks = new Dictionary<CollisionPair, CollisionCallback>();

            materialIDs = new Dictionary<String, int>();
            materialPairs = new List<string>();
            materials = new Dictionary<IntPtr, NewtonMaterial>();

            joints = new Dictionary<IntPtr, Joint>();
            jointsToBeAdded = new List<Joint>();

            pickedObjects = new List<PickedObject>();

            forces = new Dictionary<IntPtr, Stack<Vector3>>();
            torques = new Dictionary<IntPtr, Stack<Vector3>>();

            setTransformMap = new Dictionary<IPhysicsObject,Newton.NewtonSetTransform>();
            applyForceMap = new Dictionary<IPhysicsObject,Newton.NewtonApplyForceAndTorque>();
            treeCollisionMap = new Dictionary<IPhysicsObject,Newton.NewtonTreeCollision>();

            collisionMesh = new List<List<Vector3>>();

            numSubSteps = 1;
            pauseSimulation = false;
            simulationTimeStep = 0.016f;

            transformCallback = delegate(IntPtr body, float[] pMatrix)
            {
                if (!reverseIDs.ContainsKey(body) || reverseIDs[body].Manipulatable)
                    return;

                ShapeType shape = reverseIDs[body].Shape;

                tmpVec1 = scaleTable[body];
                if ((shape == ShapeType.Box) || (shape == ShapeType.Sphere) || (shape == ShapeType.ConvexHull) 
                    || (shape == ShapeType.TriangleMesh))
                {
                    Matrix.CreateScale(ref tmpVec1, out tmpMat1);
                    MatrixHelper.FloatsToMatrix(pMatrix, out tmpMat2);
                    Matrix.Multiply(ref tmpMat1, ref tmpMat2, out tmpMat1);
                    reverseIDs[body].PhysicsWorldTransform = tmpMat1;
                }
                else
                {
                    Matrix.CreateScale(ref tmpVec1, out tmpMat1);
                    Matrix.CreateRotationZ(-MathHelper.PiOver2, out tmpMat2);
                    Matrix.Multiply(ref tmpMat1, ref tmpMat2, out tmpMat1);
                    MatrixHelper.FloatsToMatrix(pMatrix, out tmpMat2);
                    Matrix.Multiply(ref tmpMat1, ref tmpMat2, out tmpMat1);
                    reverseIDs[body].PhysicsWorldTransform = tmpMat1;
                }
            };

            applyForceAndTorqueCallback = delegate(IntPtr pNewtonBody)
            {
                if (!reverseIDs.ContainsKey(pNewtonBody))
                    return;

                float[] force = new float[3];
                force[0] = force[1] = force[2] = 0;
                if (reverseIDs[pNewtonBody].ApplyGravity)
                {
                    float Ixx = 0, Iyy = 0, Izz = 0, mass = 0;

                    Newton.NewtonBodyGetMassMatrix(pNewtonBody, ref mass, ref Ixx, ref Iyy, ref Izz);

                    Vector3.Multiply(ref gravityDir, gravity * mass, out tmpVec1);
                    force = Vector3Helper.ToFloats(ref tmpVec1);
                }

                Vector3 tmp;
                if (forces.ContainsKey(pNewtonBody) && forces[pNewtonBody].Count > 0)
                {
                    Stack<Vector3> _forces = forces[pNewtonBody];
                    while (_forces.Count > 0)
                    {
                        tmp = _forces.Pop();
                        force[0] += tmp.X;
                        force[1] += tmp.Y;
                        force[2] += tmp.Z;
                    }
                }
                Newton.NewtonBodyAddForce(pNewtonBody, force);

                if (torques.ContainsKey(pNewtonBody) && torques[pNewtonBody].Count > 0)
                {
                    float[] torque = new float[3];
                    torque[0] = torque[1] = torque[2] = 0;
                    Stack<Vector3> _torques = torques[pNewtonBody];
                    while (_torques.Count > 0)
                    {
                        tmp = _torques.Pop();
                        torque[0] += tmp.X;
                        torque[1] += tmp.Y;
                        torque[2] += tmp.Z;
                    }
                    Newton.NewtonBodyAddTorque(pNewtonBody, torque);
                }
                
            };

            rayCastFilterCallback = delegate(IntPtr pNewtonBody, float[] pHitNormal, int pCollisionID,
                IntPtr pUserData, float pIntersetParam)
            {
                if (!reverseIDs.ContainsKey(pNewtonBody))
                    return -1;

                IPhysicsObject physObj = reverseIDs[pNewtonBody];
                if (physObj.Pickable)
                {
                    PickedObject pickedObject = new PickedObject(physObj, pIntersetParam);
                    pickedObjects.Add(pickedObject);
                }

                return pIntersetParam;
            };

            materialContactBeginCallback = delegate(IntPtr pMaterial, IntPtr pNewtonBody0, IntPtr pNewtonBody1)
            {
                if (!materials.ContainsKey(Newton.NewtonMaterialGetMaterialPairUserData(pMaterial)))
                    return 1;

                NewtonMaterial physMat = materials[Newton.NewtonMaterialGetMaterialPairUserData(pMaterial)];

                if (physMat.ContactBeginCallback == null)
                    return 1;

                if (reverseIDs.ContainsKey(pNewtonBody0) && reverseIDs.ContainsKey(pNewtonBody1))
                    physMat.ContactBeginCallback(reverseIDs[pNewtonBody0], reverseIDs[pNewtonBody1]);

                return 1;
            };

            materialContactProcessCallback = delegate(IntPtr pMaterial, IntPtr pContact)
            {
                if (!materials.ContainsKey(Newton.NewtonMaterialGetMaterialPairUserData(pMaterial)))
                    return 1;

                NewtonMaterial physMat = materials[Newton.NewtonMaterialGetMaterialPairUserData(pMaterial)];

                if (physMat.ContactProcessCallback == null)
                    return 1;

                float contactNormalSpeed = Newton.NewtonMaterialGetContactNormalSpeed(pMaterial, pContact);

                float[] contactPos = new float[3];
                float[] contactNormal = new float[3];
                Newton.NewtonMaterialGetContactPositionAndNormal(pMaterial, contactPos, contactNormal);

                float colObj1ContactTangentSpeed = Newton.NewtonMaterialGetContactTangentSpeed(pMaterial, pContact, 0);
                float colObj2ContactTangentSpeed = Newton.NewtonMaterialGetContactTangentSpeed(pMaterial, pContact, 1);

                float[] colObj1ContactTangentDir = new float[3];
                float[] colObj2ContactTangentDir = new float[3];
                Newton.NewtonMaterialGetContactTangentDirections(pMaterial, colObj1ContactTangentDir,
                    colObj2ContactTangentDir);

                physMat.ContactProcessCallback(Vector3Helper.Get(contactPos[0], contactPos[1], contactPos[2]),
                    Vector3Helper.Get(contactNormal[0], contactNormal[1], contactNormal[2]),
                    contactNormalSpeed, colObj1ContactTangentSpeed, colObj2ContactTangentSpeed,
                    Vector3Helper.Get(colObj1ContactTangentDir[0], colObj1ContactTangentDir[1], colObj1ContactTangentDir[2]),
                    Vector3Helper.Get(colObj2ContactTangentDir[0], colObj2ContactTangentDir[1], colObj2ContactTangentDir[2]));

                return 1;
            };

            materialContactEndCallback = delegate(IntPtr pMaterial)
            {
                if (!materials.ContainsKey(Newton.NewtonMaterialGetMaterialPairUserData(pMaterial)))
                    return;

                NewtonMaterial physMat = materials[Newton.NewtonMaterialGetMaterialPairUserData(pMaterial)];

                if (physMat.ContactEndCallback == null)
                    return;

                physMat.ContactEndCallback();
            };

            collisionIterator = delegate(IntPtr pNewtonBody, int vertexCount, float[] faceArray, int faceID)
            {
                List<Vector3> verts = new List<Vector3>();
                int max = faceArray.Length / 3;
                if (vertexCount > max)
                    Log.Write("More faceArray needed for drawing the collision mesh: " + vertexCount);
                for (int i = 0; i < vertexCount && i < max; i++)
                    verts.Add(Vector3Helper.Get(faceArray[i * 3], faceArray[i * 3 + 1], faceArray[i * 3 + 2]));

                collisionMesh.Add(verts);
            };
        }
Esempio n. 13
0
        public Object getTopObject()
        {
            PickedObject tpo = this.getTopPickedObject();

            return(tpo != null?tpo.getObject() : null);
        }
Esempio n. 14
0
        /**
         * Detects the locations of the sector geometries in this list that intersect any of the points in a specified list
         * of screen points.
         * <p/>
         * Note: Prior to calling this method, {@link #beginRendering(gov.nasa.worldwind.render.DrawContext)} must be
         * called.
         *
         * @param dc         the current draw context.
         * @param pickPoints the points to test.
         *
         * @return an array of picked objects that intersect one or more of the specified screen points.
         */
        public List <PickedObject> pick(DrawContext dc, List <Point> pickPoints)
        {
            if (dc == null)
            {
                String message = Logging.getMessage("nullValue.DrawContextIsNull");
                Logging.logger().severe(message);
                throw new IllegalStateException(message);
            }

            if (pickPoints == null || pickPoints.Count < 1)
            {
                return(null);
            }

            this.pickSupport.clearPickList();
            this.pickSupport.beginPicking(dc);

            GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

            gl.glShadeModel(GL2.GL_FLAT);

            try
            {
                // render each sector in a unique color
                this.beginRendering(dc);
                foreach (SectorGeometry sector in this)
                {
                    Color color = dc.getUniquePickColor();
                    gl.glColor3ub((byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue());
                    sector.render(dc);
                    // lat/lon/elevation not used in this case
                    this.pickSupport.addPickableObject(color.getRGB(), sector, Position.ZERO, true);
                }

                // Determine the sectors underneath the pick points. Assemble a pick-points per sector map.
                // Several pick points might intersect the same sector.
                this.pickSectors.Clear();
                foreach (Point pickPoint in pickPoints)
                {
                    PickedObject pickedSector = this.pickSupport.getTopObject(dc, pickPoint);
                    if (pickedSector == null || pickedSector.getObject() == null)
                    {
                        continue;
                    }

                    SectorGeometry sector = (SectorGeometry)pickedSector.getObject();
                    List <Point>   sectorPickPoints;
                    if (!this.pickSectors.ContainsKey(sector))
                    {
                        sectorPickPoints = new List <Point>();
                        this.pickSectors.Add(sector, sectorPickPoints);
                    }
                    else
                    {
                        this.pickSectors.TryGetValue(sector, out sectorPickPoints);
                    }
                    sectorPickPoints.Add(pickPoint);
                }

                if (this.pickSectors.Count < 1)
                {
                    return(null);
                }

                // Now have each sector determine the pick position for each intersecting pick point.
                this.beginSectorGeometryPicking(dc);
                List <PickedObject> pickedObjects = new List <PickedObject>();
                foreach (KeyValuePair <SectorGeometry, List <Point> > sector in this.pickSectors)
                {
                    List <Point>   sectorPickPoints = sector.Value;
                    PickedObject[] pos = sector.Key.pick(dc, sectorPickPoints);
                    if (pos == null)
                    {
                        continue;
                    }

                    foreach (PickedObject po in pos)
                    {
                        if (po != null)
                        {
                            pickedObjects.Add(po);
                        }
                    }
                }

                return(pickedObjects);
            }
            finally
            {
                this.endSectorGeometryPicking(dc);
                this.endRendering(dc);
                gl.glShadeModel(GL2.GL_SMOOTH); // restore to default explicitly to avoid more expensive pushAttrib

                this.pickSupport.endPicking(dc);
                this.pickSupport.clearPickList();
            }
        }
Esempio n. 15
0
        protected void doResolveTopPick(DrawContext dc, Rectangle pickRect)
        {
            PickedObjectList pol = dc.getObjectsInPickRectangle();

            if (pol != null && pol.size() == 1)
            {
                // If there is only one picked object, then it must be the top object so we're done.
                pol.get(0).setOnTop();
            }
            else if (pol != null && pol.size() > 1)
            {
                int[] minAndMaxColorCodes = null;

                foreach (PickedObject po in pol)
                {
                    int colorCode = po.getColorCode();

                    // Put all of the eligible picked objects in a map to provide constant time access to a picked object
                    // by its color code. Since the number of unique color codes and picked objects may both be large, using
                    // a hash map reduces the complexity of the next loop from O(n*m) to O(n*c), where n and m are the
                    // lengths of the unique color list and picked object list, respectively, and c is the constant time
                    // associated with a hash map access.
                    this.pickableObjects.put(colorCode, po);

                    // Keep track of the minimum and maximum color codes of the scene's picked objects. These values are
                    // used to cull the number of colors that the draw context must consider with identifying the unique
                    // pick colors in the specified screen rectangle.
                    if (minAndMaxColorCodes == null)
                    {
                        minAndMaxColorCodes = new int[] { colorCode, colorCode }
                    }
                    ;
                    else
                    {
                        if (minAndMaxColorCodes[0] > colorCode)
                        {
                            minAndMaxColorCodes[0] = colorCode;
                        }
                        if (minAndMaxColorCodes[1] < colorCode)
                        {
                            minAndMaxColorCodes[1] = colorCode;
                        }
                    }
                }

                // If there is more than one picked object, then find the picked objects corresponding to each of the top
                // colors in the pick rectangle, and mark them all as on top.
                int[] colorCodes = dc.getPickColorsInRectangle(pickRect, minAndMaxColorCodes);
                if (colorCodes != null && colorCodes.length > 0)
                {
                    // Find the top picked object for each unique color code, if any, and mark it as on top.
                    foreach (int colorCode in colorCodes)
                    {
                        if (colorCode != 0) // This should never happen, but we check anyway.
                        {
                            PickedObject po = this.pickableObjects.get(colorCode);
                            if (po != null)
                            {
                                po.setOnTop();
                            }
                        }
                    }
                }

                // Clear the map of eligible picked objects so that the picked objects from this frame do not affect the
                // next frame. This also ensures that we do not leak memory by retaining references to picked objects.
                this.pickableObjects.clear();
            }
        }