void IngameWindow::update() { // Update player name playernamelabel->setText(engine->getCurrentPlayer().getName()); // Update Square information Board* board = engine->getBoard(); Cursor* cursor = Cursor::getCursor()->getChild(); if(cursor == NULL) cursor = Cursor::getCursor(); Square* square = board->getSquare(cursor->getPosition().getX(), cursor->getPosition().getY()); Unit* unit = square->getUnit(); for(int i = 0; i < EUT_NUMBEROFUNITTYPES * 2; ++i) unitimages[i]->setVisible(false); for(int i = 0; i < ET_NUMBEROFTERRAINTYPES; ++i) terrainimages[i]->setVisible(false); // Decide which unit has to be drawn if(unit != NULL) { // Update text healthtext->setText(intToString(unit->getHP()) + " / " + intToString(unit->getMaxHp())); unitattacktext->setText(intToString(unit->getBaseAttack())); unitdefensetext->setText(intToString(unit->getBaseDefense())); unitmovementtext->setText(intToString(unit->getCurrentMovement()) + " / " + intToString(unit->getMovement())); unitimages[unit->getPlayer()->getId() * EUT_NUMBEROFUNITTYPES + unit->getType()]->setVisible(true); } else { unitattacktext->setText(""); unitdefensetext->setText(""); healthtext->setText(""); unitmovementtext->setText(""); } // Decide which terrain has to be drawn Terrain* terrain = square->getTerrain(); if(terrain != NULL) { // Update terrain text terrainattacktext->setText(intToString(terrain->getModificator(EM_ATTACK))); terraindefensetext->setText(intToString(terrain->getModificator(EM_DEFENSE))); terrainimages[terrain->getType()]->setVisible(true); } else { terrainattacktext->setText(""); terraindefensetext->setText(""); } }
void DeployWindow::moveUnit() { Cursor* cursor = Cursor::getCursor(); Cursor* child = cursor->getChild(); if(child == NULL) return; engine->moveUnitDeployment(cursor->getPosition(), child->getPosition()); cursor->setPosition(child->getPosition()); cursor->despawnChild(); printf("move unit\n"); }
void Camera :: update(const Cursor& c, const Map& map) { #ifdef VERBOSE LDebug << "Camera :: update (Was: " << position << ")"; #endif UVec2 cursorPosition = c.getPosition(); // We have to apply the camera to avoid infinite recursion of the displacement, when reaching the bound if ( cursorPosition.x - this->position.x < BOUND_CAMERA_DISPLACEMENT ) { moveLeft(); } if ( cursorPosition.x - this->position.x > MAP_MIN_WIDTH - BOUND_CAMERA_DISPLACEMENT ) { moveRight(map); } if ( cursorPosition.y - this->position.y < BOUND_CAMERA_DISPLACEMENT ) { moveUp(); } if ( cursorPosition.y - this->position.y > MAP_MIN_HEIGHT - BOUND_CAMERA_DISPLACEMENT ) { moveDown(map); } #ifdef VERBOSE LDebug << "Camera :: update (New position: " << position << ")"; #endif }
// // The Graphics Callback runs in the application "client thread" (qhStart) and sets the transformations // for the Red Sphere and Green Line of the Cursor. Also, this callback sets the WorldToDevice matrix // for use in the ServoLoopCallback. // void GraphicsCallback(void) { QHGLUT* localDisplayObject = QHGLUT::searchWindow("Coulomb Field Demo");//Get a Pointer to the display object Cursor* localDeviceCursor = Cursor::searchCursor("devCursor");//Get a pointer to the cursor Cylinder* localForceArrow = Cylinder::searchCylinder("forceArrow");//get a pointer to the cylinder Cone* localForceArrowTip = Cone::searchCone("forceArrowTip");//get a pointer to the cylinder Sphere* localCursorSphere = Sphere::searchSphere("cursorSphere");//get a pointer top the Sphere if( localDisplayObject == NULL || localDeviceCursor == NULL || localForceArrow == NULL || localCursorSphere == NULL) return; hduMatrix CylinderTransform;//Transformation for the Cylinder. This transform makes it point toward the Model hduVector3Dd localCursorPosition; hduVector3Dd DirectionVecX; hduVector3Dd PointOnPlane; hduVector3Dd DirectionVecY; hduVector3Dd DirectionVecZ; //Compute the world to device transform WorldToDevice = localDisplayObject->getWorldToDeviceTransform(); // Set transform for Red Sphere localCursorPosition = localDeviceCursor->getPosition();//Get the local cursor position in World Space hduVector3Dd localCursorSpherePos = localCursorSphere->getTranslation(); localCursorSphere->setTranslation(-localCursorSpherePos); localCursorSphere->setTranslation(localCursorPosition);//Set the position of the Sphere the same as the cursor //////////////////////////////////////////////////////////////////////////////////////////// //Code to calculate the transform of the green cylinder to point along the force direction //////////////////////////////////////////////////////////////////////////////////////////// hduMatrix DeviceToWorld = WorldToDevice.getInverse(); HDdouble ForceMagnitude = forceVec.magnitude(); DeviceToWorld[3][0] = 0.0; DeviceToWorld[3][1] = 0.0; DeviceToWorld[3][2] = 0.0; DirectionVecX = forceVec * DeviceToWorld; DirectionVecX.normalize(); PointOnPlane.set(0.0,0.0,(DirectionVecX[0]*localCursorPosition[0] + DirectionVecX[1]*localCursorPosition[1] + DirectionVecX[2]*localCursorPosition[2])/DirectionVecX[2]); DirectionVecY = PointOnPlane - localCursorPosition; DirectionVecY.normalize(); DirectionVecZ = -DirectionVecY.crossProduct(DirectionVecX); CylinderTransform[0][0] = DirectionVecZ[0]; CylinderTransform[0][1] = DirectionVecZ[1]; CylinderTransform[0][2] = DirectionVecZ[2]; CylinderTransform[0][3] = 0.0; CylinderTransform[1][0] = DirectionVecX[0]; CylinderTransform[1][1] = DirectionVecX[1]; CylinderTransform[1][2] = DirectionVecX[2]; CylinderTransform[1][3] = 0.0; CylinderTransform[2][0] = DirectionVecY[0]; CylinderTransform[2][1] = DirectionVecY[1]; CylinderTransform[2][2] = DirectionVecY[2]; CylinderTransform[2][3] = 0.0; CylinderTransform[3][0] = 0.0 ; CylinderTransform[3][1] = 0.0 ; CylinderTransform[3][2] = 0.0 ; CylinderTransform[3][3] = 1.0; CylinderTransform = CylinderTransform * hduMatrix::createTranslation(localCursorPosition[0], localCursorPosition[1], localCursorPosition[2]); localForceArrow->update(chargeRadius/4, ForceMagnitude*50, 15); localForceArrow->setTranslation(localCursorPosition); localForceArrow->setTransform(CylinderTransform); hduMatrix ConeTransform = CylinderTransform * hduMatrix::createTranslation(DirectionVecX[0] * ForceMagnitude*50,DirectionVecX[1] * ForceMagnitude*50,DirectionVecX[2] * ForceMagnitude*50 ); localForceArrowTip->setTransform(ConeTransform); ///////////////////////////////////////////// }
GraphicLSystem::Cursor::Cursor(Cursor const& source) { position = new Point(0,0,0); direction = new Vector(0,0,0); *position = source.getPosition(); *direction = source.getDirection(); }
void DeployWindow::placeEntity() { printf("place entity\n"); // get active button int activebuttonid = 0; for(activebuttonid = 0; activebuttonid < BUTTONCOUNT; ++activebuttonid) { if(radiobuttons[activebuttonid]->getState() == namelessgui::Button::ES_ACTIVE) break; } // Get cursor position Cursor* cursor = Cursor::getCursor(); // Remove terrain if(activebuttonid == 9) { engine->removeTerrain(cursor->getPosition()); } // Place unit else if(activebuttonid >= 0 && activebuttonid < 2 * EUT_NUMBEROFUNITTYPES) { int playerid = activebuttonid / EUT_NUMBEROFUNITTYPES; Player* player = engine->getPlayer(playerid); UNITTYPES unittype = (UNITTYPES)(activebuttonid % EUT_NUMBEROFUNITTYPES); engine->placeUnit(cursor->getPosition(), playerid, unittype); update(); } // Place terrain else { TERRAINTYPES terraintype = (TERRAINTYPES)(activebuttonid - (2 * EUT_NUMBEROFUNITTYPES)); engine->placeTerrain(cursor->getPosition(), terraintype); } }