/* @returns the valulated area of circle equation: pi * radius^2 */ double Circle::area() { return 3.14159 * getRadius() * getRadius(); }
void _SnacWinklerForce_Apply_Spherical( void* _context, Node_LocalIndex node_lI, double speedOfSound, Mass* mass, Mass* inertialMass, Force* force, Force* balance ) { Snac_Context* context = (Snac_Context*)_context; MeshLayout* meshLayout = (MeshLayout*)context->meshLayout; Node_ElementIndex nodeElement_I, nodeElementCount; const double factor4 = 1.0f / 4.0f; double radius,theta,phi; Snac_Node* node = Snac_Node_At( context, node_lI ); Coord* coord = Snac_NodeCoord_P( context, node_lI ); #if 0 SnacTemperature_Node* temperatureNodeExt = ExtensionManager_Get( context->mesh->nodeExtensionMgr, node, SnacTemperature_NodeHandle ); double nodeT =temperatureNodeExt->temperature; #endif double nodeT = 0.0; double Fr; float sphF[3]; HexaMD* decomp = (HexaMD*)meshLayout->decomp; Node_GlobalIndex node_gI = context->mesh->nodeL2G[node_lI]; IJK ijk; RegularMeshUtils_Node_1DTo3D( decomp, node_gI, &ijk[0], &ijk[1], &ijk[2] ); radius = sqrt( (*coord)[0]*(*coord)[0] + (*coord)[1]*(*coord)[1] + (*coord)[2]*(*coord)[2] ); theta = acos((*coord)[2]/radius); phi = atan2((*coord)[1],(*coord)[0]); /* loop over all the elements surrounding node_dI */ if( context->gravity > 0.0 ) { if(ijk[1]==0) { nodeElementCount = context->mesh->nodeElementCountTbl[node_lI]; for( nodeElement_I = 0; nodeElement_I < nodeElementCount; nodeElement_I++ ) { Element_LocalIndex element_lI = context->mesh->nodeElementTbl[node_lI][nodeElement_I]; if( element_lI < context->mesh->elementDomainCount ) { Snac_Element* element = Snac_Element_At( context, element_lI ); Material_Index material_I = element->material_I; Snac_Material* material = &context->materialProperty[material_I]; Density phsDensity = material->phsDensity; /* node->density */ Density mantleDensity = 3300.0f; double alpha = material->alpha; double beta = material->beta; double drosub = 0.0f; double p_est = context->pisos + 0.5f * ( phsDensity + drosub ) * context->gravity * ( radius - Spherical_RMin ); double rosubg = context->gravity * ( phsDensity + drosub ) * ( 1.0 - alpha * (nodeT-material->reftemp) + beta * p_est ); double press_norm = 0.0f; float normal[3]; Normal* normal1; Normal* normal2; Normal* normal3; Normal* normal4; double r1,r2,r3,r4; double dhE, area=0.0f, mag_normal; Snac_Element_Tetrahedra* tetra; Snac_Element_Tetrahedra_Surface* surface; r1 = getRadius( Snac_Element_NodeCoord( context, element_lI, 0 ) ); r2 = getRadius( Snac_Element_NodeCoord( context, element_lI, 1 ) ); r3 = getRadius( Snac_Element_NodeCoord( context, element_lI, 5 ) ); r4 = getRadius( Snac_Element_NodeCoord( context, element_lI, 4 ) ); dhE = 0.25f * ( r1 + r2 + r3 + r4 ); tetra = &element->tetra[1]; surface = &tetra->surface[0]; normal1 = &surface->normal; area += surface->area; tetra = &element->tetra[2]; surface = &tetra->surface[1]; normal2 = &surface->normal; area += surface->area; tetra = &element->tetra[6]; surface = &tetra->surface[2]; normal3 = &surface->normal; area += surface->area; tetra = &element->tetra[8]; surface = &tetra->surface[2]; normal4 = &surface->normal; area += surface->area; normal[0] = factor4 * ( (*normal1)[0] + (*normal2)[0] + (*normal3)[0] + (*normal4)[0] ); normal[1] = -1.0f * factor4 * ( (*normal1)[1] + (*normal2)[1] + (*normal3)[1] + (*normal4)[1] ); normal[2] = factor4 * ( (*normal1)[2] + (*normal2)[2] + (*normal3)[2] + (*normal4)[2] ); mag_normal = sqrt( normal[0]*normal[0] + normal[1]*normal[1] + normal[2]*normal[2] ); area *= 0.5f; press_norm = context->pisos + rosubg * ( Spherical_RMin - dhE ); (*force)[0] += factor4 * ( press_norm * area * normal[0] ); (*force)[1] += factor4 * ( press_norm * area * normal[1] ); (*force)[2] += factor4 * ( press_norm * area * normal[2] ); } } } } if( context->restartTimestep == 0 ) { if( context->timeStep == 1 ) { Fr = (*force)[0]*sin(theta)*cos(phi) + (*force)[1]*sin(theta)*sin(phi) + (*force)[2]*cos(theta); node->residualFr = Fr; } } sphF[0] = (*force)[0]*sin(theta)*cos(phi) + (*force)[1]*sin(theta)*sin(phi) + (*force)[2]*cos(theta); sphF[1] = (*force)[0]*cos(theta)*cos(phi) + (*force)[1]*cos(theta)*sin(phi) - (*force)[2]*sin(theta); sphF[2] = -1.0f * (*force)[0]*sin(phi) + (*force)[1]*cos(phi); sphF[0] -= node->residualFr; (*force)[0] = sphF[0]*sin(theta)*cos(phi) + sphF[1]*cos(theta)*cos(phi) - sphF[2]*sin(phi); (*force)[1] = sphF[0]*sin(theta)*sin(phi) + sphF[1]*cos(theta)*sin(phi) + sphF[2]*cos(phi); (*force)[2] = sphF[0]*cos(theta) - sphF[1]*sin(theta); _SnacWinklerForce_Apply_Spherical_North( context, node_lI, force, balance ); _SnacWinklerForce_Apply_Spherical_South( context, node_lI, force, balance ); }
const bool Sphere::isIn( const vgm::Vec3f& P ) const { const float distanceBetweenCenterAndP = (P - m_center).getLength(); return distanceBetweenCenterAndP <= getRadius(); }
void DynamicGoo::paint(QPainter &p){ //Check rutine //Real paint stuff //check if is dragged if (isDragging()){ p.setBrush(Qt::transparent); p.setPen(QPen(color,3)); p.drawEllipse(toPoint(body->GetPosition()), getRadius()+10,getRadius()+10); //p.drawRect(boundingRect()); } //check if is selected and draggable else if (selected && isDragable()){ if (!hasJoint()) p.setPen(QPen(color,3,Qt::DashLine)); else p.setPen(QPen(color,3,Qt::DotLine)); p.setBrush(Qt::transparent); p.drawEllipse(toPoint(body->GetPosition()), getRadius()+10,getRadius()+10); } //paint goo p.setPen(secondaryColor); QColor center=secondaryColor; center.setRgb((center.red()+50 > 255 ? 255 : center.red()+50),(center.green()+50 > 255 ? 255 : center.green()+50),(center.blue()+50 > 255 ? 255 : center.blue()+50)); if (sleeping){ p.setBrush(center); p.drawEllipse(getPPosition(),getRadius(),getRadius()); } else { b2Vec2 speed=body->GetLinearVelocity(); float angle=qAtan2(speed.x,speed.y); float module=(isFalling() ? speed.Length()/8 : (!hasJoint() ? speed.Length()/15 : 0)); p.save(); p.translate(getPPosition()); if (!isDragging()) p.rotate((hasJoint() ? 0 :-angle*180.0/3.141628)); else p.rotate(this->angle); p.setBrush(secondaryColor); p.drawEllipse(QPoint(0,0),qRound(getRadius()-module),qRound(getRadius()+module)); rx=3;//+=(rand()%5-2); ry=-2;//+=(rand()%5-2); counter++; QRadialGradient rg(rx,ry,getRadius()+5); rg.setColorAt(0,center); rg.setColorAt(1,Qt::transparent); p.setBrush(rg); p.drawEllipse(QPoint(0,0),qRound(getRadius()-module),qRound(getRadius()+module)); if ((counter>=delay && !hasJoint()) || isDragging() || isFalling()){ if (!isDragging() && !isFalling()) { bool nE=!(rand()%5); if (eye) nE=rand()%3; if (eye!=nE && nE){ eyeSizeL=qrand()%3+5; eyeSizeR=eyeSizeL+qrand()%4-1; } eye=nE; counter=0; } else if (!eye) { eyeSizeL=qrand()%3+5; eyeSizeR=eyeSizeL+qrand()%4-1; eye=true; this->angle=qrand()%360; } } if (eye && !hasJoint()&& !onGround) { p.setPen(secondaryColor); QRadialGradient rG2(-9,13,eyeSizeL); QRadialGradient rG3(9,13,eyeSizeR); rG2.setColorAt(0,Qt::white); rG2.setColorAt(1,Qt::lightGray); p.setBrush(rG2); p.drawEllipse(QPoint(-9,12),eyeSizeL,eyeSizeL); rG3.setColorAt(0,Qt::white); rG3.setColorAt(1,Qt::lightGray); p.setBrush(rG3); p.drawEllipse(QPoint(9,12),eyeSizeR,eyeSizeR); p.setBrush(Qt::black); p.setPen(Qt::transparent); p.drawEllipse(QPoint(-9,14),2,2); p.drawEllipse(QPoint(9,13),2,2); } p.restore(); } }
void VAO::pushToGPU() { vector<glm::vec3> vertices; vector<glm::vec3> colors; vector<glm::vec3> normals; vector<vaoVertex> vboData; if (GLEW_ARB_vertex_buffer_object) { cout << "Video card supports GL_ARB_vertex_buffer_object." << endl; // Allocate and assign a Vertex Array Object to our handle glGenVertexArrays(1, &vaoID); // Bind our Vertex Array Object as the current used object glBindVertexArray(vaoID); // Reserve a name for the buffer object. glGenBuffers(1, &vboID); // Bind it to the GL_ARRAY_BUFFER target. glBindBuffer(GL_ARRAY_BUFFER, vboID); // Read cloud and get 3 vectors (vertices, colors and normals) if (cloud != NULL) { vector<float> radius = getRadius(); for (unsigned int i = 0; i < cloud->size(); i++) { vaoVertex vertice; vertice.position = glm::vec3(cloud->points[i].x, cloud->points[i].y, cloud->points[i].z); vertice.normal = glm::vec3(cloud->points[i].normal_x, cloud->points[i].normal_y, cloud->points[i].normal_z); vertice.color = glm::vec3(cloud->points[i].r/255.f, cloud->points[i].g/255.f, cloud->points[i].b/255.f); vertice.radius = radius[i]; vboData.push_back(vertice); } } // Allocate space for it (sizeof(vertices) + sizeof(colors)). glBufferData(GL_ARRAY_BUFFER, sizeof(vaoVertex)*vboData.size(), NULL, GL_STATIC_DRAW); // Put "vertices" at offset zero in the buffer. glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vaoVertex)*vboData.size(), &vboData[0]); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(vaoVertex), BUFFER_OFFSET(0)); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(vaoVertex), BUFFER_OFFSET(sizeof(glm::vec3)) ); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(vaoVertex), BUFFER_OFFSET(sizeof(glm::vec3)*2) ); glVertexAttribPointer(3, 1, GL_FLOAT, GL_FALSE, sizeof(vaoVertex), BUFFER_OFFSET(sizeof(glm::vec3)*3) ); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glEnableVertexAttribArray(3); } else { cout << "Video card does NOT support GL_ARB_vertex_buffer_object." << endl; } }
//---------------------------------------------------------- void ofConePrimitive::setMode( ofPrimitiveMode mode ) { ofPrimitiveMode currMode = getMesh().getMode(); if(currMode != mode) set( getRadius(), getHeight(), getResolution().x, getResolution().y, getResolution().z, mode ); }
void CylinderMesh::construct() { int i, firstTop ; int steps = (unsigned int)(complexity * 64.0f) ; float angle ; Point normal ; Box bounds = getBounds() ; Point center = getCenter() ; float radius = getRadius() ; Primitive p ; p.type = Primitive::NoMaterial | Primitive::Strip | Primitive::Indexed ; if (steps < 4) steps = 4 ; if (steps > 64) steps = 64 ; steps &= ~1 ; // Bottom addVertex (center.x(), center.y(), bounds.min.z()) ; for (angle = 0.0f, i = 0 ; i < steps ; i++, angle += 2.0f*M_PI/(float)steps) { addVertex (cosf(angle)*radius + center.x(), sinf(angle)*radius + center.y(), bounds.min.z()) ; } for (i = 1 ; i <= steps ; i++) { p.firstElement = indices.size() ; p.numElements = 3 ; indices.push_back (0) ; indices.push_back (i) ; indices.push_back (i == steps ? 1 : i+1) ; primitives.push_back(p) ; } // Top firstTop = verts.size() ; addVertex (center.x(), center.y(), bounds.max.z()) ; for (angle = 0.0f, i = 0 ; i < steps ; i++, angle += 2.0f*M_PI/(float)steps) { addVertex (cosf(angle)*radius + center.x(), sinf(angle)*radius + center.y(), bounds.max.z()) ; } for (i = 1 ; i <= steps ; i++) { p.firstElement = indices.size() ; p.numElements = 3 ; indices.push_back (firstTop) ; indices.push_back (firstTop+(i == steps ? 1 : i+1)) ; indices.push_back (firstTop+i) ; primitives.push_back(p) ; } // Walls int pos ; for (pos = indices.size(), i = 0 ; i < steps-1 ; i++, pos += 4) { indices.push_back (i+1) ; indices.push_back (firstTop+i+1) ; indices.push_back (i+2) ; indices.push_back (firstTop+i+2) ; p.firstElement = pos ; p.numElements = 4 ; primitives.push_back(p) ; } indices.push_back (i+1) ; indices.push_back (firstTop+i+1) ; indices.push_back (1) ; indices.push_back (firstTop+1) ; p.firstElement = pos ; p.numElements = 4 ; primitives.push_back(p) ; // Other stuff setFrames (1) ; setParent (-1) ; calculateBounds() ; calculateCenter() ; calculateRadius() ; }
/** * @luafunc num Item::getRad() * * @return The radius of the item. For a Teleporter, this is the radius of the * entrance. For a ForceFieldProjector, this is the radius of the base. */ S32 Item::lua_getRad(lua_State *L) { return returnFloat(L, getRadius()); }
void CMobEntity::OnMobSkillFinished(CMobSkillState& state, action_t& action) { auto PSkill = state.GetSkill(); auto PTarget = static_cast<CBattleEntity*>(state.GetTarget()); static_cast<CMobController*>(PAI->GetController())->TapDeaggroTime(); // store the skill used m_UsedSkillIds[PSkill->getID()] = GetMLevel(); PAI->TargetFind->reset(); float distance = PSkill->getDistance(); uint8 findFlags = 0; if (PSkill->getFlag() & SKILLFLAG_HIT_ALL) { findFlags |= FINDFLAGS_HIT_ALL; } // Mob buff abilities also hit monster's pets if (PSkill->getValidTargets() == TARGET_SELF) { findFlags |= FINDFLAGS_PET; } action.id = id; if (objtype == TYPE_PET && static_cast<CPetEntity*>(this)->getPetType() == PETTYPE_JUG_PET && static_cast<CPetEntity*>(this)->getPetType() == PETTYPE_AUTOMATON) action.actiontype = ACTION_PET_MOBABILITY_FINISH; else if (PSkill->getID() < 256) action.actiontype = ACTION_WEAPONSKILL_FINISH; else action.actiontype = ACTION_MOBABILITY_FINISH; action.actionid = PSkill->getID(); if (PTarget && PAI->TargetFind->isWithinRange(&PTarget->loc.p, distance)) { if (PSkill->isAoE()) { PAI->TargetFind->findWithinArea(PTarget, (AOERADIUS)PSkill->getAoe(), PSkill->getRadius(), findFlags); } else if (PSkill->isConal()) { float angle = 45.0f; PAI->TargetFind->findWithinCone(PTarget, distance, angle, findFlags); } else { PAI->TargetFind->findSingleTarget(PTarget, findFlags); } } else { action.actiontype = ACTION_MOBABILITY_INTERRUPT; actionList_t& actionList = action.getNewActionList(); actionList.ActionTargetID = id; actionTarget_t& actionTarget = actionList.getNewActionTarget(); actionTarget.animation = PSkill->getID(); return; } uint16 actionsLength = PAI->TargetFind->m_targets.size(); PSkill->setTotalTargets(actionsLength); PSkill->setTP(state.GetSpentTP()); PSkill->setHPP(GetHPP()); uint16 msg = 0; uint16 defaultMessage = PSkill->getMsg(); bool first {true}; for (auto&& PTarget : PAI->TargetFind->m_targets) { actionList_t& list = action.getNewActionList(); list.ActionTargetID = PTarget->id; actionTarget_t& target = list.getNewActionTarget(); list.ActionTargetID = PTarget->id; target.reaction = REACTION_HIT; target.speceffect = SPECEFFECT_HIT; target.animation = PSkill->getAnimationID(); target.messageID = PSkill->getMsg(); // reset the skill's message back to default PSkill->setMsg(defaultMessage); if (objtype == TYPE_PET && static_cast<CPetEntity*>(this)->getPetType() != PETTYPE_JUG_PET) { target.animation = PSkill->getPetAnimationID(); target.param = luautils::OnPetAbility(PTarget, this, PSkill, PMaster, &action); } else { target.param = luautils::OnMobWeaponSkill(PTarget, this, PSkill); } if (msg == 0) { msg = PSkill->getMsg(); } else { msg = PSkill->getAoEMsg(); } target.messageID = msg; if (PSkill->hasMissMsg()) { target.reaction = REACTION_MISS; target.speceffect = SPECEFFECT_NONE; if (msg = PSkill->getAoEMsg()) msg = 282; } else { target.reaction = REACTION_HIT; } if (target.speceffect & SPECEFFECT_HIT) { target.speceffect = SPECEFFECT_RECOIL; target.knockback = PSkill->getKnockback(); if (first && (PSkill->getSkillchain() != 0)) { CWeaponSkill* PWeaponSkill = battleutils::GetWeaponSkill(PSkill->getSkillchain()); if (PWeaponSkill) { SUBEFFECT effect = battleutils::GetSkillChainEffect(PTarget, PWeaponSkill); if (effect != SUBEFFECT_NONE) { int32 skillChainDamage = battleutils::TakeSkillchainDamage(this, PTarget, target.param); if (skillChainDamage < 0) { target.addEffectParam = -skillChainDamage; target.addEffectMessage = 384 + effect; } else { target.addEffectParam = skillChainDamage; target.addEffectMessage = 287 + effect; } target.additionalEffect = effect; } } first = false; } } PTarget->StatusEffectContainer->DelStatusEffectsByFlag(EFFECTFLAG_DETECTABLE); } }
QString Cylinder::toString () { QString str; pcl::PointXYZ start = getStart (); pcl::PointXYZ end = getEnd (); str.append(QString::number(start.x)).append(QString(",")).append(QString::number(start.y)).append(QString(",")).append(QString::number(start.z)).append(QString(",")); str.append(QString::number(end.x)).append(QString(",")).append(QString::number(end.y)).append(QString(",")).append(QString::number(end.z)).append(QString(",")); str.append(QString::number(getVolume())).append(QString(",")).append(QString::number(getRadius())).append(QString(",")).append(QString::number(getLength())); return str; }
F32 Item::getEditorRadius(F32 currentScale) const { return (getRadius() + 2) * currentScale; }
void EMPMissile::hitObject(P<SpaceObject> object) { DamageInfo info(owner, DT_EMP, getPosition()); SpaceObject::damageArea(getPosition(), blastRange, damageAtEdge, damageAtCenter, info, getRadius()); P<ElectricExplosionEffect> e = new ElectricExplosionEffect(); e->setSize(blastRange); e->setPosition(getPosition()); e->setOnRadar(true); destroy(); }
bool CAutomatonController::TryTPMove() { if (PAutomaton->health.tp >= 1000) { const auto& FamilySkills = battleutils::GetMobSkillList(PAutomaton->m_Family); std::vector<CMobSkill*> validSkills; //load the skills that the automaton has access to with it's skill SKILLTYPE skilltype = SKILL_AME; if (PAutomaton->getFrame() == FRAME_SHARPSHOT) skilltype = SKILL_ARA; for (auto skillid : FamilySkills) { auto PSkill = battleutils::GetMobSkill(skillid); if (PSkill && PAutomaton->GetSkill(skilltype) > PSkill->getParam() && PSkill->getParam() != -1 && distance(PAutomaton->loc.p, PTarget->loc.p) < PSkill->getRadius()) { validSkills.push_back(PSkill); } } int16 currentSkill = -1; CMobSkill* PWSkill = nullptr; int8 currentManeuvers = -1; bool attemptChain = (PAutomaton->getMod(Mod::AUTO_TP_EFFICIENCY) != 0); if (attemptChain) { CStatusEffect* PSCEffect = PTarget->StatusEffectContainer->GetStatusEffect(EFFECT_SKILLCHAIN, 0); if (PSCEffect) { std::list<SKILLCHAIN_ELEMENT> resonanceProperties; if (PSCEffect->GetTier() == 0) { if (PSCEffect->GetStartTime() + 3s < m_Tick) { if (PSCEffect->GetPower()) { CWeaponSkill* PWeaponSkill = battleutils::GetWeaponSkill(PSCEffect->GetPower()); resonanceProperties.push_back((SKILLCHAIN_ELEMENT)PWeaponSkill->getPrimarySkillchain()); resonanceProperties.push_back((SKILLCHAIN_ELEMENT)PWeaponSkill->getSecondarySkillchain()); resonanceProperties.push_back((SKILLCHAIN_ELEMENT)PWeaponSkill->getTertiarySkillchain()); } else { CBlueSpell* oldSpell = (CBlueSpell*)spell::GetSpell(static_cast<SpellID>(PSCEffect->GetSubPower())); resonanceProperties.push_back((SKILLCHAIN_ELEMENT)oldSpell->getPrimarySkillchain()); resonanceProperties.push_back((SKILLCHAIN_ELEMENT)oldSpell->getSecondarySkillchain()); } } } else { resonanceProperties.push_back((SKILLCHAIN_ELEMENT)PSCEffect->GetPower()); } for (auto PSkill : validSkills) { if (PSkill->getParam() > currentSkill) { std::list<SKILLCHAIN_ELEMENT> skillProperties; skillProperties.push_back((SKILLCHAIN_ELEMENT)PSkill->getPrimarySkillchain()); skillProperties.push_back((SKILLCHAIN_ELEMENT)PSkill->getSecondarySkillchain()); skillProperties.push_back((SKILLCHAIN_ELEMENT)PSkill->getTertiarySkillchain()); if (battleutils::FormSkillchain(resonanceProperties, skillProperties) != SC_NONE) { currentManeuvers = 1; currentSkill = PSkill->getParam(); PWSkill = PSkill; } } } } } if (!attemptChain || (currentManeuvers == -1 && PAutomaton->PMaster && PAutomaton->PMaster->health.tp < PAutomaton->getMod(Mod::AUTO_TP_EFFICIENCY))) { for (auto PSkill : validSkills) { int8 maneuvers = luautils::OnMobAutomatonSkillCheck(PTarget, PAutomaton, PSkill); if (maneuvers > -1 && (maneuvers > currentManeuvers || (maneuvers == currentManeuvers && PSkill->getParam() > currentSkill))) { currentManeuvers = maneuvers; currentSkill = PSkill->getParam(); PWSkill = PSkill; } } } // No WS was chosen (waiting on master's TP to skillchain probably) if (currentManeuvers == -1) return false; if (PWSkill) return MobSkill(PTarget->targid, PWSkill->getID()); } return false; }
void RDirNode::applyForces(QuadTree & quadtree) { //child nodes for(std::list<RDirNode*>::iterator it = children.begin(); it != children.end(); it++) { RDirNode* node = (*it); node->applyForces(quadtree); } if(parent == 0) return; DirForceFunctor dff(this); quadtree.visitItemsInBounds(quadItemBounds, dff); gGourceDirNodeInnerLoops += dff.getLoopCount(); //always call on parent no matter how far away applyForceDir(parent); //pull towards parent float parent_dist = distanceToParent(); // * dirs should attract to sit on the radius of the parent dir ie: // should attract to distance_to_parent * normal_to_parent accel += gGourceForceGravity * parent_dist * normalise(parent->getPos() - pos); // * dirs should be pushed along the parent_parent to parent normal by a force smaller than the parent radius force RDirNode* pparent = parent->getParent(); if(pparent != 0) { vec2 parent_edge = (parent->getPos() - pparent->getPos()); vec2 parent_edge_normal = normalise(parent_edge); vec2 dest = (parent->getPos() + (parent->getRadius() + getRadius()) * parent_edge_normal) - pos; accel += dest; } // * dirs should repulse from other dirs of this parent const std::list<RDirNode*> & siblings = parent->getChildren(); if(!siblings.empty()) { vec2 sib_accel; int visible = 1; for(std::list<RDirNode*>::const_iterator it = siblings.begin(); it != siblings.end(); it++) { RDirNode* node = (*it); if(node == this) continue; if(!node->isVisible()) continue; visible++; sib_accel -= normalise(node->getPos() - pos); } //parent circumfrence divided by the number of visible child nodes if(visible>1) { float slice_size = (parent->getRadius() * PI) / (float) (visible+1); sib_accel *= slice_size; accel += sib_accel; } } }
//-------------------------------------------------------------- void ofCylinderPrimitive::setResolution( int radiusSegments, int heightSegments, int capSegments ) { ofPrimitiveMode mode = getMesh().getMode(); set( getRadius(), getHeight(), radiusSegments, heightSegments, capSegments, getCapped(), mode ); }
bool Bullet::render() { SDL_Rect rect = { X()-2, Y(), 4, getRadius()*2 }; SDL_FillRect(SDL_GetVideoSurface(), &rect, 0xffffffff); return isAlive(); }
//-------------------------------------------------------------- void ofConePrimitive::setResolution( int radiusRes, int heightRes, int capRes ) { ofPrimitiveMode mode = getMesh().getMode(); set( getRadius(), getHeight(), radiusRes, heightRes, capRes, mode ); }
void PhysicsCapsuleGeom::onCreate(const PhysicsCapsuleGeom *) { _GeomID = dCreateCapsule(0, getRadius(), getLength()); setCategoryBits(dGeomGetCategoryBits(_GeomID)); setCollideBits(dGeomGetCollideBits(_GeomID)); }
void CircularRegion::modifyRadius(int distance) { EllipticalRegion::modifyHeight(distance); EllipticalRegion::modifyWidth(distance); setRadius(getRadius() + distance); }
Common::Point *ShieldUnit::createTargetPos(int index, int distance, int weaponType, int sourceX, int sourceY) { float ratio; Common::Point *targetPos = new Common::Point; if (getState() == DUS_OFF) { targetPos->x = getPosX(); targetPos->y = getPosY(); } else { switch (weaponType) { case ITEM_BOMB: targetPos->x = getPosX(); targetPos->y = getPosY(); break; case ITEM_CLUSTER: targetPos->x = getPosX(); targetPos->y = getPosY(); break; case ITEM_CRAWLER: ratio = MAX(0.0, 1.0 - (static_cast<float>(getRadius()) / static_cast<float>(distance - 20))); { int maxX = _ai->getMaxX(); int maxY = _ai->getMaxY(); int thisX = (static_cast<int>(sourceX + ratio * (getPosX() - sourceX)) + maxX) % maxX; int thisY = (static_cast<int>(sourceY + ratio * (getPosY() - sourceY)) + maxY) % maxY; targetPos->x = thisX; targetPos->y = thisY; } break; case ITEM_EMP: if (getRadius() + 215 > distance) { // Emp radius double x1 = static_cast<double>(sourceX); double y1 = static_cast<double>(sourceY); double x2 = static_cast<double>(getPosX()); double y2 = static_cast<double>(getPosY()); double r1 = static_cast<double>(215); double r2 = static_cast<double>(getRadius() + 10); double d = static_cast<double>(distance); // Formulae for calculating one point of intersection of two circles float root = sqrt((((r1 + r2) * (r1 + r2)) - (d * d)) * ((d * d) - ((r2 - r1) * (r2 - r1)))); int x = (int)(((x1 + x2) / 2) + ((x2 - x1) * (r1 * r1 - r2 * r2)) / (2 * d * d) + ((y2 - y1) / (2 * d * d)) * root); int y = (int)(((y1 + y2) / 2) + ((y2 - y1) * (r1 * r1 - r2 * r2)) / (2 * d * d) - ((x2 - x1) / (2 * d * d)) * root); targetPos->x = x; targetPos->y = y; } else { ratio = 1 - (getRadius() / static_cast<float>(distance - 20)); targetPos->x = (int16)(sourceX + ratio * (getPosX() - sourceX)); targetPos->y = (int16)(sourceY + ratio * (getPosY() - sourceY)); } if (distance < getRadius()) { targetPos->x = getPosX(); targetPos->y = getPosY(); } break; default: targetPos->x = getPosX(); targetPos->y = getPosY(); break; } } return targetPos; }
//------------------------------------------------------------------------------ // setOuterRadius() - //------------------------------------------------------------------------------ bool DialArcSegment::setOuterRadius(const double x) { if (x >= getRadius()) outerRadius = x; return true; }
Common::Point *AntiAirUnit::createTargetPos(int index, int distance, int weaponType, int sourceX, int sourceY) { float ratio; int radius; Common::Point *targetPos = new Common::Point; if (!distance) distance = 1; switch (weaponType) { case ITEM_BOMB: targetPos->x = getPosX(); targetPos->y = getPosY(); break; case ITEM_CLUSTER: targetPos->x = getPosX(); targetPos->y = getPosY(); break; case ITEM_CRAWLER: radius = getRadius(); if ((distance < radius) || (getState() == DUS_OFF)) { targetPos->x = getPosX(); targetPos->y = getPosY(); } else { ratio = MAX(0, (getRadius() / distance)); targetPos->x = (int16)(getPosX() - ratio * (getPosX() - sourceX)); targetPos->y = (int16)(getPosY() - ratio * (getPosY() - sourceY)); } break; case ITEM_EMP: if (getRadius() + 215 > distance) { // Emp radius double x1 = static_cast<double>(sourceX); double y1 = static_cast<double>(sourceY); double x2 = static_cast<double>(getPosX()); double y2 = static_cast<double>(getPosY()); double r1 = static_cast<double>(215); double r2 = static_cast<double>(getRadius() + 3); double d = static_cast<double>(distance); // Formulae for calculating one point of intersection of two circles float root = sqrt((((r1 + r2) * (r1 + r2)) - (d * d)) * ((d * d) - ((r2 - r1) * (r2 - r1)))); int x = (int)(((x1 + x2) / 2) + ((x2 - x1) * (r1 * r1 - r2 * r2)) / (2 * d * d) + ((y2 - y1) / (2 * d * d)) * root); int y = (int)(((y1 + y2) / 2) + ((y2 - y1) * (r1 * r1 - r2 * r2)) / (2 * d * d) - ((x2 - x1) / (2 * d * d)) * root); targetPos->x = x; targetPos->y = y; } else { ratio = 1 - (getRadius() / static_cast<float>(distance - 20)); targetPos->x = (int16)(sourceX + ratio * (getPosX() - sourceX)); targetPos->y = (int16)(sourceY + ratio * (getPosY() - sourceY)); } break; default: targetPos->x = getPosX(); targetPos->y = getPosY(); break; } return targetPos; }
void DynamicGoo::moveToTarget(){ //Stop to follow if the goo is dragged for the use if (isDragging()) { stopFollow(); return; } if (onGround && groundPoint!=getPPosition()) { onGround=false; } if (isFalling()) return; if (hasJoint()){ return; } if (!hasJoint() && !isDragging() && isOnGround() && target==NULL ){ emit this->nextTargetPlease(NULL); } if (following && !falling){ if (prevTarget){ if (!target->isLinked(prevTarget)){ drop(); return; } QPoint meTarget=target->getPPosition()-getPPosition(); if (toVec(meTarget).Length()>15+radius/10) { stopFollow(); fallDown(); return; } //Compute mx and my for the position float mx,my; mx=(target->getVPosition().x-prevTarget->getVPosition().x); my=(target->getVPosition().y-prevTarget->getVPosition().y); float d=qSqrt(mx*mx+my*my); float md=qSqrt(qPow((target->getVPosition().x-getVPosition().x),2)+qPow((target->getVPosition().y-getVPosition().y),2)); mx/=d; my/=d; float tx,ty; //Compute tehorical x and y tx=(getVPosition().x-prevTarget->getVPosition().x)/mx; ty=(getVPosition().y-prevTarget->getVPosition().y)/my; float yt=my*tx+prevTarget->getVPosition().y; float xt=mx*ty+prevTarget->getVPosition().x; //if my y position is different at least of 12 falldown and return if ((qAbs(getVPosition().y-yt)>getRadius() && qAbs(getVPosition().x-xt)>getRadius()) || (md>d+radius)){ stopFollow(); fallDown(); return; } } //this is a work around for the very ugly bug of the "FLYING GOOS" //description of the bug if no prevTarget is setted but target is and the goo tower start to fall down the goo start to fly //for reach his target! //check if prevtarget is not setted and target is if (!prevTarget && target && !target->isOnGround()){ //compute distance between target and me float d=(target->getVPosition()-getVPosition()).Length(); //if that distance is more than 25 falldown and return //PS: remember that 30 is a single point contact between two goos if (d>=radius*0.2) { stopFollow(); fallDown(); return; } else if (d<radius*0.2){ emit this->nextTargetPlease(target); body->SetLinearVelocity(b2Vec2(0,0)); return; } } b2Vec2 dP; if (target!=NULL /*&& target->getBody()!=NULL*/) dP=target->getVPosition()-this->getVPosition(); else { stopFollow(); fallDown(); return; } if (dP.Length()<=(radius-radius/4.0)/10.0){ emit this->nextTargetPlease(target); body->SetLinearVelocity(b2Vec2(0,0)); return; } if (!prevTarget){ b2Vec2 dvec=(target->getVPosition()-getVPosition()); float d=qSqrt(dvec.x*dvec.x+dvec.y*dvec.y); if (onGround && target->isOnGround() && d<distanceToJoint){ double omega =(dP.x>0 ? speed*body->GetMass() : -speed*body->GetMass()); body->SetAngularVelocity(omega); body->ApplyForceToCenter(body->GetMass()*body->GetWorld()->GetGravity()); } else if (!onGround && d<radius*2) { emit this->nextTargetPlease(target); body->SetLinearVelocity(b2Vec2(0,0)); return; dP.x=(dP.x>0 ? speed*2 : -speed*2); dP.y=body->GetMass()*body->GetWorld()->GetGravity().y; body->ApplyForceToCenter(dP); } else{ body->SetGravityScale(1); stopFollow(); } } else { dP.x=dP.x*speed/dP.Length(); dP.y=dP.y*speed/dP.Length() ; body->SetLinearVelocity(dP); } } }
AnnularRegion::AnnularRegion(const MinorCircleRegion &mcr, Radian w) : MinorCircleRegion(mcr), width(w) { // Make a second MCR with a smaller radius inner = new MinorCircleRegion( getCenter(), getRadius() - w ); }
//-------------------------------------------------------------- void Particle::draw() { ofSetColor( r, g, b ); ofCircle( getPosition().x, getPosition().y, getRadius() ); }
//---------------------------------------------------------- void ofSpherePrimitive::setResolution( int res ) { resolution = res; ofPrimitiveMode mode = getMesh().getMode(); set(getRadius(), getResolution(), mode ); }
void RDirNode::applyForces(QuadTree& quadtree) { //child nodes for(std::list<RDirNode*>::iterator it = children.begin(); it != children.end(); it++) { RDirNode* node = (*it); node->applyForces(quadtree); } if(parent == 0) return; std::vector<QuadItem*> inbounds; int found = quadtree.getItemsInBounds(inbounds, quadItemBounds); std::set<std::string> seen; std::set<std::string>::iterator seentest; //apply forces with other that are inside the 'box' of this nodes radius for(std::vector<QuadItem*>::iterator it = inbounds.begin(); it != inbounds.end(); it++) { RDirNode* d = (RDirNode*) (*it); if(d==this) continue; if(d==parent) continue; if(d->parent==this) continue; if((seentest = seen.find(d->getPath())) != seen.end()) { continue; } seen.insert(d->getPath()); if(isParentOf(d)) continue; if(d->isParentOf(this)) continue; applyForceDir(d); gGourceDirNodeInnerLoops++; } //always call on parent no matter how far away applyForceDir(parent); //pull towards parent float parent_dist = distanceTo(parent); // * dirs should attract to sit on the radius of the parent dir ie: // should attract to distance_to_parent * normal_to_parent accel += gGourceForceGravity * parent_dist * (parent->getPos() - pos).normal(); // * dirs should be pushed along the parent_parent to parent normal by a force smaller than the parent radius force RDirNode* pparent = parent->getParent(); if(pparent != 0) { vec2f parent_edge = (parent->getPos() - pparent->getPos()); vec2f parent_edge_normal = parent_edge.normal(); vec2f dest = (parent->getPos() + (parent->getRadius() + getRadius()) * parent_edge_normal) - pos; accel += dest; } // * dirs should repulse from other dirs of this parent std::list<RDirNode*>* siblings = parent->getChildren(); if(siblings->size() > 0) { vec2f sib_accel; int visible = 1; for(std::list<RDirNode*>::iterator it = siblings->begin(); it != siblings->end(); it++) { RDirNode* node = (*it); if(node == this) continue; if(!node->isVisible()) continue; visible++; sib_accel -= (node->getPos() - pos).normal(); } //parent circumfrence divided by the number of visible child nodes if(visible>1) { float slice_size = (parent->getRadius() * PI) / (float) (visible+1); sib_accel *= slice_size; accel += sib_accel; } } }
//---------------------------------------------------------- void ofSpherePrimitive::setMode( ofPrimitiveMode mode ) { ofPrimitiveMode currMode = getMesh().getMode(); if(currMode != mode) set(getRadius(), getResolution(), mode ); }
void Nuke::hitObject(P<SpaceObject> object) { DamageInfo info(owner, DT_Kinetic, getPosition()); SpaceObject::damageArea(getPosition(), blastRange, damageAtEdge, damageAtCenter, info, getRadius()); P<ExplosionEffect> e = new ExplosionEffect(); e->setSize(blastRange); e->setPosition(getPosition()); e->setOnRadar(true); }
void Particle::setY(float y){ position.y = ofClamp(y,getRadius(),ofGetWindowHeight() - getRadius()); }