当前位置: 首页>>代码示例>>C++>>正文


C++ Vector2D::mult方法代码示例

本文整理汇总了C++中Vector2D::mult方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector2D::mult方法的具体用法?C++ Vector2D::mult怎么用?C++ Vector2D::mult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector2D的用法示例。


在下文中一共展示了Vector2D::mult方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: handleStimulus

void Animal::handleStimulus(Environment *environment, double dt) {
    voiceInterval -= dt;
    
    if (this == environment->getPlayer()) {
        Vector2D movement = environment->getMovement();
        movement = movement.mult(dt);
        translate(movement);
        handleCollisions(environment);
        environment->updateObjectScreen(this);
        
        if (movement.distanceTo(Vector2D()) > 1.0e-5) {
            addEnergy(-dt);
        }
        
        for (int i = 0; i < sensors.size(); i++) {
            sensors[i]->handleStimulus(this, environment, dt);
        }
    } else {
        RandomNumberGenerator *rng = RandomNumberGenerator::getInstance();
        if (curAIStateDuration > 0.0) {
            curAIStateDuration -= dt;
        } else {
            curAIStateDuration = ((double) rng->getInt(500, 3000)) / 1000.0;
            curAIDirection = Vector2D(rng->getInt(-1, 1), rng->getInt(-1, 1));
            curAIDirection = curAIDirection.mult(speed);
        }
        
        Vector2D movement = curAIDirection;
        movement = movement.mult(dt);
        translate(movement);
        handleCollisions(environment);
        environment->updateObjectScreen(this);
    }
}
开发者ID:jefrsilva,项目名称:LD24Awareness,代码行数:34,代码来源:Animal.cpp

示例2: handleCollisions

void Animal::handleCollisions(Environment *environment) {
    Vector2D boundsCorrection;
    if (getBounds().getMinX() < environment->getBounds().getMinX()) {
        boundsCorrection.setX(environment->getBounds().getMinX() - getBounds().getMinX());
    }
    if (getBounds().getMinY() < environment->getBounds().getMinY()) {
        boundsCorrection.setY(environment->getBounds().getMinY() - getBounds().getMinY());
    }
    if (getBounds().getMaxX() > environment->getBounds().getMaxX()) {
        boundsCorrection.setX(environment->getBounds().getMaxX() - getBounds().getMaxX());
    }
    if (getBounds().getMaxY() > environment->getBounds().getMaxY()) {
        boundsCorrection.setY(environment->getBounds().getMaxY() - getBounds().getMaxY());
    }
    translate(boundsCorrection);
    
    std::vector<Object *> nearestObjects = environment->getNearestObjects(this);
    for (int k = 0; k < nearestObjects.size(); k++) {
        Object *nearestObject = nearestObjects[k];
        double distance = getPosition().distanceTo(nearestObject->getPosition());
        double radius = (OBJECT_WIDTH / 2);
        if (distance < 2.0 * radius) {
            Vector2D overlapVector = Vector2D(nearestObject->getPosition(), getPosition());        
            overlapVector = overlapVector.normalize();
            
            double overlapLength = 2.0 * radius - distance;
            overlapVector = overlapVector.mult(overlapLength);
            
            translate(overlapVector);
            
            handleCollision(environment, nearestObject);
        }
    }
}
开发者ID:jefrsilva,项目名称:LD24Awareness,代码行数:34,代码来源:Animal.cpp

示例3:

Vector2D
Vector2D::proj(Vector2D s, Vector2D t)
{

	t.normalise();
	Vector2D proj = t;
	float multiple = proj.dot(s, t) / proj.dot(t, t);
	proj.mult(multiple);
	return proj;

}
开发者ID:MarekBillington,项目名称:Asteroids-Game,代码行数:11,代码来源:Vector2D.cpp

示例4: renderFeedback

void MultiDirectionalEar::renderFeedback(Object *object, Environment *environment) {
    if (object == environment->getPlayer()) {
        Vector2D windowPos = environment->getWindowPos(object->getPosition());        
        for (int i = 0; i < nearestObjects.size(); i++) {
            Object *nearestObject = nearestObjects[i];
            if (nearestObject->getVoice() && nearestObject->getVoiceInterval() <= 0.0) {
                nearestObject->resetVoiceInterval();
                Vector2D objectWindowPos = environment->getWindowPos(nearestObject->getPosition());
                Vector2D relativePos = objectWindowPos.add(windowPos.mult(-1.0));
                relativePos = relativePos.normalize();
                double pan = relativePos.getX();
                
                double nearestObjectDistance = windowPos.distanceTo(objectWindowPos);
                double gain = 1.0 - (nearestObjectDistance / 1000.0);
                if (gain < 0.0) {
                    gain = 0.0;
                }
                
                al_play_sample(nearestObject->getVoice(), gain, pan, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
            }
        }                    
    }
}
开发者ID:jefrsilva,项目名称:LD24Awareness,代码行数:23,代码来源:MultiDirectionalEar.cpp


注:本文中的Vector2D::mult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。