void ofxBoxObj::update(ofxParticleEmitter * _pEmit){ x = box->getPosition().x; y = box->getPosition().y; if ((ofRandom(0, 50) < 2) ) _pEmit->addParticle(ofPoint(x,y-getScaledHeight()*0.5)); };
void ofxBoxObj::draw(int _level){ ofSetColor(255, 255); box->draw(_level); ofPushMatrix(); ofTranslate(x-getScaledWidth()*0.5,y-getScaledHeight()*0.5); ofScale(scale, scale); if (*bDebug) drawBoundingBox(); ofPopMatrix(); }
void Font::printVl(frenda::System *sys, float x, float y, float z, int start, int printLen, const char *fmt, va_list vl) { unsigned char buf[1024]; vsnprintf((char*)buf, sizeof(buf), fmt, vl); if(start == -1) start = 0; if(printLen == -1) printLen = strlen((char*)buf); sys->pvr->setTexture(PVR_LIST_TR_POLY, texture); sys->pvr->sendPolygonHeader(PVR_LIST_TR_POLY); sys->pvr->beginPrimitives(PVR_LIST_TR_POLY); float cr = colorR, cg = colorG, cb = colorB, ca = colorA; float cx = x, cy = y; // TODO alpha not applied during rendering?! for(int i = start; i < start + printLen; i++) { if((buf[i] == '{' && buf[i + 1] == 'n') || buf[i] == '\n') { cx = x; cy += getScaledHeight(); if(buf[i] != '\n') i += 2; } else if(buf[i] == '{') { if(buf[i + 1] == 'c') { if(buf[i + 2] == '}') { cr = colorR; cg = colorG; cb = colorB; i += 2; } else { int r, g, b; sscanf((char*)&buf[i + 2], "%02x%02x%02x", &r, &g, &b); cr = ((unsigned char)r) / 255.0f; cg = ((unsigned char)g) / 255.0f; cb = ((unsigned char)b) / 255.0f; i += 8; } } else if(buf[i + 1] == 'a') { if(buf[i + 2] == '}') { ca = colorA; i += 2; } else { int a; sscanf((char*)&buf[i + 2], "%02x", &a); ca = ((unsigned char)a) / 255.0f; i += 4; } } else if(buf[i + 1] == 'p') { break; } } else { CharacterDataStruct *chdata = NULL; for(uint32 j = 0; j < characterList.characterCount; j++) { if(characterList.characters[j].characterCode == (uint32)buf[i]) { chdata = &characterList.characters[j]; break; } } if(chdata) { if(chdata->characterCode != 0x20) { float w = chdata->characterWidth, h = chdata->characterHeight; float u1 = (chdata->fontXCoord / texture->w); float u2 = ((chdata->fontXCoord + w) / texture->w); float v1 = (chdata->fontYCoord / texture->h); float v2 = ((chdata->fontYCoord + h) / texture->h); w *= scale; h *= scale; uint32 col = PVR_PACK_COLOR(ca, cr, cg, cb); sys->pvr->sendVertex03(PLX_VERT, cx, cy, z, u1, v1, col, 0); sys->pvr->sendVertex03(PLX_VERT, cx, cy + h, z, u1, v2, col, 0); sys->pvr->sendVertex03(PLX_VERT, cx + w, cy, z, u2, v1, col, 0); sys->pvr->sendVertex03(PLX_VERT_EOS, cx + w, cy + h, z, u2, v2, col, 0); cx += w; } else cx += (chdata->characterWidth * scale); } else cx += (12.0f * scale); } } sys->pvr->endPrimitives(); sys->pvr->setTexture(PVR_LIST_TR_POLY, NULL); sys->pvr->sendPolygonHeader(PVR_LIST_TR_POLY); }
const Graphics::Surface *QuickTimeDecoder::VideoTrackHandler::decodeNextFrame() { if (endOfTrack()) return 0; if (_reversed) { // Subtract one to place us on the frame before the current displayed frame. _curFrame--; // We have one "dummy" frame at the end to so the last frame is displayed // for the right amount of time. if (_curFrame < 0) return 0; // Decode from the last key frame to the frame before the one we need. // TODO: Probably would be wise to do some caching int targetFrame = _curFrame; _curFrame = findKeyFrame(targetFrame) - 1; while (_curFrame != targetFrame - 1) bufferNextFrame(); } const Graphics::Surface *frame = bufferNextFrame(); if (_reversed) { if (_holdNextFrameStartTime) { // Don't set the next frame start time here; we just did a seek _holdNextFrameStartTime = false; } else { // Just need to subtract the time _nextFrameStartTime -= getFrameDuration(); } } else { if (_holdNextFrameStartTime) { // Don't set the next frame start time here; we just did a seek _holdNextFrameStartTime = false; } else if (_durationOverride >= 0) { // Use our own duration from the edit list calculation _nextFrameStartTime += _durationOverride; _durationOverride = -1; } else { _nextFrameStartTime += getFrameDuration(); } // Update the edit list, if applicable // HACK: We're also accepting the time minus one because edit lists // aren't as accurate as one would hope. if (!atLastEdit() && getRateAdjustedFrameTime() >= getCurEditTimeOffset() + getCurEditTrackDuration() - 1) { _curEdit++; if (!atLastEdit()) enterNewEditList(true); } } if (frame && (_parent->scaleFactorX != 1 || _parent->scaleFactorY != 1)) { if (!_scaledSurface) { _scaledSurface = new Graphics::Surface(); _scaledSurface->create(getScaledWidth().toInt(), getScaledHeight().toInt(), getPixelFormat()); } _decoder->scaleSurface(frame, _scaledSurface, _parent->scaleFactorX, _parent->scaleFactorY); return _scaledSurface; } return frame; }
uint16 QuickTimeDecoder::VideoTrackHandler::getHeight() const { return getScaledHeight().toInt(); }
void Terrain::createTerrainMesh() { int i = 0, t = 0, t2 = 0; totalVerts = 0; totalTriangles = 0; if(vertex) delete[] vertex; if(texCoords) delete[] texCoords; if(texCoords2) delete[] texCoords2; //Sizes we need for the points/color and tex coords. int size = ((heightMap->getSizeX() - 1) * (heightMap->getSizeX() - 1) * 6) * 3; int tSize = ((heightMap->getSizeX() - 1) *(heightMap->getSizeX() - 1) * 6) * 2; vertex = new float[size]; texCoords = new float[tSize]; texCoords2 = new float[tSize]; // Loop through and generate a grid. Use the height map // when setting the Y to create the terrain mesh. Create 2 triangles // each iteration. for(int z = 0; z < heightMap->getSizeX() - 1; z++) { for(int x = 0; x < heightMap->getSizeX() - 1; x++) { // Calculate texture coords for these tris. float left = (float)x / heightMap->getSizeX(); float right = ((float)x + 1) / heightMap->getSizeX(); float bottom = (float)z / heightMap->getSizeX(); float top = (float)(z + 1) / heightMap->getSizeX(); // V1. texCoords[t++] = left * numRepeats;//0.0;//left; texCoords[t++] = bottom * numRepeats;//0.0;//bottom; texCoords2[t2++] = left;//left * numRepeats; texCoords2[t2++] = bottom;//bottom * numRepeats; vertex[i++] = (float)x; vertex[i++] = getScaledHeight(x, z); vertex[i++] = (float)z; totalVerts++; // LOGGER::getInstance().write("heightmap.log", "V1 texCords: %f textCoords: %f TexCoords2: %f texCoords2: %f X: %d Y: %f z: %d \n", left, bottom, left*numRepeats, bottom*numRepeats, x, getScaledHeight(x, z), z ); // V2. texCoords[t++] = left * numRepeats;//0.0;//left; texCoords[t++] = top * numRepeats;//1.0;//top; texCoords2[t2++] = left;//left * numRepeats; texCoords2[t2++] = top;//top * numRepeats; vertex[i++] = (float)x; vertex[i++] = getScaledHeight(x, z + 1); vertex[i++] = (float)z + 1; totalVerts++; // LOGGER::getInstance().write("heightmap.log", "V2 texCords: %f textCoords: %f TexCoords2: %f texCoords2: %f X: %d Y: %f z: %d \n", left, top, left*numRepeats, top*numRepeats, x, getScaledHeight(x, z+1), z+1 ); // V3. texCoords[t++] = right * numRepeats;//1.0;//right; texCoords[t++] = bottom * numRepeats;//0.0;//bottom; texCoords2[t2++] = right;//right * numRepeats; texCoords2[t2++] = bottom;//bottom * numRepeats; vertex[i++] = (float)x + 1; vertex[i++] = getScaledHeight(x + 1, z); vertex[i++] = (float)z; totalVerts++; //LOGGER::getInstance().write("heightmap.log", "V3 texCords: %f textCoords: %f TexCoords2: %f texCoords2: %f X: %d Y: %f z: %d \n", right, bottom, right*numRepeats, bottom*numRepeats, x+1, getScaledHeight(x+1, z), z ); // V4. texCoords[t++] = right * numRepeats;//1.0;//right; texCoords[t++] = bottom * numRepeats;//0.0;//bottom; texCoords2[t2++] = right;//right * numRepeats; texCoords2[t2++] = bottom;//bottom * numRepeats; vertex[i++] = (float)x + 1; vertex[i++] = getScaledHeight(x + 1, z); vertex[i++] = (float)z; totalVerts++; //LOGGER::getInstance().write("heightmap.log", "V4 texCords: %f textCoords: %f TexCoords2: %f texCoords2: %f X: %d Y: %f z: %d \n", right, bottom, right*numRepeats, bottom*numRepeats, x+1, getScaledHeight(x+1, z), z ); // V5. texCoords[t++] = right * numRepeats;//1.0;//right; texCoords[t++] = top * numRepeats;//1.0;//top; texCoords2[t2++] = right;//right * numRepeats; texCoords2[t2++] = top;//top * numRepeats; vertex[i++] = (float)x + 1; vertex[i++] = getScaledHeight(x + 1, z + 1); vertex[i++] = (float)z + 1; totalVerts++; //LOGGER::getInstance().write("heightmap.log", "V5 texCords: %f textCoords: %f TexCoords2: %f texCoords2: %f X: %d Y: %f z: %d \n", right, top, right*numRepeats, top*numRepeats, x+1, getScaledHeight(x+1, z+1), z+1 ); // V6. texCoords[t++] = left * numRepeats;//0.0;//left; texCoords[t++] = top * numRepeats;//1.0;//top; texCoords2[t2++] = left;//left * numRepeats; texCoords2[t2++] = top;//top * numRepeats; vertex[i++] = (float)x; vertex[i++] = getScaledHeight(x, z + 1); vertex[i++] = (float)z + 1; totalVerts++; //LOGGER::getInstance().write("heightmap.log", "V6 texCords: %f textCoords: %f TexCoords2: %f texCoords2: %f X: %d Y: %f z: %d \n", left, top, left*numRepeats, top*numRepeats, x, getScaledHeight(x, z+1), z+1 ); totalTriangles += 2; } } std::cout << "Total terrain triangles: " << totalTriangles << std::endl; }