Changeset 11640 for code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc
- Timestamp:
- Dec 4, 2017, 4:38:17 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc
r11615 r11640 31 31 * 32 32 * 33 *<OFFEN Describe 33 *<OFFEN Describe 34 Math from asteroidField.lua used. 34 35 * 35 36 * 37 38 39 DESCRIPTION 40 o Andere: Simpel wie in asteroidField.lua, oder einfach Asteroiden, die nichts abwerfen? 41 --> Letzteres scheint passender, simpler. 42 36 43 37 44 */ … … 77 84 RegisterClass(SpicedAsteroidField); 78 85 79 SpicedAsteroidField::SpicedAsteroidField(Context* context) {86 SpicedAsteroidField::SpicedAsteroidField(Context* context) : Pawn(context) { 80 87 81 88 // Da auch noetig? Wegen set in XML-Code? … … 83 90 84 91 this->context = context; 85 this->initialised = false; 86 87 //Noetig, damit nicht sofort zerstoert? 88 this->setCollisionType(WorldEntity::CollisionType::Dynamic); 92 this->foggy = true; 93 this->fogDensity = 0.5; 89 94 90 95 // Old from Pawn 91 96 this->registerVariables(); 92 97 93 orxout() << "AsteroidMining:: Pseudo-Konstruktor passiert!" << endl; 94 98 99 // this->create(); 100 this->bAlive_ = false; 101 this->destroyLater(); 95 102 } 96 103 … … 101 108 void SpicedAsteroidField::create(){ 102 109 103 104 105 110 int size; 111 int pX; 112 int pY; 113 int pZ; 114 115 Vector3* relPos; 116 117 for(int gertrud = 0; gertrud<count; ++gertrud){ 118 119 AsteroidMinable* a = new AsteroidMinable(this->context); 120 121 size = round(rnd()*(this->maxSize - this->minSize)) + this->minSize; 122 a->setSize(size); 123 124 pX = round(rnd()*2*this->radius) - radius; 125 pY = round(rnd()*2*this->radius) - radius; 126 pZ = round(rnd()*2*this->radius) - radius; 127 relPos = new Vector3(pX, pY, pZ); 128 a->setPosition(this->position + *relPos); 129 130 bool spiced = (rnd() < (this->mDensity)); // does drop pickups etc. 131 a->toggleDropStuff(spiced); 132 133 // @TODO: Fox Fog stuff, error due to billbord 134 135 // Billboard* bb; 136 // if(this->foggy && mod(gertrud, 5) == 0){ 137 // bb = new Billboard(this->context); 138 // bb->setPosition(this-position + *relPos); 139 // bb->setMaterial("Smoke/Smoke"); 140 // bb->setScale(size); // tricky? 141 142 // bb->setColour(ColourValue(this-fogDensity, this->fogDensity, this->fogDensity)); // 4rd argument = transparency? 143 144 // // print("<Billboard ") 145 // // print("position = \"") 146 // // print(posX) print(",") 147 // // print(posY) print(",") 148 // // print(posZ) print("\" ") 149 // // print("colour=\"") 150 // // print(brightness) print(",") 151 // // print(brightness) print(",") 152 // // print(brightness) print("\" ") 153 // // print("material=\"Smoke/Smoke\" scale=") 154 // // print(size) 155 // // print(" />") 156 // } 157 } 106 158 } 107 159 108 160 void SpicedAsteroidField::XMLPort(Element& xmlelement, XMLPort::Mode mode) 109 161 { 110 SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode);162 // SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode); 111 163 // XMLPortParam(PickupSpawner, "pickup", setPickupTemplateName, getPickupTemplateName, xmlelement, mode); 112 164 XMLPortParam(SpicedAsteroidField, "count", setCount, getCount, xmlelement, mode); … … 117 169 XMLPortParam(SpicedAsteroidField, "radius", setRadius, getRadius, xmlelement, mode); 118 170 XMLPortParam(SpicedAsteroidField, "foggy", setFog, isFoggy, xmlelement, mode); 119 171 XMLPortParam(SpicedAsteroidField, "fogDensity", setFogDensity, getFogDensity, xmlelement, mode); 120 172 121 173 } … … 126 178 void SpicedAsteroidField::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) 127 179 { 128 SUPER(SpicedAsteroidField, XMLEventPort, xmlelement, mode);180 // SUPER(SpicedAsteroidField, XMLEventPort, xmlelement, mode); 129 181 130 182 XMLPortEventState(SpicedAsteroidField, BaseObject, "vulnerability", setVulnerable, xmlelement, mode); … … 133 185 void SpicedAsteroidField::registerVariables() 134 186 { 135 // registerVariable(this->bAlive_, VariableDirection::ToClient); 136 // registerVariable(this->bVulnerable_, VariableDirection::ToClient); 137 // registerVariable(this->health_, VariableDirection::ToClient); 138 // registerVariable(this->maxHealth_, VariableDirection::ToClient); 139 140 registerVariable(this->size, VariableDirection::ToClient); 141 registerVariable(this->generateSmaller, VariableDirection::ToClient); 142 143 registerVariable(this->initialised, VariableDirection::ToClient); 144 //registerVariable(this->context, VariableDirection::ToClient); // can't link that since it's a context 145 146 147 // float size; 148 // bool generateSmaller; 149 // bool initialised; 150 151 // Context* context; 152 } 153 154 void SpicedAsteroidField::tick(float dt) 155 { 187 188 registerVariable(this->count, VariableDirection::ToClient); 189 registerVariable(this->mDensity, VariableDirection::ToClient); 190 registerVariable(this->position, VariableDirection::ToClient); 191 registerVariable(this->maxSize, VariableDirection::ToClient); 192 registerVariable(this->minSize, VariableDirection::ToClient); 193 registerVariable(this->radius, VariableDirection::ToClient); 194 registerVariable(this->foggy, VariableDirection::ToClient); 195 registerVariable(this->fogDensity, VariableDirection::ToClient); 196 197 198 } 199 200 void SpicedAsteroidField::tick(float dt){ 156 201 157 202 this->create(); 158 this->~SpicedAsteroidField(); // seems dangerous. Necessary for efficiency? 159 160 203 this->bAlive_ = false; 204 this->destroyLater(); 161 205 } 162 206 … … 166 210 167 211 } 212 213 // --[[ fog generator 214 // generates fog 215 // posX, posY, posZ - position in space 216 // size - size of billboard 217 // brightness - [0,1] fog brightness 218 // --]] 219 // function generateFog(posX, posY, posZ, size, brightness) 220 // print("<Billboard ") 221 // print("position = \"") 222 // print(posX) print(",") 223 // print(posY) print(",") 224 // print(posZ) print("\" ") 225 // print("colour=\"") 226 // print(brightness) print(",") 227 // print(brightness) print(",") 228 // print(brightness) print("\" ") 229 // print("material=\"Smoke/Smoke\" scale=") 230 // print(size) 231 // print(" />") 232 // end 233 234 // --[[ asteroid field generator 235 // generates asteroid field 236 // posX, posY, posZ - position in space 237 // minSize, maxSize - size boundaries of each asteroid 238 // radius - size of the cube around position in space 239 // count - number of asteroids 240 // fog - enable fog 0/1 241 // --]] 242 // function asteroidField(posX, posY, posZ, minSize, maxSize, radius, count, fog) 243 // for i = 1, count, 1 do 244 // size = (math.random() * (maxSize - minSize)) + minSize 245 // pX = (2 * math.random() * radius) - radius + posX 246 // pY = (2 * math.random() * radius) - radius + posY 247 // pZ = (2 * math.random() * radius) - radius + posZ 248 // print("<StaticEntity ") 249 250 // print("position = \"") 251 // print(pX) print(",") 252 // print(pY) print(",") 253 // print(pZ) print("\" ") 254 255 // print("scale = \"") print(size) print("\" ") 256 257 // print("collisionType = static linearDamping = 0.8 angularDamping = 1 ") 258 // print("collisiondamage = 1000 enablecollisiondamage = true>") 259 260 // print("<attached>") 261 // print("<Model mass=\"") print(size * 10) print("\" ") 262 // print("mesh=\"ast") print(math.mod(i,6) + 1) print(".mesh\" />") 263 // print("</attached>") 264 265 // print("<collisionShapes> ") 266 // print("<SphereCollisionShape radius=\"") 267 // print(size * 2.5) print("\" />") 268 // print("</collisionShapes>") 269 270 // print("</StaticEntity>") 271 272 // if fog == 1 and i % 5 == 0 then 273 // generateFog(pX, pY, pZ, radius*0.04, 0.2) 274 // end 275 // end 276 // end 277 278 279 // --[[ asteroid belt generator 280 // generates asteroid belt 281 // posX, posY, posZ - position in space 282 // yaw, pitch - rotation 283 // minSize, maxSize - size boundaries of each asteroid 284 // radius0, radius1 - inner/outer radius 285 // count - number of asteroids 286 // fog - enable fog 0/1 287 // --]] 288 // function asteroidBelt(centerX, centerY, centerZ, yaw, pitch, segments, minSize, maxSize, radius0, radius1, count, fog) 289 // dPhi = (2 * math.pi) / segments 290 // width = math.abs(radius1 - radius0) 291 // radius = (radius1 + radius0) / 2 292 // segmentCount = count / segments 293 294 // print("<StaticEntity collisionType=static yaw=") print(yaw) 295 // print(" pitch=") print(pitch) 296 297 // print(" position = \"") 298 // print(centerX) print(",") 299 // print(centerY) print(",") 300 // print(centerZ) print("\"") 301 // print(">") 302 303 // print("<attached>") 304 305 // for i = 0, segments - 1, 1 do 306 // asteroidField((radius * math.cos(i * dPhi)), 307 // (radius * math.sin(i * dPhi)), 308 // 0, minSize, maxSize, width, segmentCount, fog) 309 // end 310 311 // print("</attached>") 312 // print("</StaticEntity>") 313 // end
Note: See TracChangeset
for help on using the changeset viewer.