CollisionVolume::CollisionVolume( const std::string& cvTypeString, const float3& cvScales, const float3& cvOffsets ) { // default-initialize *this = CollisionVolume(); int cvType = COLVOL_TYPE_SPHERE; int cvAxis = COLVOL_AXIS_Z; if (!cvTypeString.empty()) { const std::string& cvTypeStr = StringToLower(cvTypeString); const std::string& cvTypePrefix = cvTypeStr.substr(0, 3); switch (cvTypePrefix[0]) { case 'e': { cvType = COLVOL_TYPE_ELLIPSOID; } break; // "ell..." case 'c': { cvType = COLVOL_TYPE_CYLINDER; } break; // "cyl..." case 'b': { cvType = COLVOL_TYPE_BOX; } break; // "box" } if (cvType == COLVOL_TYPE_CYLINDER) { switch (cvTypeStr[cvTypeStr.size() - 1]) { case 'x': { cvAxis = COLVOL_AXIS_X; } break; case 'y': { cvAxis = COLVOL_AXIS_Y; } break; case 'z': { cvAxis = COLVOL_AXIS_Z; } break; default: {} break; // just use the z-axis } } } InitShape(cvScales, cvOffsets, cvType, COLVOL_HITTEST_CONT, cvAxis); }
void PhysicsActor::InitPhysics(float density, float friction, float restitution, eShapeType shapeType, bool isSensor, int groupIndex, int collisionFlags, bool fixedRotation) { if (!theWorld.IsPhysicsSetUp()) { std::cout << "ERROR: World physics must be initialized before Actor's." << std::endl; return; } b2CircleDef circle; b2PolygonDef box; b2ShapeDef* shape; if (shapeType == SHAPETYPE_BOX) { // The extents is just a vector of the box's half widths. // Box2D is tuned for meters, kilograms, and seconds. (Unless you've changed its units.) box.SetAsBox(0.5f*_size.X, 0.5f*_size.Y); shape = &box; } else if (shapeType == SHAPETYPE_CIRCLE) { // TODO: handle ellipse? circle.radius = 0.5f*_size.X; shape = &circle; } else { std::cout << "ERROR: Invalid shape type given." << std::endl; return; } shape->density = density; shape->friction = friction; shape->restitution = restitution; shape->groupIndex = groupIndex; shape->isSensor = isSensor; if( collisionFlags != -1 ) { shape->maskBits = (short)collisionFlags; shape->categoryBits = (short)collisionFlags; } InitShape( shape ); b2BodyDef bd; bd.userData = this; bd.position.Set(_position.X, _position.Y); bd.angle = MathUtil::ToRadians(_rotation); bd.fixedRotation = fixedRotation; if (MathUtil::FuzzyEquals(density, 0.0)) { _physBody = theWorld.GetPhysicsWorld().CreateStaticBody(&bd); } else { _physBody = theWorld.GetPhysicsWorld().CreateDynamicBody(&bd); } _physBody->CreateShape(shape); _physBody->SetMassFromShapes(); CustomInitPhysics(); }
void PhysicsActor::InitPhysics() { if (!theWorld.IsPhysicsSetUp()) { sysLog.Log("ERROR: World physics must be initialized before Actor's."); return; } b2CircleShape circle; b2PolygonShape box; b2Shape* shape = NULL; if (_shapeType == SHAPETYPE_BOX) { // The extents is just a vector of the box's half widths. // Box2D is tuned for meters, kilograms, and seconds. (Unless you've changed its units. [You probably shouldn't.]) box.SetAsBox(0.5f*_size.X, 0.5f*_size.Y); shape = &box; } else if (_shapeType == SHAPETYPE_CIRCLE) { circle.m_radius = 0.5f*_size.X; shape = &circle; } else { sysLog.Log("ERROR: Invalid shape type given."); return; } b2FixtureDef fixtureDef; fixtureDef.shape = shape; fixtureDef.density = _density; fixtureDef.friction = _friction; fixtureDef.restitution = _restitution; fixtureDef.filter.groupIndex = _groupIndex; fixtureDef.isSensor = _isSensor; InitShape( shape ); b2BodyDef bd; bd.userData = this; bd.position.Set(_position.X, _position.Y); bd.angle = MathUtil::ToRadians(_rotation); bd.fixedRotation = _fixedRotation; if (MathUtil::FuzzyEquals(_density, 0.0f)) { bd.type = b2_staticBody; } else { bd.type = b2_dynamicBody; } _physBody = theWorld.GetPhysicsWorld().CreateBody(&bd); _physBody->CreateFixture(&fixtureDef); _physBody->SetUserData(this); CustomInitPhysics(); }
void AAMFit::Fit( IplImage* pFrame, CvRect *pR, int pType ) { if( _model == NULL ) return; AAM_Shape currentShape = InitShape( _model->GetMeanShape(), pR, pType ); int iter = _model->Fit(pFrame, currentShape, 20, false); // TODO: Valahol szivárog egy kis memória - nem mindig _imagePoints = currentShape.getPoints(); }
void Flasher::PreRender(Sur * const psur) { if (m_vdpoint.Size() == 0) InitShape(); psur->SetFillColor(m_ptable->RenderSolid() ? g_pvp->m_fillColor: -1); psur->SetObject(this); // Don't want border color to be over-ridden when selected - that will be drawn later psur->SetBorderColor(-1, false, 0); std::vector<RenderVertex> vvertex; GetRgVertex(vvertex); Texture *ppi; if (m_ptable->RenderSolid() && m_d.m_fDisplayTexture && (ppi = m_ptable->GetImage(m_d.m_szImageA))) { ppi->EnsureHBitmap(); if (m_d.m_imagealignment == ImageModeWrap) { float _minx = FLT_MAX; float _miny = FLT_MAX; float _maxx = -FLT_MAX; float _maxy = -FLT_MAX; for (unsigned i = 0; i < vvertex.size(); i++) { if (vvertex[i].x < _minx) _minx = vvertex[i].x; if (vvertex[i].x > _maxx) _maxx = vvertex[i].x; if (vvertex[i].y < _miny) _miny = vvertex[i].y; if (vvertex[i].y > _maxy) _maxy = vvertex[i].y; } if (ppi->m_hbmGDIVersion) psur->PolygonImage(vvertex, ppi->m_hbmGDIVersion, _minx, _miny, _minx + (_maxx - _minx), _miny + (_maxy - _miny), ppi->m_width, ppi->m_height); } else { if (ppi->m_hbmGDIVersion) psur->PolygonImage(vvertex, ppi->m_hbmGDIVersion, m_ptable->m_left, m_ptable->m_top, m_ptable->m_right, m_ptable->m_bottom, ppi->m_width, ppi->m_height); else { // Do nothing for now to indicate to user that there is a problem } } } else psur->Polygon(vvertex); }
void Daggerstorm::Cast(ObjectRef user, ObjectRef enemy) { for (int i = 0; i < 8; i++) { auto projectileObject = Object::Create(); projectileObject->SetJustEnabled(); static int projectileNumber = 0; std::string name = std::string("projectile") + std::to_string(projectileNumber++); projectileObject->SetName(name); auto projectileComp = projectileObject->AddComponent<ProjectileComponent>(); auto spriteComp = projectileObject->AddComponent<SpriteComponent>(); auto colliderComp = projectileObject->AddComponent<ColliderComponent>(); Vector2f direction = directions[i]; projectileComp->SetDirection(direction); projectileComp->SetSpeed(projectileSpeed); projectileComp->SetSpell(this); projectileComp->SetUser(user); projectileComp->SetCanApplyOnUser(false); spriteComp->SetTexture("dagger.png"); spriteComp->SetSize(Vector2f(20, 40)); colliderComp->InitShape("rectangle", "20, 20"); colliderComp->SetIsStatic(false); colliderComp->SetIsPhantom(true); Vector2f userPos = user->GetComponent<SpriteComponent>()->GetSize(); Vector2f startingPos = user->GetPos() + userPos/2.f; Vector2f projectileSize = spriteComp->GetSize(); float magic = (sqrt(pow(projectileSize.x, 2) + pow(projectileSize.y, 2))) / 2; projectileObject->SetPos(startingPos + magic * direction); g_menuHandler->GetCurrentMenu()->AddChild(std::move(projectileObject)); } r_cooldown = cooldown; }
HRESULT Flasher::Init(PinTable *ptable, float x, float y, bool fromMouseClick) { m_ptable = ptable; m_d.m_IsVisible = true; m_d.m_vCenter.x = x; m_d.m_vCenter.y = y; m_d.m_rotX = 0.0f; m_d.m_rotY = 0.0f; m_d.m_rotZ = 0.0f; SetDefaults(fromMouseClick); InitShape(); InitVBA(fTrue, 0, NULL); return S_OK; }
void CollisionVolume::InitBox(const float3& scales) { InitShape(scales, ZeroVector, COLVOL_TYPE_BOX, COLVOL_HITTEST_CONT, COLVOL_AXIS_Z); }
void CollisionVolume::InitSphere(float radius) { // <r> is the object's default RADIUS (not its diameter), // so we need to double it to get the full-length scales InitShape(float3(1.0f, 1.0f, 1.0f) * radius * 2.0f, ZeroVector, COLVOL_TYPE_SPHERE, COLVOL_HITTEST_CONT, COLVOL_AXIS_Z); }