Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 12, 2017, 8:29:52 PM (7 years ago)
Author:
remartin
Message:

Added tilting for the spicedAsteroidBelt. Finished commenting, polish up. Done.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidBelt.cc

    r11665 r11667  
    2929/**
    3030
    31     @file SpicedAsteroidBelt.cc
     31    @file
     32    @author remartin
    3233    @brief Asteroid belt with lots of parameters. Derived from asteroidField.lua
    3334
     35    Generates a ring of asteroids by calling SpicedAsteroidField multiple times.
     36    It's in the xy-plane at default, orientation can be changed with tiltAt
     37    (angle where it gets elevated/lowered the most) and TiltBy (angle at z-axis).
     38    This doesn't work very well and could probably implemented differently with
     39    relative coordinates (attach etc, stuff in WorldEntity).
    3440
     41    It is required to wait until all XML-arguments are set. That's why the actual
     42    generation happens when tick() gets called for the first time.
     43   
    3544*/
    3645
     
    6473        this->count = 250;
    6574        this->position = Vector3(0,0,0);
    66         // this->yaw = 0;
    67         // this->pitch = 0;
    6875        this->segments = 30;
    6976        this->minSize = 1;
     
    7582        this->fogDensity = 0.5;
    7683
    77         // Old from Pawn
     84        this->tiltAt = 0.0;
     85        this->tiltBy = 0.0; 
     86
    7887        this->registerVariables();
    7988
     
    8796
    8897        float myPi = 3.1415927410125732421875; //pi; // Math.pi ist statisch oder so.
    89         float dPhi = (2 * myPi) / segments;
    90         float width = radius1 - radius0; if(width<0){width = -width;} // predefined abs?
    91         float radius = (radius1 + radius0) / 2.0;
    92         int segmentCount = round(count / segments);
     98        float width = this->radius1 - this->radius0; if(width<0){width = -width;} // predefined abs?
     99        float radius = (this->radius1 + this->radius0) / 2.0;
     100        int segmentCount = round(this->count / this->segments);
    93101
    94         SpicedAsteroidField* af[segments];
     102        SpicedAsteroidField* af[this->segments];
    95103        (void)af[0]; // avoid nasty compiler warning
    96104
     105        float dPhi = (2 * myPi) / this->segments;
     106        float dTheta = 4.0*this->tiltBy/this->segments;
     107        float sepp = -this->tiltAt;
     108        float globi = (myPi/2.0) + this->tiltBy;
     109
    97110        for(int s = 0; s<segments; ++s){
    98             Vector3* pos = new Vector3(radius*cos(s*dPhi), radius*sin(s*dPhi),0);
     111            sepp = sepp + dPhi;
     112            if(s<segments/2){           
     113                globi = globi - dTheta;
     114            }else{
     115                globi = globi + dTheta;
     116            }
     117           
     118            Vector3* pos = new Vector3(radius*cos(sepp)*sin(globi), radius*sin(sepp)*sin(globi), radius*cos(globi));
    99119            af[s] = new SpicedAsteroidField(this->context, this->position + *pos, this->minSize, this->maxSize, width, segmentCount, this->foggy, this->mDensity, this->fogDensity);
     120           
    100121        }
    101122       
     
    109130        XMLPortParam(SpicedAsteroidBelt, "mDensity", setMineralDensity, getMineralDensity, xmlelement, mode);
    110131        XMLPortParam(SpicedAsteroidBelt, "position", setPosition, getPosition, xmlelement, mode);
    111         // XMLPortParam(SpicedAsteroidBelt, "yaw", setYaw, getYaw, xmlelement, mode);
    112         // XMLPortParam(SpicedAsteroidBelt, "pitch", setPitch, getPitch, xmlelement, mode);
    113132        XMLPortParam(SpicedAsteroidBelt, "segments", setSegments, getSegments, xmlelement, mode);
    114133
     
    119138        XMLPortParam(SpicedAsteroidBelt, "foggy", setFog, isFoggy, xmlelement, mode);
    120139        XMLPortParam(SpicedAsteroidBelt, "fogDensity", setFogDensity, getFogDensity, xmlelement, mode);
     140
     141        XMLPortParam(SpicedAsteroidBelt, "tiltAt", setTiltAt, getTiltAt, xmlelement, mode);
     142        XMLPortParam(SpicedAsteroidBelt, "tiltBy", setTiltBy, getTiltBy, xmlelement, mode);
    121143
    122144    }
     
    131153        registerVariable(this->mDensity, VariableDirection::ToClient);
    132154        registerVariable(this->position, VariableDirection::ToClient);
    133         // registerVariable(this->yaw, VariableDirection::ToClient);
    134         // registerVariable(this->pitch, VariableDirection::ToClient);
    135155        registerVariable(this->segments, VariableDirection::ToClient);
    136156
     
    141161        registerVariable(this->foggy, VariableDirection::ToClient);
    142162        registerVariable(this->fogDensity, VariableDirection::ToClient);
     163
     164        registerVariable(this->tiltAt, VariableDirection::ToClient);
     165        registerVariable(this->tiltBy, VariableDirection::ToClient);
    143166
    144167    }
Note: See TracChangeset for help on using the changeset viewer.