void Scythe::calculateMaxRotation() { IW_CALLSTACK("Scythe::calculateMaxRotation"); // calculate max rotation to the left float deltaY = this->i2Position.y; //this->uAttatchedToList[0]->i2Position.y - this->i2Position.y; float deltaX = (float)abs(this->uAttatchedToList[0]->i2Position.x - this->i2Position.x); float rads = atan(deltaX/deltaY); this->fMaxLeft = rads; // caculate max rotation to the right /*deltaY = this->i2Position.y; //abs(this->uAttatchedToList[1]->i2Position.y - this->i2Position.y); deltaX = (float)abs(this->uAttatchedToList[1]->i2Position.x - this->i2Position.x); rads = atan(deltaX/deltaY); this->fMaxRight = rads;*/ // swinging scythe this->rotAxis.x = this->i2RegionSize.x/2 + this->i2Position.x; //(this->uAttatchedToList[0]->i2Position.x + this->uAttatchedToList[1]->i2Position.x)/2; this->rotAxis.y = this->uAttatchedToList[0]->i2Position.y /*+ this->uAttatchedToList[1]->i2Position.y)/2*/ + Screen::getBOXSIZE().y; this->fAngle = this->fMaxLeft; //(this->fMaxLeft + this->fMaxRight)* 0.5f; this->iLength = (int)((this->i2Position.y - this->rotAxis.y) * 0.5f); // plus 2 to avoid divide by zero. if ( this->iLength == 0) { IwAssertMsg(MYAPP, false, ("scythe With length of zero, move more than one box lower than rotation point")); } this->fGDividedByLength = GRAVC/(float)this->iLength; //this->fperoid = 6.28 * sqrt((float)this->iLength/GRAV); this->mRot.SetRot(IW_ANGLE_FROM_RADIANS(this->fAngle), this->rotAxis); }
void renderImageWorldSpace(CIwFVec2& position, float angle, float scaleFactor, int textureSize, float worldRot, int frameNumber, int numFrames, float z) { static CIwSVec3 vertices[4]; static CIwSVec2 UVs[4]; //set up model space vertices int vertexDist = scaleFactor*textureSize/2; vertices[0] = CIwSVec3(-1*vertexDist, -1*vertexDist, z); vertices[2] = CIwSVec3(vertexDist, -1*vertexDist, z); vertices[3] = CIwSVec3(vertexDist, vertexDist, z); vertices[1] = CIwSVec3(-1*vertexDist, vertexDist, z); CIwMat modelTransform = CIwMat::g_Identity; modelTransform.SetRotZ(IW_ANGLE_FROM_RADIANS(angle)); modelTransform.SetTrans(CIwVec3(position.x, -position.y, 0)); CIwMat rot = CIwMat::g_Identity; rot.SetRotZ(IW_ANGLE_FROM_RADIANS(worldRot)); modelTransform = modelTransform*rot; IwGxSetModelMatrix(&modelTransform, false); float frameRatio = 1.0/numFrames; //set up sprite UV's iwfixed cf = IW_FIXED((float)frameNumber / numFrames); iwfixed nf = IW_FIXED((frameNumber + 1.0) / numFrames); UVs[0] = CIwSVec2(cf, 0); UVs[2] = CIwSVec2(nf, 0); UVs[3] = CIwSVec2(nf, IW_GEOM_ONE); UVs[1] = CIwSVec2(cf, IW_GEOM_ONE); //render the unit in model space IwGxSetUVStream(UVs); IwGxSetZDepthFixed(8); IwGxSetVertStreamModelSpace(vertices, 4); IwGxDrawPrims(IW_GX_QUAD_STRIP, NULL, 4); IwGxFlush(); }
void Scythe::update(uint64 time) { IW_CALLSTACK("Scythe::update"); if (GameState::getState() != GameState::PLAY) { return; } this->iTime = time; this->iTimePassed += time; // time from milliseconds to seconds double t = (double)this->iTime * 0.001; if ( t > 1 ) // to avoid lag spikes { t = 0; } // calulate the change in angle this->fAngularAcceleration = -this->fGDividedByLength * sin(this->fAngle); this->fAngularVel += this->fAngularAcceleration * t; this->fAngle += this->fAngularVel * t; // in case of emergency reset the scythe if ( this->fAngularAcceleration > 10 || this->fAngularVel > 10|| this->fAngle > 10) { this->fAngle = this->fMaxLeft; this->fAngularAcceleration = 0; this->fAngularVel; } //update rotation matrix and boundingbox this->mRot.SetRot(IW_ANGLE_FROM_RADIANS(this->fAngle), this->rotAxis); this->brBoundingBox.setPosition(getRotatedCoords(CIwSVec2(this->i2Position.x + (int)(this->i2Size.x * 0.5f), this->i2Position.y + (int)(this->i2Size.y * 0.75f)))); if (this->bUpdate == true) LethalUnit::update(); }