//------------------------------------------------------------------ // Storm3D_Camera::TestPointVisibility //------------------------------------------------------------------ bool Storm3D_Camera::TestPointVisibility(const VC3 &pointpos) { if(forcedOrthogonalProjection) // Todo: real check return true; // Update vis planes, if needed if (visplane_update_needed) UpdateVisPlanes(); // Back/Front planes float er=VC3(pointpos.x-position.x, pointpos.y-position.y,pointpos.z-position.z).GetDotWith(pnormals[0]); if (er<0) return false; if (er>vis_range) return false; // Side Planes if (VC3(pointpos.x-position.x,pointpos.y-position.y, pointpos.z-position.z).GetDotWith(pnormals[1]) <0) return false; if (VC3(pointpos.x-position.x,pointpos.y-position.y, pointpos.z-position.z).GetDotWith(pnormals[2]) <0) return false; // Up/Down planes if (VC3(pointpos.x-position.x,pointpos.y-position.y, pointpos.z-position.z).GetDotWith(pnormals[3]) <0) return false; if (VC3(pointpos.x-position.x,pointpos.y-position.y, pointpos.z-position.z).GetDotWith(pnormals[4]) <0) return false; // It's visible (at last) return true; }
CameraAutotilter::CameraAutotilter(game::GameMap *gameMap) { this->gameMap = gameMap; this->lastRotation = VC3(0,0,0); this->lastPosition = VC3(0,0,0); this->lastTime = Timer::getTime(); }
ScriptableAIDirectControl::ScriptableAIDirectControl(Game *game, Unit *unit) { this->game = game; this->unit = unit; this->eventMask = 0; this->previousEventsOnMask = 0; //this->actions = AIDirectControlActions(); // does not need init //this->actionsToDisableAutomatically = AIDirectControlActions(); // does not need init this->aimMode = AIM_MODE_OFFSET_SELF; this->aimPosition = VC3(0,0,0); this->aimPositionResult = VC3(0,0,0); this->timerTicksAmount = 1; this->lastTimerCall = 0; this->customEventsUsed = 0; for (int i = 0; i < SCRIPTABLEAIDIRECTCONTROL_MAX_CUSTOM_EVENTS; i++) { this->customEventsTicksLeft[i] = 0; this->customEventsName[i] = NULL; } }
void OptionApplier::applyCameraOptions(IStorm3D_Scene *scene) { if (SimpleOptions::getBool(DH_OPT_B_GAME_SIDEWAYS)) { scene->GetCamera()->SetUpVec(VC3(0,0,1)); } else { scene->GetCamera()->SetUpVec(VC3(0,1,0)); } }
VectorDamper::VectorDamper() { pos = VC3(0, 0, 0); speed = VC3(0, 0, 0); target = VC3(0, 0, 0); mass = 1.0f; k = 0.1f; overdampFactor = 1.0f; calculateC(); }
void DebugTrackerVisualizer::visualizeTrackers(game::tracking::ObjectTracker *objectTracker) { assert(objectTracker != NULL); std::vector<ITrackerObject *> trackerList = objectTracker->getAllTrackers(); for (int i = 0; i < (int)trackerList.size(); i++) { ITrackerObject *tracker = trackerList[i]; std::string trackerName = tracker->getType()->getTrackerTypeName(); COL col = COL(0,0,1); VC3 pos = tracker->getTrackerPosition(); VC3 sizes = VC3(0.1f, 0.1f, 0.1f); if (trackerName == "projectile") { col = COL(1.0f,0.7f,0.0f); sizes *= 1.5f; } VC3 c1 = VC3(pos.x - sizes.x, pos.y + sizes.y, pos.z - sizes.z); VC3 c2 = VC3(pos.x + sizes.x, pos.y + sizes.y, pos.z - sizes.z); VC3 c3 = VC3(pos.x + sizes.x, pos.y + sizes.y, pos.z + sizes.z); VC3 c4 = VC3(pos.x - sizes.x, pos.y + sizes.y, pos.z + sizes.z); VC3 cb1 = VC3(pos.x - sizes.x, pos.y - sizes.y, pos.z - sizes.z); VC3 cb2 = VC3(pos.x + sizes.x, pos.y - sizes.y, pos.z - sizes.z); VC3 cb3 = VC3(pos.x + sizes.x, pos.y - sizes.y, pos.z + sizes.z); VC3 cb4 = VC3(pos.x - sizes.x, pos.y - sizes.y, pos.z + sizes.z); float extra_offset = 0.0f + (i / 200.0f); VC3 cb4_extra = VC3(pos.x - sizes.x - extra_offset, pos.y - sizes.y, pos.z + sizes.z); disposable_scene->AddLine(c1, c2, col); disposable_scene->AddLine(c2, c3, col); disposable_scene->AddLine(c3, c4, col); disposable_scene->AddLine(c4, c1, col); disposable_scene->AddLine(cb1, cb2, col); disposable_scene->AddLine(cb2, cb3, col); disposable_scene->AddLine(cb3, cb4, col); disposable_scene->AddLine(cb4, cb1, col); disposable_scene->AddLine(c1, cb1, col); disposable_scene->AddLine(c2, cb2, col); disposable_scene->AddLine(c3, cb3, col); disposable_scene->AddLine(c4, cb4, col); disposable_scene->AddLine(c4, cb4, col); COL col2 = COL(0,1,1); disposable_scene->AddLine(c4, cb4_extra, col2); } }
// Sets the position of interest and elapsed time for the camera system. Must be used before querying // camera parameters. void CameraSystemAim::update( VC3 positionOfInterest, int elapsedTime ) { cameraPosition = positionOfInterest + VC3(0, 1.395f, 0); targetPosition = aimPosition; targetPosition.y = cameraPosition.y + sinf(betaAngle); cameraPosition = cameraPosition + (cameraPosition-targetPosition).GetNormalized()*1.687f; upVector = VC3(0, 1, 0); QUAT tmp_quat3( (targetPosition-cameraPosition).GetNormalized(), DEG2RAD( -7.7f )); tmp_quat3.RotateVector( upVector ); FOV = 70.0f; }
bool Storm3D_Camera::TestBoxVisibility(const VC3 &min, const VC3 &max) { if(forcedOrthogonalProjection) // Todo: real check return true; VC3 size = max - min; VC3 vertices[8] = { VC3(min.x, min.y, min.z), VC3(min.x + size.x, min.y, min.z), VC3(min.x + size.x, min.y + size.y, min.z), VC3(min.x + size.x, min.y + size.y, min.z + size.z), VC3(min.x + size.x, min.y, min.z + size.z), VC3(min.x, min.y + min.y, min.z), VC3(min.x, min.y + min.y, min.z + min.z), VC3(min.x, min.y, min.z + min.z), }; float origoDistance = position.GetRangeTo(VC3()); bool allInside = true; for(int i = 0; i < 5; ++i) { bool allOutside = true; if(i == 0) { for(int j = 0; j < 8; ++j) { float distance = pnormals[i].GetDotWith(vertices[j]) + origoDistance + vis_range; allOutside = allOutside && (distance >= 0); allInside = allInside && (distance < 0); if(!allOutside && !allInside) break; } } for(int j = 0; j < 8; ++j) { float distance = pnormals[i].GetDotWith(vertices[j]) + origoDistance; allOutside = allOutside && (distance < 0); allInside = allInside && (distance >= 0); if(!allOutside && !allInside) break; } if(allOutside) return false; } return true; }
void AbstractPhysicsObject::syncInactiveImplementationObject(PHYSICS_ACTOR &obj) { if(!dynamicActor) return; if (moveToVelocity) { obj->setVelocity(velocity); moveToVelocity = false; } if (moveToAngularVelocity) { obj->setAngularVelocity(angularVelocity); moveToAngularVelocity = false; } if (doImpulse) { obj->addImpulse(impulsePosition, impulse); impulsePosition = VC3(0,0,0); impulse = VC3(0,0,0); doImpulse = false; } if (moveToPosition) { if (attemptedPosition) { obj->movePosition(position); attemptedPosition = false; } else { obj->setPosition(position); } moveToPosition = false; } if (moveToRotation) { if (attemptedRotation) { obj->moveRotation(rotation); attemptedRotation = false; } else { obj->setRotation(rotation); } moveToRotation = false; } this->dirty = false; }
void WorldFold::resetWorldFold() { for (int i = 0; i < MAX_WORLD_FOLDS; i++) { worldFoldMatrix[i].CreateIdentityMatrix(); worldFoldResultMatrix[i].CreateIdentityMatrix(); worldFoldExists[i] = false; worldFoldKey[i] = 1; } worldFoldCenter = VC3(0,0,0); wfCameraMatrix.CreateIdentityMatrix(); wfCameraPosition = VC3(0,0,0); }
Rect getScreenArea(const AABB &aabb, Game *game) { VC3 v[8]; v[0] = VC3(aabb.mmin.x, aabb.mmin.y, aabb.mmin.z); v[1] = VC3(aabb.mmax.x, aabb.mmin.y, aabb.mmin.z); v[2] = VC3(aabb.mmin.x, aabb.mmax.y, aabb.mmin.z); v[3] = VC3(aabb.mmin.x, aabb.mmin.y, aabb.mmax.z); v[4] = VC3(aabb.mmax.x, aabb.mmax.y, aabb.mmin.z); v[5] = VC3(aabb.mmin.x, aabb.mmax.y, aabb.mmax.z); v[6] = VC3(aabb.mmax.x, aabb.mmin.y, aabb.mmax.z); v[7] = VC3(aabb.mmax.x, aabb.mmax.y, aabb.mmax.z); Point start = convertVC3toScreen(v[0], game); Point end = start; for(int i = 1; i < 8; ++i) { Point p = convertVC3toScreen(v[i], game); start.x = std::min(start.x, p.x); start.y = std::min(start.y, p.y); end.x = std::max(end.x, p.x); end.y = std::max(end.y, p.y); } Rect rect; rect.x = start.x; rect.y = start.y; rect.w = end.x - start.x; rect.h = end.y - start.y; return rect; }
ProgressBar::ProgressBar() { interruptPercent = 1.0f; timeDone = 0; timeTotal = 1; timeTick = 0; unit = NULL; label = NULL; doneLabel = NULL; interruptedLabel = NULL; borderImage = NULL; barImage = NULL; visible = false; visibilityLeftCounter = 0; doneTriggered = false; nextTickTrigger = 0; progressing = false; triggerInterrupted = false; progressPosition = VC3(0,0,0); progressAngle = 0; restartedWhileVisible = false; }
bool ClawUnitActor::setPathTo(Unit *unit, const VC3 &destination_) { VC3 destination = destination_; frozenbyte::ai::Path *path = solvePath(unit, unit->getPosition(), destination); // luckily, getPath may modify the destination value, if it is blocked // so no need to check that here. if (path != NULL) { unit->setPath(path); unit->setPathIndex(unit->getPathIndex() + 1); // (...path object is now contained within the unit, // unit will handle it's proper deletion) unit->setWaypoint(unit->getPosition()); unit->setFinalDestination(VC3(destination.x, game->gameMap->getScaledHeightAt(destination.x, destination.z), destination.z)); return true; } else { unit->setPath(NULL); unit->setFinalDestination(unit->getPosition()); unit->setWaypoint(unit->getPosition()); return false; } }
Storm3D_SpotlightData(Storm3D &storm_, IDirect3D9 &d3d, IDirect3DDevice9 &device_, bool ps14_, bool ps20_) : storm(storm_), device(device_), properties(device), coneColorMultiplier(0.3f), //smoothness(5.f), smoothness(5.f), ps14(ps14_), ps20(ps20_), smoothing(false), spotlightAlwaysVisible(false), camera(&storm), hasFade(false), hasCone(false), scissorRect(true), hasShadows(false), enabled(true), visible(false), coneUpdated(false), updateCone(true), noShadowModel(0), light_type(IStorm3D_Spotlight::Directional), coneFov(0) { properties.direction = VC3(0, 0, 1.f); properties.color = COL(1.f, 1.f, 1.f); shadowMap = staticBuffers.getShadowMap(); angle[0] = angle[1] = 0.f; speed[0] = 0.07f; speed[1] = -0.11f; }
void DebugVisualizerTextUtil::renderText(const VC3 &position, int offsetX, int offsetY, const char *text) { if (ui::defaultIngameFont != NULL) { IStorm3D_Font *f = ((OguiStormFont *)ui::defaultIngameFont)->fnt; if (text == NULL) text = "(null)"; VC3 pos = position; VC3 result = VC3(0,0,0); float rhw = 0; float real_z = 0; IStorm3D_Camera *cam = disposable_scene->GetCamera(); bool infront = cam->GetTransformedToScreen(pos, result, rhw, real_z); if (infront) { bool offscreen = false; int x = (int)(result.x * scr_width); int y = (int)(result.y * scr_height); if (x < 0 || y < 0 || x >= scr_width || y >= scr_height) offscreen = true; if (!offscreen) { float scrfloatx = (float)(x + offsetX); float scrfloaty = (float)(y + offsetY); float alpha = 1.0f; COL col = COL(1,1,1); disposable_scene->Render2D_Text(f, VC2(scrfloatx, scrfloaty), VC2(16, 16), text, alpha, col); } } } }
UnitTargeting::UnitTargeting() { targetSet = false; targetPosition = VC3(0, 0, 0); targetUnit = NULL; autoTarget = false; groundTarget = false; lineOfFireToTarget = false; lastTargetPosition = VC3(0,0,0); lastTargetPositionExists = false; aimingPosition = VC3(0,0,0); sweepTarget = VC3(0,0,0); sweepsSinceTarget = 0; targetLoseCounter = 0; targetLoseTime = 0; lofLoseStartedTime = 0; }
CameraSystemAim::CameraSystemAim() { positionOfInterest = VC3(0, 0, 0); angle = 0; betaAngle = 0; bank = 0; cameraPosition = VC3(0, 0, 1); targetPosition = VC3(0, 0, 0); upVector = VC3(0, 1, 0); FOV = 90; offset = VC3(0,2,0); distance = 10; response = 10; mode = 0; }
ScriptableAIDirectControl::ScriptableAIDirectControl(Game *game, Unit *unit) { this->game = game; this->unit = unit; this->eventMask = 0; this->previousEventsOnMask = 0; //this->actions = AIDirectControlActions(); // does not need init //this->actionsToDisableAutomatically = AIDirectControlActions(); // does not need init this->aimMode = AIM_MODE_OFFSET_SELF; this->aimPosition = VC3(0,0,0); this->aimPositionResult = VC3(0,0,0); this->timerTicksAmount = 1; this->lastTimerCall = 0; }
Decoration::Decoration() { name = NULL; position = VC3(0,0,0); rotation = VC3(0,0,0); startRotation = VC3(0,0,0); visualObject = NULL; visualObjectModel = NULL; stretched = false; for (int i = 0; i < DECORATION_MAX_EFFECTS; i++) { effectOn[i] = false; effectValue[i] = 0; } boundingQuadSizeX = 0.0f; boundingQuadSizeY = 0.0f; tickCount = 0; animationSpeed = 1; }
UnitHighlight::UnitHighlight(IStorm3D *storm3D, IStorm3D_Scene *stormScene) { this->storm3D = storm3D; this->stormScene = stormScene; highlightUnit = NULL; bool highlightTerrain = false; VC3 highlightTerrainPosition = VC3(0,0,0); #ifdef LEGACY_FILES visualObjectModel = new VisualObjectModel("Data/Models/Pointers/highlight.s3d"); #else visualObjectModel = new VisualObjectModel("data/model/pointer/highlight.s3d"); #endif // NOTICE: actually setting vo1 effect also sets it for vo2, // as no vo->disableSharedObjects() is called. // (they have shared meshes) visualObject = visualObjectModel->getNewObjectInstance(); visualObject->setCollidable(false); visualObject->setVisible(false); visualObject->setEffect(VISUALOBJECTMODEL_EFFECT_ADDITIVE); visualObject->setEffect(VISUALOBJECTMODEL_EFFECT_TRANSPARENT_30); visualObject2 = visualObjectModel->getNewObjectInstance(); visualObject2->setCollidable(false); visualObject2->setVisible(false); visualObject2->setEffect(VISUALOBJECTMODEL_EFFECT_ADDITIVE); visualObject2->setEffect(VISUALOBJECTMODEL_EFFECT_TRANSPARENT_30); #ifdef LEGACY_FILES terrainVisualObjectModel = new VisualObjectModel("Data/Models/Pointers/highlight_terrain.s3d"); #else terrainVisualObjectModel = new VisualObjectModel("data/model/pointer/highlight_terrain.s3d"); #endif terrainVisualObject = terrainVisualObjectModel->getNewObjectInstance(); terrainVisualObject->setEffect(VISUALOBJECTMODEL_EFFECT_ADDITIVE); terrainVisualObject->setEffect(VISUALOBJECTMODEL_EFFECT_TRANSPARENT_30); terrainVisualObject->setCollidable(false); terrainVisualObject->setVisible(false); terrainVisualObject2 = terrainVisualObjectModel->getNewObjectInstance(); terrainVisualObject2->setEffect(VISUALOBJECTMODEL_EFFECT_ADDITIVE); terrainVisualObject2->setEffect(VISUALOBJECTMODEL_EFFECT_TRANSPARENT_30); terrainVisualObject2->setCollidable(false); terrainVisualObject2->setVisible(false); rotX = 0; rotY = 0; rotZ = 0; }
//------------------------------------------------------------------ // Storm3D_Camera::TestPointIsBehind //------------------------------------------------------------------ bool Storm3D_Camera::TestPointIsBehind(const VC3 &pointpos) { // Update vis planes, if needed if (visplane_update_needed) UpdateVisPlanes(); // Front plane float er=VC3(pointpos.x-position.x, pointpos.y-position.y,pointpos.z-position.z).GetDotWith(pnormals[0]); if (er<0) return true; // It's on front (of camera) return false; }
ParticleSpawner::ParticleSpawner(Game *game) { this->game = game; this->name = NULL; this->position = VC3(0,0,0); this->direction = VC3(0,0,0); this->weapon = NULL; this->enabled = true; this->outsideScreen = false; this->distanceToListenerSq = 0.0f; this->waitTime = 0; this->projectileHandle = 0; this->attached = false; this->attachedTo = UNIFIED_HANDLE_NONE; }
void RopeJoint::run() { for (int i = 0; i < ROPEJOINT_ENDS; i++) { if (game->unifiedHandleManager->doesObjectExist(this->objHandle[i])) { } else { // the object must have broken or something? detach. // TODO: should either connect to self or maybe to last known global position for this end... attachEnd(i, UNIFIED_HANDLE_NONE, VC3(0,0,0)); } } }
//------------------------------------------------------------------ // Storm3D_Camera::GetUpVecReal //------------------------------------------------------------------ VC3 Storm3D_Camera::GetUpVecReal() const { // Fix up vector VC3 dir=target-position; VC3 upr=upvec.GetCrossWith(-dir); upr=upr.GetCrossWith(dir); if (fabs(upr.GetSquareLength()) < 0.001) { upr = VC3(0,1,0); } else { upr.Normalize(); } return upr; }
bool UpgradeManager::isLocked(Unit *unit, int upgradeId) { assert(upgradeId >= 0 && upgradeId < MAX_UPGRADE_TYPES); assert(unit != NULL); const char *script = upgradeTypes[upgradeId].getScript(); const char *sub = "is_locked"; util::Script *s = util::ScriptManager::getInstance()->getScript(script); if (s == NULL) return false; if (!s->hasSub(sub)) return false; return 1 == game->gameScripting->runOtherScript(script, sub, unit, VC3(0,0,0)); }
void PhysicsLib::enableFeature(PhysicsLib::Feature feature, bool enable) { if(!data->sdk || !data->scene) return; if(!data->scene->isWritable()) { ::Logger::getInstance()->warning("PhysicsLib::enableFeature - Attempt to set physics features while physics running (pause game/physics update first)."); return; } data->featureMap[feature] = enable; data->applyOptions(); // not necessarily a good idea? will cause a huge hit for this frame until proper settings get updated.. updateVisualization(VC3(0,0,0), 999999.0f, true); }
VC3 TrackableUnifiedHandleObject::getTrackableObjectPosition() const { // BUGBUG?? assert ei toimi // assert(TrackableUnifiedHandleObject::game != NULL); if (IS_UNIFIED_HANDLE_UNIT(handle)) { return tuho_game->units->getTrackableUnifiedHandlePosition(handle); } else if (IS_UNIFIED_HANDLE_TERRAIN_OBJECT(handle)) { return tuho_game->gameUI->getTerrain()->getTrackableUnifiedHandlePosition(handle); } else { assert(!"TrackableUnifiedHandleObject::getTrackableObjectPosition - Unified handle maps to unsupported object type."); return VC3(0,0,0); } }
void DecalPositionCalculator::calculateDecalRotation(game::GameScene *gameScene, const VC3 &position, QUAT &resultRotation, float yAngle, VC3 &normal) { VC2 p2(position.x, position.z); //normal = gameScene->getTerrain()->getInterpolatedNormal(p2); //normal = gameScene->getTerrain()->getFaceNormal(p2); getNormal(gameScene, position, VC2(0.5f, 0.5f), normal); QUAT rotation; rotation.MakeFromAngles(-PI*.5f, yAngle, 0); rotateToward(normal, VC3(0,1.f,0), resultRotation); resultRotation = rotation * resultRotation; /* VC3 x(rand() % 1000 / 999.f, 0, rand() % 1000 / 999.f); if(x.GetSquareLength() > 0.0001f) x.Normalize(); else x = VC3(1.f, 0, 0); x -= hitNormal * x.GetDotWith(hitNormal); VC3 y = -x.GetCrossWith(hitNormal); assert(fabsf(x.GetDotWith(y)) < 0.0001f); assert(fabsf(x.GetDotWith(hitNormal)) < 0.0001f); MAT tm; tm.Set(0, x.x); tm.Set(1, x.y); tm.Set(2, x.z); tm.Set(4, y.x); tm.Set(5, y.y); tm.Set(6, y.z); tm.Set(8, hitNormal.x); tm.Set(9, hitNormal.y); tm.Set(10, hitNormal.z); resultRotation = tm.GetRotation(); */ }
void showWindowAt(int x, int y) { window->MoveTo(x - 5, y - 5); window->Show(); isVisible = true; closedAck = false; if (game::SimpleOptions::getBool(DH_OPT_B_MENU_AUTOPAUSE)) { // Pause game if(!game.isTacticalMode()) { gameWasRunning = true; game.gameUI->setPointersChangedFlag(game.singlePlayerNumber); } else gameWasRunning = false; game.setTacticalMode(true); } // TODO: client number game::SceneSelection *sel = game.gameUI->getSceneSelection(0); clickPosition = VC3(sel->scaledMapX, game.gameMap->getScaledHeightAt(sel->scaledMapX, sel->scaledMapY), sel->scaledMapY); if (game::SimpleOptions::getBool(DH_OPT_B_MENU_TWO_CLICK)) { // TODO: correct player... if (sel->unit != NULL && sel->unit->visibility.isSeenByPlayer(game.singlePlayerNumber)) { game.gameUI->setUnitHighlight(game.singlePlayerNumber, sel->unit); } else { game.gameUI->setTerrainHighlight(game.singlePlayerNumber, clickPosition); } game.gameUI->lockHighlight(game.singlePlayerNumber); } }
VisualEffect::VisualEffect(VisualEffectType *effectType, IPointableObject *object, IPointableObject *origin, const VC3 &position, const VC3 &endPosition, const VC3 &rotation, int muzzleFlashBarrelNumber) { this->deleteFlag = false; this->effectType = effectType; this->position = VC3(0,0,0); this->visualObject = NULL; this->follow = NULL; this->refCount = 0; this->spotlight = NULL; this->pointlight = UNIFIED_HANDLE_NONE; this->pointlightManager = NULL; this->deleteFrameCounter = 0; this->advanceDeleteCounter = false; init(object, origin, position, endPosition, rotation, muzzleFlashBarrelNumber); visual_effect_allocations++; }