void calibate(int x, int y, int cr, int cg, int cb) { HDC hScreen = GetDC(GetDesktopWindow()); screenCap(0, 0, GetDeviceCaps(hScreen, HORZRES), GetDeviceCaps(hScreen, VERTRES)); //just the whole screen if (x <= 0 || y <= 0) { return; } int tempY = y; const int cap = 5000; const int tollerance = 20; int c = 0; while (tempY >= 0 && colorRangeCheck(posR(x, tempY), posG(x, tempY), posB(x, tempY), cr, cg, cb, tollerance) && c < cap) { tempY--; c++; } barPosY = tempY; tempY = y; while (tempY < GetDeviceCaps(hScreen, VERTRES) && colorRangeCheck(posR(x, tempY), posG(x, tempY), posB(x, tempY), cr, cg, cb, tollerance) && c < cap) { tempY++; c++; } barHeight = tempY - barPosY; int tempX = x; while (tempX >= 0 && colorRangeCheck(posR(tempX, y), posG(tempX, y), posB(tempX, y), cr, cg, cb, tollerance) && c < cap) { tempX--; c++; } barPosX = tempX - 1; tempX = x; while (tempX < GetDeviceCaps(hScreen, HORZRES) && colorRangeCheck(posR(tempX, y), posG(tempX, y), posB(tempX, y), cr, cg, cb, tollerance) && c < cap) { tempX++; c++; } barWidth = tempX - barPosX; }
void RigidBody::constructTMatrix(phy::TransformationMatrix & tMatrix) { tMatrix(0,3) = posB(0); tMatrix(1,3) = posB(1); //multiply by rotation matrix (effective equivalent of matrix multiplication) tMatrix(0,0) = angleCosB(); tMatrix(1,0) = angleSinB(); tMatrix(0,1) = -angleSinB(); tMatrix(1,1) = angleCosB(); }
void RigidBody::constructTMatrixInv(phy::TransformationMatrix & tInvMatrix) { //inverted rotation matrix tInvMatrix(0,0) = angleCosB(); tInvMatrix(1,0) = -angleSinB(); tInvMatrix(0,1) = angleSinB(); tInvMatrix(1,1) = angleCosB(); //multiply inverted translation matrix by inverted rotation matrix to obtain inverted //transformation matrix (inv translation matrix has negated tMatrix(0,3) and tMatrix(1,3)) tInvMatrix(0,3) = (-posB(0) * angleCosB()) - (posB(1) * angleSinB()); tInvMatrix(1,3) = ( posB(0) * angleSinB()) - (posB(1) * angleCosB()); }
void DestructibleWallsDemo::drawBrick( const hkVector4& position, const hkVector4& halfsize) const { hkVector4 posA=position; hkVector4 posC=position; posA.sub4( halfsize ); posC.add4( halfsize ); hkVector4 posB=posA; posB(0) = posC(0); hkVector4 posD=posA; posD(1) = posC(1); posA(2) = posB(2) = posC(2)= posD(2) = .0f; HK_DISPLAY_LINE(posA, posB , 0xffffffff); HK_DISPLAY_LINE(posB, posC , 0xffffffff); HK_DISPLAY_LINE(posC, posD , 0xffffffff); HK_DISPLAY_LINE(posD, posA , 0xffffffff); HK_DISPLAY_LINE(posA, posC , 0xffffffff); }
bool processInput(std::shared_ptr< Overlay::ISurface > pSurface) { if (GetAsyncKeyState(VK_F10)) { showMenu = !showMenu; }else if (showMenu && GetAsyncKeyState(VK_LBUTTON)) { POINT p; GetPhysicalCursorPos(&p); HWND window = GetForegroundWindow(); ScreenToClient(window, &p); if (selectedOption == -1) { for (int i = 0; i <= maxOption; i++) { if (isInOption(p.x, p.y, i)) { debugText = std::to_string(i); selectedOption = i; } } if (selectedOption == 0) { infoText = "Click on the HP Bar's Center!"; }else if (selectedOption == 1) { infoText = "Click on desired position"; } }else if (selectedOption == 0) { GetPhysicalCursorPos(&p); ShowCursor(FALSE); screenCap(p.x, p.y, 0, 0); barColor = createRGBA(posR(0, 0), posG(0, 0), posB(0, 0), 255); calibate(p.x, p.y, posR(0, 0), posG(0, 0), posB(0, 0)); ShowCursor(TRUE); selectedOption = -1; infoText = ""; }else if (selectedOption == 1) { hpBarX = p.x; hpBarY = p.y; selectedOption = -1; infoText = ""; } std::this_thread::sleep_for(std::chrono::milliseconds(160)); } std::this_thread::sleep_for(std::chrono::milliseconds(160)); return true; }
void MovableObject::store(char * snapshot) const { //store pos phy::RecordableFloatPoint<2>::Store(snapshot, posA()); snapshot += phy::RecordableFloatPoint<2>::SnapshotSize(); phy::RecordableFloatPoint<2>::Store(snapshot, posB()); snapshot += phy::RecordableFloatPoint<2>::SnapshotSize(); //store tMatrix phy::RecordableFloatMatrix<4, 4>::Store(snapshot, m_tMatrix.active()); snapshot += phy::RecordableFloatMatrix<4, 4>::SnapshotSize(); phy::RecordableFloatMatrix<4, 4>::Store(snapshot, m_tMatrix.background()); snapshot += phy::RecordableFloatMatrix<4, 4>::SnapshotSize(); //store tMatrixInv phy::RecordableFloatMatrix<4, 4>::Store(snapshot, m_tMatrixInv.active()); snapshot += phy::RecordableFloatMatrix<4, 4>::SnapshotSize(); phy::RecordableFloatMatrix<4, 4>::Store(snapshot, m_tMatrixInv.background()); snapshot += phy::RecordableFloatMatrix<4, 4>::SnapshotSize(); }
void DemoApplication::render() { OVector3 posA(0.0f); OVector3 posB(0.0f); OMatrixStack mtx; /* calculating displacement vectors */ posA.setX(_movRadiusA*cosf(_thetaA)); posA.setZ(_movRadiusA*sinf(_thetaA)); posB.setX(_movRadiusB*cosf(_thetaB)); posB.setZ(_movRadiusB*sinf(_thetaB)); /* Get initial matrix from camera related transforms */ mtx = *(camera()->transform()); /* render cube */ mtx.push(); mtx.translate(posA); mtx.scale(0.5f); _cube->render(&mtx); mtx.pop(); /* render torus */ mtx.push(); mtx.translate(posB); mtx.scale(0.25f); mtx.rotateX(45.0f); _torus->render(&mtx); mtx.pop(); /* render text */ _title->render(); _fpsText->render(); _perfText->render(); _idleText->render(); _cameraText->render(); _renderText->render(); }
float getPercentageHP() { screenCap(barPosX, barPosY, barWidth, barHeight); if (barWidth == 0 || barHeight == 0) { return -1; } std::vector<int> avgR(barWidth); std::vector<int> avgG(barWidth); std::vector<int> avgB(barWidth); for (int i = 1; i <= barWidth; i++) { int sumR = 0; int sumG = 0; int sumB = 0; for (int j = 1; j <= barHeight; j++) { int x = i; int y = j; int red = posR(x, y); int green = posG(x, y); int blue = posB(x, y); sumR += red; sumG += green; sumB += blue; } sumR /= barHeight; sumG /= barHeight; sumB /= barHeight; avgR[i - 1] = sumR; avgG[i - 1] = sumG; avgB[i - 1] = sumB; } for (int i = 0; i < avgR.size(); i++) { if (avgR[i] < 80) { return (float)i / barWidth; } } return 1.f; }
void MovableObject::constructTMatrixInv(phy::TransformationMatrix & tMatrixInv) { tMatrixInv(0,3) = -posB(0); tMatrixInv(1,3) = -posB(1); }
void MovableObject::constructTMatrix(phy::TransformationMatrix & tMatrix) { tMatrix(0,3) = posB(0); tMatrix(1,3) = posB(1); }