/* * The animation creates a font polygon at the block's center * * The font polygon rises slowly and fades out after one second. */ void GameController::AnimatePointsMessage(const hdVec3& pos, int points, float scale) { hdVec2 screenPos; ConvertInterfaceToScreen(screenPos, pos.x, pos.y); hdFontPolygon* pointsFont = new hdFontPolygon(GAME_CONTROLLER_POINTS_FONT, "", NULL, screenPos.x, screenPos.y, 160.0f, 40.0f); pointsFont->SetTextFormatted("%d", points); pointsFont->SetTint(1.0f, 1.0f, hdClamp(scale-0.25f, 0.5f, 1.0f), 1.0f); pointsFont->SetAlpha(0.0f); pointsFont->SetScale(hdClamp(scale+0.25f, 1.0f, 2.0f)); pointsFont->AlignLeft(); m_animPolygons->Add(pointsFont); hdAnimation* transAnim = hdAnimationController::CreateAnimation(this); hdVectorAction* moveTo = new hdVectorAction(); moveTo->SetDuration(1.7f); moveTo->SetDestination(hdVec3(pointsFont->GetWorldCenter().x, screenPos.y + 100.0f, 0.0f)); transAnim->AddGameObject(pointsFont); transAnim->AddAction(moveTo); transAnim->SetFinishedCallback(this, GameController::PointsMessageCallback); transAnim->StartAnimation(); AnimateFadeInOut(pointsFont, 0.25f, 0.75f, 0.5f); }
void AppController::Step(double sysInterval, double fixedInterval) { #if (TARGET_IPHONE_SIMULATOR == 1) || (TARGET_OS_IPHONE == 1) hdAnimationController::Instance()->StepWithInterval(hdClamp(sysInterval, 0.016, 0.04)); #else hdAnimationController::Instance()->StepWithInterval(hdMin(fixedInterval, 0.04)); #endif activeController->Step(sysInterval); }
void AddVerticesForTQ(GLenum prim, hdVec3* vertices, hdVec2* textureCoordinates, const int vertexCount, hdTexture* texture, const float* colorTint, const float alpha) { hdglColor4f(colorTint[0], colorTint[1], colorTint[2], hdClamp(alpha, 0.0f, colorTint[3])); for (int i = 0; i < vertexCount; ++i) { if (texture != NULL) { hdglTexCoord2f(textureCoordinates[i].x, textureCoordinates[i].y); } hdglVertex3f(vertices[i].x, vertices[i].y, vertices[i].z); } }
void AppController::StartApp() { // Ensure we have a game dir hdAssert(strlen(FileSystem_BaseDir()) > 0); // Ensure config has been set up hdAssert(hdConfig::ConfigWasInitialized()); // Load user config LoadPlayerConfigFile(); loadingController = new LoadingController(this); #if DEBUG == 1 if (getenv("START_WORLD_OVERRIDE_PATH")) { m_levelPickerWorld = WorldManager::Instance()->FindTotemWorld(getenv("START_WORLD_OVERRIDE_PATH")); const char *levIdStr = getenv("START_WORLD_OVERRIDE_LEVELID"); m_levelId = (levIdStr) ? hdClamp(atoi(levIdStr), 0, m_levelPickerWorld->GetLevelCount() - 1) : 0; Level *lev = m_levelPickerWorld->GetLevels()[m_levelId]; EnsureGameController(); gameController->InitLevel(lev, 0); gameController->SetLevelStats(NULL); activeController = gameController; gameController->AnimateShow(); return; } else { introController = new IntroController(this); activeController = introController; introController->AnimateShow(); menuController = NULL; } #else introController = new IntroController(this); activeController = introController; introController->AnimateShow(); menuController = NULL; #endif }
void hdAlphaAction::Apply(hdTimeInterval elapsed, hdGameObject* gameObject) { float current; if (m_endAlpha > m_startAlpha) { current = (m_endAlpha - m_startAlpha) * ((m_progress) / m_duration); } else { current = 1.0f + (m_endAlpha - m_startAlpha) * ((m_progress) / m_duration); } current = hdClamp(current, 0.0f, 1.0f); gameObject->SetAlpha(current); #ifdef ANIMATION_DEBUG hdPrintf("Alpha Action:: Name: %d, Progress: %f, Elapsed: %f, New Alpha: %f\n", gameObject->GetName(), m_progress, elapsed, (float)current); #endif }
hdTextureManager::hdTextureManager() { m_textures = new hdPointerList<hdTexture, kMaxTextures>(); unsigned char *ptr; unsigned char *data; int x, y; // create a checkerboard texture data = (unsigned char*)calloc(1, 16 * 16 * 4 ); for( y = 0; y < 16; ++y ) { for( x = 0; x < 16; ++x ) { ptr = &data[ (y * 16 + x) * 4 ]; if( (y < 8) ^ (x < 8) ) { ptr[ 0 ] = ptr[ 1 ] = ptr[ 2 ] = 0x00; ptr[ 3 ] = 0xFF; } else { ptr[ 0 ] = ptr[ 1 ] = ptr[ 2 ] = 0xFF; ptr[ 3 ] = 0xFF; } } } m_nullTexture = this->LoadTexture( "***r_notexture***", data, 16, 16, TT_Pic, 4); free(data); maxTextureBPP = strtol(hdConfig::GetValueForKey(CONFIG_MAXTEXTUREBPP_KEY).c_str(), NULL, 0); maxTextureBPP = hdClamp(maxTextureBPP, 1, 8); m_textureQualityLevel = hdConfig::GetValueForKey(CONFIG_TEXTUREQUALITYLEVEL_KEY); hdglError("error after attempting to bind null texture"); }
void ScreenSettings_GetScaleFactor(float *outScaleFactor) { *outScaleFactor = hdClamp(screenSettings.scaleFactor, 1.0f, 10.0f); }
void DrawPrimitiveWithTint(GLenum prim, hdVec3* vertices, hdVec2* textureCoordinates, const int vertexCount, const hdAABB& aabb, hdTexture* texture, const float* colorTint, const float alpha) { GLboolean blendEnabled; GLint blendFuncSrc, blendFuncDst; if (vertexCount < 3) return; if (nullTexture == NULL) { nullTexture = hdTextureManager::Instance()->GetNullTexture(); } glMatrixMode(GL_MODELVIEW); if (texture == NULL || texture == nullTexture) { hdglBindTexture(NULL); } else { hdglBindTexture(texture); if (texture->isPremultipliedAlpha) { glGetBooleanv(GL_BLEND, &blendEnabled); glGetIntegerv(GL_BLEND_SRC, &blendFuncSrc); glGetIntegerv(GL_BLEND_DST, &blendFuncDst); if (hdClamp(alpha, 0.0f, colorTint[3]) == 1.0f) { glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); } else { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } } } hdVec3 center(0.0f, 0.0f, 0.0f); hdglBegin(prim); hdglColor4f(colorTint[0], colorTint[1], colorTint[2], hdClamp(alpha, 0.0f, colorTint[3])); for (int i = 0; i < vertexCount; ++i) { hdVec3 v = center + vertices[i]; if (textureCoordinates != NULL && texture != nullTexture) { hdglTexCoord2f(textureCoordinates[i].x, textureCoordinates[i].y); } hdglVertex3f(v.x, v.y, v.z); } hdglEnd(); if (texture && texture != nullTexture) { if (texture->isPremultipliedAlpha) { glBlendFunc(blendFuncSrc, blendFuncDst); } } #ifdef LEVEL_EDITOR hdglBegin(GL_LINE_LOOP); hdglColor4f(0.0f, 0.0f, 0.0f, hdClamp(alpha, 0.0f, colorTint[3])); for (int32 i = 0; i < vertexCount; ++i) { hdVec3 v = center + vertices[i]; hdglVertex3f(v.x, v.y, v.z); } hdglEnd(); #endif }
/* * This is a very crappy per vertex shader. * * Code below takes a normal for each vertex pair (perpendicular. to line made by pair), * and then calculates the light for the quad as a modification to the tint. Light is * an ambient value pointing along the negative y axis. * * Perform normal smoothing by taking the average normal of adjacent vertex pairs and using a * texture combine at 2x the rgb scale so brights look brighter and darks look darker. It looks * surprisingly good. * * UPDATE: This function was written before OpenGLES support was any good on iOS. * Colors were calculated by using matrices, to take advantage of the * internal matrix functions that use the SIMD floating point operations on NEON and VFPU * chips. */ void DrawExtrusionLighting(hdVec3* vertices, hdVec2* textureCoordinates, const int vertexCount, const hdAABB& aabb, hdTexture* texture, const float* colorTint, const float alpha, const float depth,bool reflected, const hdVec3& screenCenter) { unsigned i; short i1, i2, i3, i4, stride; hdMatrix inColors, normals, outColors; float fAlpha; float lightNormal; float prevNormal, currNormal, nextNormal; float norm0, norm1; unsigned char precalcAlpha; lightNormal = 0.0f; prevNormal = Get2DNormal(vertices[vertexCount - 1], vertices[0]); currNormal = Get2DNormal(vertices[0], vertices[1]); nextNormal = Get2DNormal(vertices[1], vertices[2]); float firstVertexNormal, secondVertexNormal; /* * Precalcs */ precalcAlpha = hdClamp((int)(255 * alpha), 0, (int)(255 * colorTint[3])); fAlpha = hdClamp(alpha, 0.0f, colorTint[3]); MatrixIdentity(inColors); MatrixIdentity(normals); MatrixIdentity(outColors); #if (TARGET_IPHONE_SIMULATOR == 0) && (TARGET_OS_IPHONE == 1) && defined(__ARM_NEON__) for(i=0; i < 16; ++i) { inColors.f[i] = colorTint[i >> 2]; } #else for(i=0; i < 16; ++i) { inColors.f[i] = colorTint[i & 3]; } #endif for (int i = 0; i < vertexCount; ++i) { i1 = i; i2 = ((i+1) >= vertexCount) ? (i+1)-vertexCount : (i+1); // shitty modulus i3 = ((i+2) >= vertexCount) ? (i+2)-vertexCount : (i+2); i4 = ((i+3) >= vertexCount) ? (i+3)-vertexCount : (i+3); stride = i * 4; hdVec3 normal = vertices[i2] - vertices[i1]; // no smoothing for objects with sharp angles // TODO: use angle beween i1, i2, i3 for this. if (vertexCount < 6) { lightNormal = hdClamp((1.0f + currNormal) * SHADING_MODIFIER, 0.25f, 1.0f); norm0 = FRONT_VERTEX_SHADE * lightNormal; norm1 = BACK_VERTEX_SHADE * lightNormal; normals.f[__11] = norm0; normals.f[__22] = norm1; normals.f[__33] = norm1; normals.f[__44] = norm0; hdMatrixMultiply(outColors, inColors, normals); } else { firstVertexNormal = hdClamp((1.0f + (prevNormal + currNormal) * 0.5f) * SHADING_MODIFIER, 0.2f, 1.0f); secondVertexNormal = hdClamp((1.0f + (currNormal + nextNormal) * 0.5f) * SHADING_MODIFIER, 0.2f, 1.0f); normals.f[__11] = FRONT_VERTEX_SHADE * firstVertexNormal; normals.f[__22] = BACK_VERTEX_SHADE * firstVertexNormal; normals.f[__33] = BACK_VERTEX_SHADE * secondVertexNormal; normals.f[__44] = FRONT_VERTEX_SHADE * secondVertexNormal; hdMatrixMultiply(outColors, inColors, normals); } //BIG HACK // HACK HACK HACK // Vals come out of NEON in the wrong order. #if (TARGET_IPHONE_SIMULATOR == 0) && (TARGET_OS_IPHONE == 1) && defined(__ARM_NEON__) if (texture != NULL) { hdglTexCoord2f(textureCoordinates[0 + stride].x, textureCoordinates[0 + stride].y); } hdglColor4f(outColors.f[__11], outColors.f[__12], outColors.f[__13], fAlpha); hdglVertex3f(vertices[i1].x, vertices[i1].y, vertices[i1].z - depth); if (texture != NULL) { hdglTexCoord2f(textureCoordinates[1 + stride].x, textureCoordinates[1 + stride].y); } hdglColor4f(outColors.f[__21], outColors.f[__22], outColors.f[__23], fAlpha); hdglVertex3f(vertices[i1].x, vertices[i1].y, vertices[i1].z + depth); if (texture != NULL) { hdglTexCoord2f(textureCoordinates[2 + stride].x, textureCoordinates[2 + stride].y); } hdglColor4f(outColors.f[__31], outColors.f[__32], outColors.f[__33], fAlpha); hdglVertex3f(vertices[i2].x, vertices[i2].y, vertices[i2].z + depth); if (texture != NULL) { hdglTexCoord2f(textureCoordinates[3 + stride].x, textureCoordinates[3 + stride].y); } hdglColor4f(outColors.f[__41], outColors.f[__42], outColors.f[__43], fAlpha); hdglVertex3f(vertices[i2].x, vertices[i2].y, vertices[i2].z - depth); #else if (texture != NULL) { hdglTexCoord2f(textureCoordinates[0 + stride].x, textureCoordinates[0 + stride].y); } hdglColor4f(outColors.f[__11], outColors.f[__21], outColors.f[__31], fAlpha); hdglVertex3f(vertices[i1].x, vertices[i1].y, vertices[i1].z - depth); if (texture != NULL) { hdglTexCoord2f(textureCoordinates[1 + stride].x, textureCoordinates[1 + stride].y); } hdglColor4f(outColors.f[__12], outColors.f[__22], outColors.f[__32], fAlpha); hdglVertex3f(vertices[i1].x, vertices[i1].y, vertices[i1].z + depth); if (texture != NULL) { hdglTexCoord2f(textureCoordinates[2 + stride].x, textureCoordinates[2 + stride].y); } hdglColor4f(outColors.f[__13], outColors.f[__23], outColors.f[__33], fAlpha); hdglVertex3f(vertices[i2].x, vertices[i2].y, vertices[i2].z + depth); if (texture != NULL) { hdglTexCoord2f(textureCoordinates[3 + stride].x, textureCoordinates[3 + stride].y); } hdglColor4f(outColors.f[__14], outColors.f[__24], outColors.f[__34], fAlpha); hdglVertex3f(vertices[i2].x, vertices[i2].y, vertices[i2].z - depth); #endif prevNormal = currNormal; currNormal = nextNormal; nextNormal = Get2DNormal(vertices[i3], vertices[i4]); } }
void DrawExtrusionFlatQuad(hdVec3* vertices, hdVec2* textureCoordinates, const int vertexCount, const hdAABB& aabb, hdTexture* texture, const float* colorTint, const float alpha, const float depth, bool reflected, const hdVec3& screenCenter) { short i1, i2, stride; hdVec3 normal; hdColor4 frontColor, backColor; frontColor.Setf(colorTint[0] * FLAT_FRONT_VERTEX_SHADE, colorTint[1] * FLAT_FRONT_VERTEX_SHADE, colorTint[2] * FLAT_FRONT_VERTEX_SHADE, hdClamp(alpha, 0.0f, colorTint[3])); backColor.Setf(colorTint[0] * FLAT_BACK_VERTEX_SHADE, colorTint[1] * FLAT_BACK_VERTEX_SHADE, colorTint[2] * FLAT_BACK_VERTEX_SHADE, hdClamp(alpha, 0.0f, colorTint[3])); for (int i = 0; i < vertexCount; ++i) { i1 = i; i2 = ((i+1) >= vertexCount) ? (i+1)-vertexCount : (i+1); stride = i * 4; normal = vertices[i2] - vertices[i1]; if (texture != NULL) { hdglTexCoord2f(textureCoordinates[0 + stride].x, textureCoordinates[0 + stride].y); } hdglColor4ub(frontColor.r, frontColor.g, frontColor.b, frontColor.a); hdglVertex3f(vertices[i1].x, vertices[i1].y, vertices[i1].z - depth); if (texture != NULL) { hdglTexCoord2f(textureCoordinates[1 + stride].x, textureCoordinates[1 + stride].y); } hdglColor4ub(backColor.r, backColor.g, backColor.b, backColor.a); hdglVertex3f(vertices[i1].x, vertices[i1].y, vertices[i1].z + depth); if (texture != NULL) { hdglTexCoord2f(textureCoordinates[2 + stride].x, textureCoordinates[2 + stride].y); } hdglColor4ub(backColor.r, backColor.g, backColor.b, backColor.a); hdglVertex3f(vertices[i2].x, vertices[i2].y, vertices[i2].z + depth); if (texture != NULL) { hdglTexCoord2f(textureCoordinates[3 + stride].x, textureCoordinates[3 + stride].y); } hdglColor4ub(frontColor.r, frontColor.g, frontColor.b, frontColor.a); hdglVertex3f(vertices[i2].x, vertices[i2].y, vertices[i2].z - depth); } }