Official Fulqrum Publishing forum

Official Fulqrum Publishing forum (http://forum.fulqrumpublishing.com/index.php)
-   FMB, Mission & Campaign builder Discussions (http://forum.fulqrumpublishing.com/forumdisplay.php?f=203)
-   -   Terrain height at map point2D ? (http://forum.fulqrumpublishing.com/showthread.php?t=30738)

salmo 03-26-2012 07:50 AM

Terrain height at map point2D ?
 
I want to develop a function that recieves a 2D map coordinate & returns the terrain height at that point. Height could be a Z coordinate or height in metres. I've searched the COD methods for something useful I can play with without success. Any ideas anyone?

code removed by author

Smokeynz 03-26-2012 08:55 AM

I use something similar in my develpment I am working on, where I use a trigger point reference to activate the process, then within the Ontrigger I use the 2D pos location realtive to the trigger location. I only needed the 2D at this point, but was thinking about 3D aswell
There is 3D like the 2D which contains the z axis.

If you use the visual express you can load the specific clod syntax.

salmo 03-26-2012 09:53 AM

Quote:

Originally Posted by Smokeynz (Post 402963)
I use something similar in my develpment I am working on, where I use a trigger point reference to activate the process, then within the Ontrigger I use the 2D pos location realtive to the trigger location. I only needed the 2D at this point, but was thinking about 3D aswell
There is 3D like the 2D which contains the z axis.

If you use the visual express you can load the specific clod syntax.

Sorry, I don't understand the "I use the 2D pos location realtive to the trigger location. I only needed the 2D at this point, but was thinking about 3D aswell
There is 3D like the 2D which contains the z axis."

Can you explain what methods or formula or algorithm you are using the obtain terrain height from the 2D map point.

hc_wolf 03-26-2012 03:01 PM

example
 
here are two codes to help

sorry no time to explain


Code:


    private void FindNearestMarker(out Point2d target, Point2d basePoint, int army)        // piano, I find the nearest marker to the country
    {
        Point2d res = new Point2d(-1,-1);
        double minDist = 9999999999.9 ;
        foreach (MissionMarker mm in MissionMarkers)
        {
            if (mm.army == army)
            {
                double curDist = Math.Sqrt(Math.Pow((basePoint.x - mm.x),2 )+ Math.Pow((basePoint.y - mm.y),2));
                if (curDist < minDist)
                {
                    minDist = curDist;
                    res.x = mm.x; res.y = mm.y;
                }
            }
        }
        target = res;
    }

Code:

    private bool PointBetween(double intervalPoint1,double intervalPoint2,double point)        // kh-n checks whether the point lies in the interval
    {
        return ((point > Math.Min(intervalPoint1, intervalPoint2)) && (point < Math.Max(intervalPoint1, intervalPoint2)));
    }

    private void FindFinishPoint(out Point2d target,Point2d startPoint, int army)              // piano, I find the final destination
    {
        Point2d res = new Point2d(-1, -1);
        int enemyArmy = (army == 1) ? 2 : 1;       
        Point2d nearestEnemyMarker;
        Point3d startPos = new Point3d(startPoint.x, startPoint.y,0);
        FindNearestMarker(out nearestEnemyMarker, startPoint, enemyArmy);                      // first find the closest enemy marker
        AiActor nearestEnemyGG = FindGroundTarget(enemyArmy, startPos);                        // then the nearest group of enemy
        if (nearestEnemyGG != null)
        {
            if ((PointBetween(startPoint.x, nearestEnemyMarker.x, nearestEnemyGG.Pos().x)) && (PointBetween(startPoint.y, nearestEnemyMarker.y, nearestEnemyGG.Pos().y)))
            {
                res.x = nearestEnemyGG.Pos().x;
                res.y = nearestEnemyGG.Pos().y;
            }
            else res = nearestEnemyMarker;                                                      // and select one of them is closer
        }
        target = res;
    }


salmo 03-26-2012 03:44 PM

I get most of that Wolf, but I still don't see how this determines terrain height at the marker point? I was hoping I could find a method to test the LandType in 3D space, not just 2D space as below ...

code removed by author

Smokeynz 03-26-2012 09:05 PM

Much as wolf describes, although it looks like his version adds math function.

Kodiak helped me with the syntax arrangement for the 2Dpoint stuff, the rest I added, the logic test.

This is part of the complete code, I call references to process the results.
This setup is to detect players with a zone, well in this case 3 trigger zones where I create reaction ranges. You could just have one ofcurse. Effectively this overides all internal mission parameters, except I hijack the ontrigger and trigger, where I use Tpassthough to separate the armies.

For 3D, although I haven't tested it yet, I suspect all that needs to be added is the z axis to the internal double getdistancefromto. Point2 would become Point3D. That's all for the from ~ to

Note the Ontrigger fires the list for players, if you had specific objects, vehicles, you could(should) list them.(better to do this as objects can disappear causing exceptions references)

After the listing of the objects(players in this case) a ForEach is used to test the position against the reference


The change for the 2nd part, note the redradarx and redradar1y are the grid reference x,y coords. You would need to add the z coord

Point2d RedRadar1 = new Point2d(redradar1x, redradar1y); //this is reference location.
Point2d ActorPos = new Point2d(item.Place().Pos().x, item.Place().Pos().y);// this is object location at time of trigger


Theory, would become

Point3d <name> = new Point3d(coord x, coord y, coord z);

Point3d ActorPos = new Point3d(item.Place().Pos().x, item.Place().Pos().y, item.Place().Pos().z);

I use ranging tests in the logic following the location tests, you wouldn't need all this, only one test, less than the distance you want to trigger from the (x,y,z) reference position.

In my test if the result is true for any of the states, note I set different true or false arrangements, this is processsesd in the final mission loader private void.

I also separate the ai trigger processing into separate private void.

The advantage of separating final processing is that I can activate the final processing by other conditions other than ontrigger.

Code:


 internal double getDistanceFromTo(Point2d startPoint, Point2d endPoint)
    {
        return startPoint.distance(ref endPoint);
    }
         
    public override void OnTrigger(int missionNumber, string shortName, bool active)
    {
        base.OnTrigger(missionNumber, shortName, active);

        List<Player> plebs = new List<Player>();
        if (GamePlay.gpPlayer() != null)           
            plebs.Add(GamePlay.gpPlayer());
        if (GamePlay.gpRemotePlayers() != null)           
            plebs.AddRange(GamePlay.gpRemotePlayers());           

        plebs.ForEach(item =>
        {
            if (item.Place() != null)
            {
                //radar circles
                Point2d RedRadar1 = new Point2d(redradar1x, redradar1y);// radar trigger(Blue activate)
                Point2d BlueRadar1 = new Point2d(blueradar1x, blueradar1y);// radar trigger(Red activate)
                //Player pos
                Point2d ActorPos = new Point2d(item.Place().Pos().x, item.Place().Pos().y);

                //test Radars and Player Pos
                if (item.Army() == 1)
                {
                    if (getDistanceFromTo(ActorPos, BlueRadar1) > 15000.1)
                    {
                        Rredinblue1 = false;
                        Rredinblue2 = false;
                        Rredinblue3 = false;
                    }

                    if (getDistanceFromTo(ActorPos, BlueRadar1) < 15000)
                        if (getDistanceFromTo(ActorPos, BlueRadar1) > 10000.1)
                        {
                            Rredinblue1 = true;
                            Rredinblue2 = false;
                            Rredinblue3 = false;
                        }

                    if (getDistanceFromTo(ActorPos, BlueRadar1) < 10000)
                        if (getDistanceFromTo(ActorPos, BlueRadar1) > 5000.1)
                        {
                            Rredinblue1 = false;
                            Rredinblue2 = true;
                            Rredinblue3 = false;
                        }
                    if (getDistanceFromTo(ActorPos, BlueRadar1) < 5000)
                    {
                        Rredinblue1 = false;
                        Rredinblue2 = false;
                        Rredinblue3 = true;
                    }                   
                }
                                                                               
                if (item.Army() == 2)
                {
                    if (getDistanceFromTo(ActorPos, RedRadar1) > 15000.1)
                    {
                        Rblueinred1 = false;
                        Rblueinred2 = false;
                        Rblueinred3 = false;
                    }
                    if (getDistanceFromTo(ActorPos, RedRadar1) < 15000)
                        if (getDistanceFromTo(ActorPos, RedRadar1) > 10000.1)
                        {
                            Rblueinred1 = true;
                            Rblueinred2 = false;
                            Rblueinred3 = false;

                        }
                    if (getDistanceFromTo(ActorPos, RedRadar1) < 10000)
                        if (getDistanceFromTo(ActorPos, RedRadar1) > 5000.1)
                        {
                            Rblueinred1 = false;
                            Rblueinred2 = true;
                            Rblueinred3 = false;
                        }
                    if (getDistanceFromTo(ActorPos, RedRadar1) < 5000)
                    {
                        Rblueinred1 = false;
                        Rblueinred2 = false;
                        Rblueinred3 = true;
                    }
                }             
            }
        });
        // Radar detection
        if ((Rredinblue1 | Rredinblue2 | Rredinblue3 | Rblueinred1 | Rblueinred2 | Rblueinred3) == true)
        {
            SelectTriggerMission();           
        }
        // ai as triggers (AI can be treated separately here as well as player)
        TriggerProcessing(shortName, active);

    }



All times are GMT. The time now is 03:09 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2007 Fulqrum Publishing. All rights reserved.