bool RenderObject::isPieceFlippedHorizontal() { RenderObject *p = getTopParent(); if (p) return p->isfh(); return isfh(); }
void RenderObject::matrixChain() { if (parent) parent->matrixChain(); #ifdef BBGE_BUILD_OPENGL glTranslatef(position.x+offset.x, position.y+offset.y, 0); glRotatef(rotation.z+rotationOffset.z, 0, 0, 1); glTranslatef(beforeScaleOffset.x, beforeScaleOffset.y, 0); glScalef(scale.x, scale.y, 0); if (isfh()) { //glDisable(GL_CULL_FACE); glRotatef(180, 0, 1, 0); } glTranslatef(internalOffset.x, internalOffset.y, 0); #endif }
void Quad::spawnChildClone(float t) { if (!this->texture) return; Quad *q = new Quad; q->setTexture(this->texture->name); q->setLife(t+0.1f); q->setDecayRate(1); q->width = this->width; q->height = this->height; q->alpha = 1; q->alpha.interpolateTo(0, t); if (isfh()) q->flipHorizontal(); q->position = this->position; q->followCamera = this->followCamera; q->scale = this->scale; q->offset = this->offset; q->blendType = this->blendType; //q->parentManagedPointer = true; //q->renderBeforeParent = false; core->getTopStateData()->addRenderObject(q, this->layer); //addChild(q); }
void SchoolFish::onUpdate(float dt) { BBGE_PROF(SchoolFish_onUpdate); /* Quad::onUpdate(dt); return; */ /* if (dsq->continuity.form == FORM_BEAST) this->activationType = ACT_CLICK; else this->activationType = ACT_NONE; */ /* if (burstDelay == 0) { maxSpeedLerp = 2; Vector v = getNormal(); vel = 0; v *= -5000; vel += v; //float t = (100 + rand()%100)/100.0; float t = 2; maxSpeedLerp.interpolateTo(1, t); burstDelay = 10;// + (rand()%100)/100.0; //rotateToVec(v, 0, 90); //rotation.interpolateTo(0, 1); if (v.x > 0 && !isfh()) { flipHorizontal(); flipDelay = 0.5; } if (v.x < 0 && isfh()) { flipHorizontal(); flipDelay = 0.5; } } else */ { burstDelay -= dt; if (burstDelay < 0) { burstDelay = 0; } } if (stickToNaijasHead && alpha.x < 0.1) stickToNaijasHead = false; if (this->layer < LR_ENTITIES) { //debugLog("background fish!"); /* setDamageTarget(DT_AVATAR_SHOCK, false); setDamageTarget(DT_AVATAR_BITE, false); setDamageTarget(DT_AVATAR_VOMIT, false); setDamageTarget(DT_AVATAR_ENERGYBLAST, false); */ setEntityType(ET_NEUTRAL); collideRadius = 0; } if (getState() == STATE_DEAD) { FlockEntity::onUpdate(dt); respawnTimer -= dt; if (!(dsq->game->avatar->position - this->position).isLength2DIn(2000)) { if (respawnTimer < 0) { respawnTimer = 0; perform(STATE_IDLE); } } } else { /* if (layer == LR_ENTITIES || layer == LR_ENTITIES2) { rippleTimer -= dt; if (rippleTimer < 0) { if (core->afterEffectManager) core->afterEffectManager->addEffect(new ShockEffect(Vector(core->width/2, core->height/2),position,0.04,0.06,15,0.2f)); rippleTimer = 0.5; } } */ FlockEntity::onUpdate(dt); if (dsq->game->isValidTarget(this, 0)) dsq->game->handleShotCollisions(this); /* soundDelay -= dt; if (soundDelay <= 0) { //sound(swimSound, 1000 + rand()%100); soundDelay = 4+(rand()%50)/100.0; } */ /* 1. if distance_to(closest_boid) <= too_close then set direction away from closest_boid 2. speed_of_neighbors := average(speed(x), for all x where distance_to(x) <= neighborhood_size) direction_of_neighbors := avg(direction(x), for all x where distance_to(x) <= neighborhood_size) if speed < speed_of_neighbors then increase speed if speed > speed_of_neighbors then decrease speed turn towards direction_of_neighbors 3. position_of_neighbors := avg(position(x), for all x where distance_to(x) <= neighborhood_size) turn towards position_of_neighbors */ float seperation = 1; float alignment = 0; float cohesion = 0.75; /* FlockPiece flock; getFlockInRange(160, &flock); */ // if flock in 160 ? if (true) { VectorSet newDirection; if (avoidTime>0) { avoidTime -= dt; if (avoidTime<0) avoidTime=0; } Vector dir = getFlockHeading(); Vector accumulator; applyCohesion(accumulator); applyAlignment(accumulator, dir); // alignment applySeparation(accumulator); applyAvoidance(accumulator); updateVelocity(accumulator); /* if (dsq->game->isValidTarget(this, 0)) doSpellAvoidance(dt, 96, dodgeAbility); */ Vector lastPosition = position; Vector newPosition = position + (vel*velocityScale*dt) + vel2*dt; position = newPosition; if (dsq->game->isObstructed(position)) { position = lastPosition; /* position = Vector(newPosition.x, lastPosition.y); if (dsq->game->isObstructed(position)) { position = Vector(lastPosition.x, newPosition.y); if (dsq->game->isObstructed(position)) { position = lastPosition; } } */ } //updateCurrents(dt); updateVel2(dt); /* if (flipDelay > 0) { flipDelay -= dt; if (flipDelay < 0) { flipDelay = 0; } } */ flipDelay = 0; //dir.normalize2D(); if (flipDelay <= 0) { const float amt = 0; /* if (fabs(dir.x) > fabs(dir.y)) { if (dir.x > amt && !isfh()) { flipHorizontal(); flipDelay = 0.5; } if (dir.x < -amt && isfh()) { flipHorizontal(); flipDelay = 0.5; } } */ if (vel.x > amt && !isfh()) { flipHorizontal(); } if (vel.x < -amt && isfh()) { flipHorizontal(); } } //rotateToVec(accumulator, 5, 90); float angle = atan(dir.y/dir.x); angle = ((angle*180)/3.14); if (angle > 45) angle = 45; if (angle < -45) angle = -45; rotation = Vector(0,0,angle); //rotation.interpolateTo(Vector(0, 0, angle), 0); } } }
void RenderObject::renderCall() { //RenderObjectLayer *rlayer = core->getRenderObjectLayer(getTopLayer()); if (positionSnapTo) this->position = *positionSnapTo; position += offset; #ifdef BBGE_BUILD_DIRECTX if (!RENDEROBJECT_FASTTRANSFORM) core->getD3DMatrixStack()->Push(); #endif #ifdef BBGE_BUILD_OPENGL if (!RENDEROBJECT_FASTTRANSFORM) glPushMatrix(); if (!RENDEROBJECT_SHAREATTRIBUTES) { glPushAttrib(GL_ALL_ATTRIB_BITS); } #endif if (!RENDEROBJECT_FASTTRANSFORM) { if (layer != LR_NONE) { RenderObjectLayer *l = &core->renderObjectLayers[layer]; if (l->followCamera != NO_FOLLOW_CAMERA) { followCamera = l->followCamera; } } if (followCamera!=0 && !parent) { if (followCamera == 1) { #ifdef BBGE_BUILD_OPENGL glLoadIdentity(); glScalef(core->globalResolutionScale.x, core->globalResolutionScale.y,0); glTranslatef(position.x, position.y, position.z); if (isfh()) { glDisable(GL_CULL_FACE); glRotatef(180, 0, 1, 0); } if (core->mode == Core::MODE_3D) { glRotatef(rotation.x+rotationOffset.x, 1, 0, 0); glRotatef(rotation.y+rotationOffset.y, 0, 1, 0); } glRotatef(rotation.z+rotationOffset.z, 0, 0, 1); #endif #ifdef BBGE_BUILD_DIRECTX core->getD3DMatrixStack()->LoadIdentity(); core->scaleMatrixStack(core->globalResolutionScale.x, core->globalResolutionScale.y,0); core->translateMatrixStack(position.x, position.y, 0); if (isfh()) { //HACK: disable cull -> core->getD3DMatrixStack()->RotateAxisLocal(&D3DXVECTOR3(0, 1, 0), D3DXToRadian(180)); } core->rotateMatrixStack(rotation.z + rotationOffset.z); #endif } else { Vector pos = getFollowCameraPosition(); #ifdef BBGE_BUILD_OPENGL glTranslatef(pos.x, pos.y, pos.z); if (isfh()) { glDisable(GL_CULL_FACE); glRotatef(180, 0, 1, 0); } if (core->mode == Core::MODE_3D) { glRotatef(rotation.x+rotationOffset.x, 1, 0, 0); glRotatef(rotation.y+rotationOffset.y, 0, 1, 0); } glRotatef(rotation.z+rotationOffset.z, 0, 0, 1); #endif #ifdef BBGE_BUILD_DIRECTX core->translateMatrixStack(pos.x, pos.y, 0); if (isfh()) { //HACK: disable cull -> core->getD3DMatrixStack()->RotateAxisLocal(&D3DXVECTOR3(0, 1, 0), D3DXToRadian(180)); } core->rotateMatrixStack(rotation.z + rotationOffset.z); #endif } } else { #ifdef BBGE_BUILD_OPENGL glTranslatef(position.x, position.y, position.z); #endif #ifdef BBGE_BUILD_DIRECTX core->translateMatrixStack(position.x, position.y, 0); #endif #ifdef BBGE_BUILD_OPENGL if (RenderObject::renderPaths && position.data && position.data->path.getNumPathNodes() > 0) { glLineWidth(4); glEnable(GL_BLEND); int i = 0; glColor4f(1.0f, 1.0f, 1.0f, 0.5f); glBindTexture(GL_TEXTURE_2D, 0); glBegin(GL_LINES); for (i = 0; i < position.data->path.getNumPathNodes()-1; i++) { glVertex2f(position.data->path.getPathNode(i)->value.x-position.x, position.data->path.getPathNode(i)->value.y-position.y); glVertex2f(position.data->path.getPathNode(i+1)->value.x-position.x, position.data->path.getPathNode(i+1)->value.y-position.y); } glEnd(); glPointSize(20); glBegin(GL_POINTS); glColor4f(0.5,0.5,1,1); for (i = 0; i < position.data->path.getNumPathNodes(); i++) { glVertex2f(position.data->path.getPathNode(i)->value.x-position.x, position.data->path.getPathNode(i)->value.y-position.y); } glEnd(); } #endif #ifdef BBGE_BUILD_OPENGL if (core->mode == Core::MODE_3D) { glRotatef(rotation.x+rotationOffset.x, 1, 0, 0); glRotatef(rotation.y+rotationOffset.y, 0, 1, 0); } glRotatef(rotation.z+rotationOffset.z, 0, 0, 1); if (isfh()) { glDisable(GL_CULL_FACE); glRotatef(180, 0, 1, 0); } #endif #ifdef BBGE_BUILD_DIRECTX //core->getD3DMatrixStack()->RotateAxisLocal(&D3DXVECTOR3(0, 0, 1), rotation.z+rotationOffset.z); core->rotateMatrixStack(rotation.z + rotationOffset.z); if (isfh()) { //HACK: disable cull core->getD3DDevice()->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); //core->getD3DMatrixStack()->Scale(-1, 1, 1); //core->applyMatrixStackToWorld(); core->getD3DMatrixStack()->RotateAxisLocal(&D3DXVECTOR3(0, 1, 0), D3DXToRadian(180)); //core->applyMatrixStackToWorld(); } #endif } #ifdef BBGE_BUILD_OPENGL glTranslatef(beforeScaleOffset.x, beforeScaleOffset.y, beforeScaleOffset.z); if (core->mode == Core::MODE_3D) glScalef(scale.x, scale.y, scale.z); else glScalef(scale.x, scale.y, 1); glTranslatef(internalOffset.x, internalOffset.y, internalOffset.z); #endif #ifdef BBGE_BUILD_DIRECTX core->translateMatrixStack(beforeScaleOffset.x, beforeScaleOffset.y, 0); core->scaleMatrixStack(scale.x, scale.y, 1); core->translateMatrixStack(internalOffset.x, internalOffset.y, 0); core->applyMatrixStackToWorld(); #endif //glDisable(GL_CULL_FACE); /* Never set anywhere. --achurch if (renderOrigin) { #ifdef BBGE_BUILD_OPENGL glBegin(GL_TRIANGLES); glColor4f(1.0f, 0.0f, 0.0f, 1.0f); glVertex3f(0.0f, 5.0f, 0.0f); glVertex3f(50.0f, 0.0f, 0.0f); glVertex3f(0.0f, -5.0f, 0.0f); glColor4f(0.0f, 1.0f, 0.0f, 1.0f); glVertex3f(0.0f, 0.0f, 5.0f); glVertex3f(0.0f, 50.0f, 0.0f); glVertex3f(0.0f, 0.0f, -5.0f); glColor4f(0.0f, 0.0f, 1.0f, 1.0f); glVertex3f(5.0f, 0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 50.0f); glVertex3f(-5.0f, 0.0f, 0.0f); glEnd(); #endif } */ } for (Children::iterator i = children.begin(); i != children.end(); i++) { if (!(*i)->isDead() && (*i)->renderBeforeParent) (*i)->render(); } //if (useColor) { #ifdef BBGE_BUILD_OPENGL if (rlayer) glColor4f(color.x * rlayer->color.x, color.y * rlayer->color.y, color.z * rlayer->color.z, alpha.x*alphaMod); else glColor4f(color.x, color.y, color.z, alpha.x*alphaMod); #elif defined(BBGE_BUILD_DIRECTX) core->setColor(color.x, color.y, color.z, alpha.x*alphaMod); #endif } if (texture) { #ifdef BBGE_BUILD_OPENGL if (texture->textures[0] != lastTextureApplied || repeatTexture != lastTextureRepeat) { texture->apply(repeatTexture); lastTextureRepeat = repeatTexture; lastTextureApplied = texture->textures[0]; } #endif #ifdef BBGE_BUILD_DIRECTX texture->apply(repeatTexture); #endif } else { if (lastTextureApplied != 0 || repeatTexture != lastTextureRepeat) { #ifdef BBGE_BUILD_OPENGL glBindTexture(GL_TEXTURE_2D, 0); #endif #ifdef BBGE_BUILD_DIRECTX core->bindTexture(0, 0); #endif lastTextureApplied = 0; lastTextureRepeat = repeatTexture; } } applyBlendType(); bool doRender = true; int pass = renderPass; if (core->currentLayerPass != RENDER_ALL && renderPass != RENDER_ALL) { RenderObject *top = getTopParent(); if (top) { if (top->overrideRenderPass != OVERRIDE_NONE) pass = top->overrideRenderPass; } doRender = (core->currentLayerPass == pass); } if (renderCollisionShape) renderCollision(); if (doRender) onRender(); //collisionShape.render(); if (!RENDEROBJECT_SHAREATTRIBUTES) { glPopAttrib(); } for (Children::iterator i = children.begin(); i != children.end(); i++) { if (!(*i)->isDead() && !(*i)->renderBeforeParent) (*i)->render(); } if (!RENDEROBJECT_FASTTRANSFORM) { #ifdef BBGE_BUILD_OPENGL glPopMatrix(); #endif #ifdef BBGE_BUILD_DIRECTX core->getD3DMatrixStack()->Pop(); core->applyMatrixStackToWorld(); #endif } position -= offset; if (integerizePositionForRender) { position = savePosition; } }