void M3Truck::draw(WarDraw *wd){ if(!w) return; /* cull object */ if(wd->vw->gc->cullFrustum(pos, getHitRadius())) return; double pixels = getHitRadius() * fabs(wd->vw->gc->scale(pos)); if(pixels < 2) return; wd->lightdraws++; static Motion *steerMotion = NULL; static Motion *turretYawMotion = NULL; static Motion *turretPitchMotion = NULL; static OpenGLState::weak_ptr<bool> init; if(!init){ model = LoadMQOModel(modPath() << _SC("models/m3truck1.mqo")); steerMotion = LoadMotion(modPath() << "models/m3truck-steer.mot"); turretYawMotion = LoadMotion(modPath() << "models/m3truck-turretyaw.mot"); turretPitchMotion = LoadMotion(modPath() << "models/m3truck-turretpitch.mot"); init.create(*openGLState); }; if(model){ glPushMatrix(); { Mat4d mat; transform(mat); glMultMatrixd(mat); } MotionPose mp[3]; steerMotion->interpolate(mp[0], steer / getMaxSteeringAngle() * 10. + 10.); turretYawMotion->interpolate(mp[1], fmod(turrety / M_PI * 20. + 20., 40.)); mp[0].next = &mp[1]; turretPitchMotion->interpolate(mp[2], barrelp / M_PI * 20. + 10.); mp[1].next = &mp[2]; /* center of gravity offset */ glTranslated(0, -getLandOffset(), 0); // Unlike most ModelEntities, Tank's model need not be rotated 180 degrees because // the model is made such way. glScaled(-modelScale, modelScale, -modelScale); DrawMQOPose(model, mp); glPopMatrix(); } }
void Tank::draw(WarDraw *wd){ static Motion *turretYawMotion = NULL; static Motion *barrelPitchMotion = NULL; if(!w) return; /* cull object */ if(wd->vw->gc->cullFrustum(pos, getHitRadius())) return; double pixels = getHitRadius() * fabs(wd->vw->gc->scale(pos)); if(pixels < 2) return; wd->lightdraws++; static OpenGLState::weak_ptr<bool> init; if(!init){ model = LoadMQOModel(modPath() << _SC("models/type90.mqo")); turretYawMotion = LoadMotion(modPath() << "models/type90-turretyaw.mot"); barrelPitchMotion = LoadMotion(modPath() << "models/type90-barrelpitch.mot"); init.create(*openGLState); }; if(model){ // TODO: We'd like to apply the team colors to the model sometime. // GLfloat fv[4] = {.8f, .5f, 0.f, 1.f}, ambient[4] = {.4f, .25f, 0.f, 1.f}; // if(race % 2) // fv[0] = 0., fv[2] = .8f, ambient[0] = 0., ambient[2] = .4f; glPushMatrix(); { Mat4d mat; transform(mat); glMultMatrixd(mat); } /* center of gravity offset */ glTranslated(0, -getLandOffset(), 0); MotionPose mp[2]; turretYawMotion->interpolate(mp[0], fmod(turrety / M_PI * 20. + 20., 40.)); barrelPitchMotion->interpolate(mp[1], barrelp / M_PI * 20. + 10.); mp[0].next = &mp[1]; // Unlike most ModelEntities, Tank's model need not be rotated 180 degrees because // the model is made such way. glScaled(modelScale, modelScale, modelScale); DrawMQOPose(model, mp); glPopMatrix(); } }
void SpacePlane::init(){ static bool initialized = false; if(!initialized){ sq_init(modPath() << _SC("models/SpacePlane.nut"), ModelScaleProcess(modelScale) <<= SingleDoubleProcess(hitRadius, _SC("hitRadius")) <<= MassProcess(defaultMass) <<= SingleDoubleProcess(maxHealthValue, _SC("maxhealth"), false) <<= Vec3dListProcess(engines, _SC("engines")) <<= DrawOverlayProcess(overlayDisp) ); initialized = true; } undocktime = 0.f; health = getMaxHealth(); mass = defaultMass; people = RandomSequence((unsigned long)this).next() % 100 + 100; engineHeat = 0.f; pf.resize(engines.size()); for(int i = 0; i < pf.size(); i++) pf[i] = NULL; }
void M3Truck::drawCockpit(WarDraw *wd){ if(!w) return; Player *player = game->player; if(player->getChaseCamera() != 0 || player->mover != player->cockpitview || player->mover != player->nextmover) return; static Model *cockpitModel = NULL; static Motion *handleMotion = NULL; static OpenGLState::weak_ptr<bool> init; if(!init){ cockpitModel = LoadMQOModel(modPath() << _SC("models/m3truck1_cockpit.mqo")); handleMotion = LoadMotion(modPath() << "models/m3truck-handle.mot"); init.create(*openGLState); }; if(!cockpitModel) return; Vec3d seat = cameraPositions[0] + Vec3d(0, getLandOffset(), 0); MotionPose mp[1]; handleMotion->interpolate(mp[0], steer / getMaxSteeringAngle() * 10. + 10.); glPushAttrib(GL_DEPTH_BUFFER_BIT); glClearDepth(1.); glClear(GL_DEPTH_BUFFER_BIT); glPushMatrix(); glLoadMatrixd(wd->vw->rot); gldMultQuat(this->rot); gldTranslaten3dv(seat); glScaled(-modelScale, modelScale, -modelScale); DrawMQOPose(cockpitModel, mp); glPopMatrix(); glPopAttrib(); }
CharBuffer Manager::read(const char* path) { FILE *const fi = fopen( modPath(path), "rb" ); if(!fi) return CharBuffer(); fseek(fi,0,SEEK_END); const int len = ftell(fi); fseek(fi,0,SEEK_SET); CharBuffer text = new Array<char>(len+1); fread( text->base, len,1,fi ); text->base[len] = '\0'; fclose(fi); return text; }