void GFXGLCubemap::tmResurrect() { if(mDynamicTexSize) initDynamic(mDynamicTexSize,mFaceFormat); else { if ( mDDSFile ) initStatic( mDDSFile ); else initStatic( mTextures ); } }
NS_L2D_BEGIN SPImageSprite ImageSprite::create(const std::string &fileName, int width, int height) { if (!_staticInited) initStatic(); return SPImageSprite(new ImageSprite(fileName, width, height)); }
void GFXCubemap::initNormalize( U32 size ) { Point3F axis[6] = {Point3F(1.0, 0.0, 0.0), Point3F(-1.0, 0.0, 0.0), Point3F(0.0, 1.0, 0.0), Point3F( 0.0, -1.0, 0.0), Point3F(0.0, 0.0, 1.0), Point3F( 0.0, 0.0, -1.0),}; Point3F s[6] = {Point3F(0.0, 0.0, -1.0), Point3F( 0.0, 0.0, 1.0), Point3F(1.0, 0.0, 0.0), Point3F( 1.0, 0.0, 0.0), Point3F(1.0, 0.0, 0.0), Point3F(-1.0, 0.0, 0.0),}; Point3F t[6] = {Point3F(0.0, -1.0, 0.0), Point3F(0.0, -1.0, 0.0), Point3F(0.0, 0.0, 1.0), Point3F(0.0, 0.0, -1.0), Point3F(0.0, -1.0, 0.0), Point3F(0.0, -1.0, 0.0),}; F32 span = 2.0; F32 start = -1.0; F32 stride = span / F32(size - 1); GFXTexHandle faces[6]; for(U32 i=0; i<6; i++) { GFXTexHandle &tex = faces[i]; GBitmap *bitmap = new GBitmap(size, size); // fill in... for(U32 v=0; v<size; v++) { for(U32 u=0; u<size; u++) { Point3F vector; vector = axis[i] + ((F32(u) * stride) + start) * s[i] + ((F32(v) * stride) + start) * t[i]; vector.normalizeSafe(); vector = ((vector * 0.5) + Point3F(0.5, 0.5, 0.5)) * 255.0; vector.x = mClampF(vector.x, 0.0f, 255.0f); vector.y = mClampF(vector.y, 0.0f, 255.0f); vector.z = mClampF(vector.z, 0.0f, 255.0f); // easy way to avoid knowledge of the format (RGB, RGBA, RGBX, ...)... U8 *bits = bitmap->getAddress(u, v); bits[0] = U8(vector.x); bits[1] = U8(vector.y); bits[2] = U8(vector.z); } } tex.set(bitmap, &GFXDefaultStaticDiffuseProfile, true, "Cubemap"); } initStatic(faces); }
Model::Model(std::string name, bool forceAnim) : ManagedItem(name), forceAnim(forceAnim) { // replace .MDX with .M2 char tempname[256]; strcpy(tempname,name.c_str()); tempname[name.length()-2] = '2'; tempname[name.length()-1] = 0; MPQFile f(tempname); ok = !f.isEof(); if (!ok) { gLog("Error loading model [%s]\n", tempname); return; } memcpy(&header, f.getBuffer(), sizeof(ModelHeader)); // HACK: these particle systems are way too active and cause horrible horrible slowdowns // I'm removing them until I can fix emission speed so it doesn't get this crazy if (false || name=="World\\Kalimdor\\Orgrimmar\\Passivedoodads\\Orgrimmarbonfire\\Orgrimmarsmokeemitter.Mdx" //|| name=="World\\Kalimdor\\Orgrimmar\\Passivedoodads\\Orgrimmarbonfire\\Orgrimmarbonfire01.Mdx" ) { header.nParticleEmitters = 0; } animated = isAnimated(f) || forceAnim; // isAnimated will set animGeometry and animTextures gLog("Loading model %s%s\n", tempname, animated ? " (animated)" : ""); trans = 1.0f; vbuf = nbuf = tbuf = 0; globalSequences = 0; animtime = 0; anim = 0; colors = 0; lights = 0; transparency = 0; particleSystems = 0; ribbons = 0; if (header.nGlobalSequences) { globalSequences = new int[header.nGlobalSequences]; memcpy(globalSequences, (f.getBuffer() + header.ofsGlobalSequences), header.nGlobalSequences * 4); } if (animated) initAnimated(f); else initStatic(f); f.close(); }
// on "init" you need to initialize your instance bool HelloBom::init() { initStatic(); ////////////////////////////// // 1. super init first if (!Layer::init()) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Point origin = Director::getInstance()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object auto closeItem = MenuItemImage::create( "CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(HelloBom::menuCloseCallback, this)); closeItem->setPosition(Point(origin.x + visibleSize.width - closeItem->getContentSize().width / 2, origin.y + closeItem->getContentSize().height / 2)); // create menu, it's an autorelease object auto menu = Menu::create(closeItem, NULL); menu->setPosition(Point::ZERO); this->addChild(menu, 1); b2Vec2 gravity; gravity.Set(0.0f, -9.8f); world = new b2World(gravity); world->SetAllowSleeping(true); world->SetContinuousPhysics(true); b2BodyDef backgroundef; backgroundef.position.Set(0, 0); b2Body *body = world->CreateBody(&backgroundef); b2Vec2 bottomLeft; bottomLeft.Set(0, 0); b2Vec2 bottomRight; bottomRight.Set(width_game, 0); b2Vec2 topLeft; topLeft.Set(0, height_game*50); b2Vec2 topRight; topRight.Set(width_game,height_game*50); b2EdgeShape bottomshape; bottomshape.Set(bottomLeft, bottomRight); body->CreateFixture(&bottomshape, 0); b2EdgeShape leftshape; leftshape.Set(bottomLeft, topLeft); body->CreateFixture(&leftshape, 0); b2EdgeShape rightshape; rightshape.Set(bottomRight, topRight); body->CreateFixture(&rightshape, 0); startGame(); return true; }