Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

USARBot.IR2Sensor


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
// Based on Erik Winter IRSensor class
//
// This class modifies the way noise is handled. It allows to shape noise
// in any way with an InterpCurve.
// Note: Noise shaped this way is no more linear but parabolic
//
// by Marco Zaratti - marco.zaratti@gmail.com
//==============================================================================
//
// This class is basically the same as the USARSim RangeSensor class
// For the moment only the Range and output curve parameters are changed
//	author: Erik Winter
//  created: 2005-02-24	Created the class from the USARSim RangeSensor class
//
//  modified:	2005-03-07	Made the IR look straight through transparent materials
//				2005-03-15  If the IR hits a transparent material it now sends out a new trace from the HitLocation recursively
//							until it hits a non-transparent material or reaches MaxRange
//
//	Todo:
//		- Apply the fact that the IR can see through, and though miss glass walls
//			* halfly done, if it hits a transparent material it returns maxRange. On these maps it should be an okay simplification, Fully Done

class IR2Sensor extends RangeSensor config (USARBot);

var config InterpCurve  OutputNoise;

function float GetRange()
{
    local vector HitLocation, HitNormal;
    local vector curLoc, direction;
    local float range, error;
    local material mtrl;


    range=0;
    curLoc=Location;
    direction = vector(Rotation);

    while(range < uuMaxRange)
    {
        if (Trace(HitLocation, HitNormal, Location + uuMaxRange*direction, curLoc, true, vect(0,0,0), mtrl)==NONE){
            range=MaxRange;
            break;
        }
        else {
            range=VSize(HitLocation-Location);
            if (converter!=None)
                range=converter.LengthFromUU(range);
        }

        if(InStr(string(mtrl), "Trans")==-1) // The IR hitted a non-transparent material.
            break;
        else
        {
            curLoc = HitLocation + 0.1*direction;
            range = VSize(curLoc - Location);
        }
    }
    //Cap range
    if (range>MaxRange) range=MaxRange;
    if (range<MinRange) range=MinRange;

    //Add noise
    if (OutputCurve.Points.length>0)
    {
        range=InterpCurveEval(OutputCurve, range);
        error=InterpCurveEval(OutputNoise, range);
    }
    range += RandRange(-error,error)*range;

    //Cap range again
    if (range>MaxRange) range=MaxRange;
    if (range<MinRange) range=MinRange;



    return range;

}

function String GetData()
{
    local string outstring;
    outstring="{Name "$ItemName$" Range "$converter.FloatString(GetRange())$"}";
    return outstring;
}

function String GetConfData()
{
    local string outstring;
    outstring = Super.GetConfData();
    outstring = outstring@"{MaxRange "$converter.FloatString(MaxRange)$"} {MinRange "$converter.FloatString(MinRange)$"}";
    return outstring;
}

defaultproperties
{
    bUseGroup=True
    ItemType="IR"
    HiddenSensor=false
    MaxRange=.8 // 0.80 m
    MinRange=.1 // 0.10 m
    OutputCurve=(Points=((InVal=0.000000,OutVal=0.000000),(InVal=0.800000,OutVal=0.800000)))
    OutputNoise=(Points=((InVal=0.0,OutVal=0.0),(InVal=0.8,OutVal=0.1)))
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Sa 16.9.2006 21:12:24.000 - Creation time: Mo 16.4.2007 11:20:48.843 - Created with UnCodeX