本文整理汇总了C++中Vect函数的典型用法代码示例。如果您正苦于以下问题:C++ Vect函数的具体用法?C++ Vect怎么用?C++ Vect使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Vect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool GameScene::init()
{
if(Scene::initWithPhysics())
{
//this->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
this->getPhysicsWorld()->setGravity(Vect(0,-900));
}
//Ìí¼Ó±³¾°
auto backgroundLayer=BackgroundLayer::create();
if(backgroundLayer)
{
this->addChild(backgroundLayer);
}
auto statusLayer=StatusLayer::create();
//Ìí¼ÓÖ÷ÓÎÏ·²ã
auto gameLayer = GameLayer::create();
if(gameLayer)
{
gameLayer->setPhyWorld(this->getPhysicsWorld());
gameLayer->setDelegator(statusLayer);
this->addChild(gameLayer);
}
//Ìí¼ÓÓÎϷ״̬²ã
if(statusLayer)
{
this->addChild(statusLayer);
}
//Ìí¼Ó¿ØÖƲã
auto optionLayer=OptionLayer::create();
if(optionLayer)
{
optionLayer->setDelegator(gameLayer);
this->addChild(optionLayer);
}
return true;
}
示例2: BattleScene
Scene* BattleScene::scene(const std::string& level)
{
Scene *scene = Scene::createWithPhysics();
Size size=Director::getInstance()->getVisibleSize();
//通过ECS创建场景
auto layer=new BattleScene();
if( layer && layer->initWithColor(Color4B(255*0.91,255*0.91,255*0.91,255),size.width,size.height))
{
layer->autorelease();
scene->getPhysicsWorld()->setGravity(Vect(0,0));
GX::Entity* welcome=GX::GameSystem::getInstance()->getECS()->createEntity("Battle.json");
layer->addChild(welcome->getNode());
scene->addChild(layer);
}
return scene;
}
示例3: random
void TestScene::update(float delta)
{
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
int chance = random(1, 100);
float yPos = random(0.0f, visibleSize.height);
if (chance <= 5)
{
Sprite* mailbox = Sprite::create("mailbox.png");
auto spriteBody = PhysicsBody::createBox(mailbox->boundingBox().size, PhysicsMaterial(1.0f, 0.5f, 0.5f));
mailbox->setPhysicsBody(spriteBody);
mailbox->setPosition(Point(visibleSize.width + origin.x, yPos + origin.y));
mailbox->getPhysicsBody()->setVelocity(Vect(-500, 0));
this->addChild(mailbox);
}
}
示例4: CCLOG
void UserScene::load(){
CCLOG("User Scene load");
getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
getPhysicsWorld()->setGravity(Vect(0,-100));
getPhysicsWorld()->setSpeed(3.0);
syslayer = SysLayer::create();
worldlayer = WorldLayer::create();
worldlayer->setUserScene(this);
battlelayer = BattleLayer::create();
worldlayer->addChild(battlelayer,10);
this->addChild(syslayer);
this->addChild(worldlayer);
WorldSize = worldlayer->getWorldSize();
}
示例5: createScene
Scene* HelloWorld::createScene()
{
Size visibleSize = Director::getInstance()->getVisibleSize();
// 'scene' is an autorelease object
auto scene = Scene::createWithPhysics();
scene->getPhysicsWorld()->setGravity(Vect(0,0));
//scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
// 'layer' is an autorelease object
auto layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
示例6: isHit
void Player::isHit()
{
if (invurnerable)
return;
this->HP -= 10;
this->invurnerable = true;
this->invurnerableTime = 90;
// TODO: discuss if this is necessary
this->getPhysicsBody()->applyImpulse(Vect(-70, 0));
//FadeIn* fadeIn = FadeIn::create(0.5f);
//FadeOut* fadeOut = FadeOut::create(0.5f);
TintBy* tintToWhite = TintBy::create(1, 0, 255, 255);
TintBy* tintBack = tintToWhite->reverse();
//Sequence* sequence = Sequence::create(fadeOut, fadeIn, fadeOut,fadeIn,fadeOut, fadeIn, nullptr);
Sequence* sequence = Sequence::create(tintToWhite, tintToWhite, tintToWhite, nullptr);
this->runAction(sequence);
}
示例7: performCollide
bool EllipseObstacle::performCollide (
Vect pos, Vect::Component rad, Vect spd, float delta,
Vect& outPos, Vect& outSpd, float& outDelta, Vect& norm
) {
if (rad > Ball::MIN_PARTICLE_RADIUS) {
EllipseObstacle el {_center, _rx+rad, _ry+rad, _ang};
return el.collide(pos, 0, spd, delta, outPos, outSpd, outDelta);
}
Matr mScale = Matr::scale(1.f/_rx, 1.f/_ry);
Matr mTrans = Matr::translate(-_center.x(), -_center.y());
Matr mRot = Matr::rotate(_ang);
Vect tPos = pos * mTrans * mRot * mScale;
Vect tSpd = spd * mRot * mScale;
CircleObstacle co {Vect(0.f, 0.f, 1.f), 1.f};
Vect tOutPos, tOutSpd;
bool coll = co.performCollide(
tPos, rad, tSpd, delta,
tOutPos, tOutSpd, outDelta,
norm
);
if (!coll) {
return false;
}
norm = (mScale * mRot).transposed() * norm;
Matr muScale = Matr::scale(_rx, _ry);
Matr muTrans = Matr::translate(_center.x(), _center.y());
Matr muRot = Matr::rotate(-_ang);
outPos = tOutPos * muScale * muRot * muTrans;
outSpd = spd - norm.project(spd) * 2;
return true;
}
示例8: GetKeyState
// Helper function to fire bullet (if necessary)
void Demo::privFireBullet(const float elapsedTime)
{
// Delay between shots
const float waitTime = 2.0f;
static float currTime = waitTime;
currTime += elapsedTime;
// Check whether left mouse button is pressed
short lmb = GetKeyState(VK_LBUTTON);
bool lmbPressed = (lmb & 0x80) != 0;
// Fire if button is pressed and the wait time has elapsed
if (lmbPressed && (!bullet.active || currTime >= waitTime))
{
// Need to figure out our target
float width = cam.nearWidth + (cam.farWidth - cam.nearWidth) * (490.0f - cam.nearDist) / (cam.farDist - cam.nearDist);
float height = cam.nearHeight + (cam.farHeight - cam.nearHeight) * (490.0f - cam.nearDist) / (cam.farDist - cam.nearDist);
// Use current crosshair positions (in screen coordinates)
// and width and height of frustum at distance of blocks
Vect target;
target[0] = crosshairX.position[0] * 0.5f * width;
target[1] = crosshairX.position[1] * 0.5f * height + 50.0f;
target[2] = -490.0f;
target[3] = 1.0f;
currTime = 0.0f;
// Set our velocity to be toward the target point
this->bullet.position = this->cam.vPos;
this->bullet.velocity = target - this->bullet.position;
this->bullet.velocity.norm();
this->bullet.velocity *= 1000.0f;
this->bullet.rotation = Quat(0.0f, 0.0f, 0.0f, 1.0f);
this->bullet.angVelocity = Vect(0.0f, 0.0f, 0.0f);
this->bullet.active = 1;
this->bullet.gravityNow = false;
}
}
示例9: traceIn
void MeshEntity::ResetScale()
{
traceIn(MeshEntity::ResetScale);
if(!mesh)
{
AppWarning(TEXT("ResetScale must be called after MeshEntity::Init()"));
return;
}
bounds = mesh->bounds;
bHasScale = !scale.CloseTo(Vect(1.0f, 1.0f, 1.0f));
if(bHasScale)
{
bounds.Min *= scale;
bounds.Max *= scale;
}
else
scale = 1.0f;
traceOut;
}
示例10: init
bool GameScene::init(){
if(Scene::initWithPhysics()){
// this->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
this->getPhysicsWorld()->setGravity(Vect(0, -900));
// Add the background
auto backgroundLayer = BackgroundLayer::create();
if(backgroundLayer) {
this->addChild(backgroundLayer);
}
auto statusLayer = StatusLayer::create();
// Add the main game layer
auto gameLayer = GameLayer::create();
if(gameLayer) {
gameLayer->setPhyWorld(this->getPhysicsWorld());
gameLayer->setDelegator(statusLayer);
this->addChild(gameLayer);
}
// Add the game status layer to show the score and game status
if(statusLayer) {
this->addChild(statusLayer);
}
// Add operation layer to control the game
auto optionLayer = OptionLayer::create();
if(optionLayer) {
optionLayer->setDelegator(gameLayer);
this->addChild(optionLayer);
}
return true;
}else {
return false;
}
}
示例11: CC_BREAK_IF
bool GameScene::init()
{
bool bRet = false;
do
{
CC_BREAK_IF(!Scene::initWithPhysics());
this->getPhysicsWorld()->setGravity(Vect(0, -900));
auto backgroundLayer = BackgroundLayer::create();
if(backgroundLayer) {
this->addChild(backgroundLayer);
}
auto statusLayer = StatusLayer::create();
auto gameLayer = GameLayer::create();
if(gameLayer) {
gameLayer->setPhyWorld(this->getPhysicsWorld());
gameLayer->setDelegator(statusLayer);
this->addChild(gameLayer);
}
if(statusLayer) {
this->addChild(statusLayer);
}
auto optionLayer = OptionLayer::create();
if(optionLayer) {
optionLayer->setDelegator(gameLayer);
this->addChild(optionLayer);
}
bRet = true;
} while (0);
return bRet;
}
示例12: jump
// Jump action of the Player
// Creates an animation , smooth jumping, and possibility of double-jumping if
// jump key is pressed during this action.
// Sets action to JUMPING
void Player::jump()
{
// Set current action to JUMPING
this->currentAction = Action::JUMPING;
//Stop running animation and replace the sprite png to the jumping one
this->getActionManager()->removeActionByTag(PLAYER_ANIMATION_RUNNING, this);
//TODO: Insert the jumping animation instead of a single frame
// Get resource loader instance
ResourceLoader resLoader = ResourceLoader::getInstance();
// Get running animation
Vector<SpriteFrame*> runningAnimation = resLoader.getAnimation(PLAYER_ANIMATION_RUNNING);
this->setDisplayFrame(runningAnimation.at(1));
//JUMP
//this->getPhysicsBody()->applyImpulse(Vect(0, Director::getInstance()->getWinSize().height *500.0 / 600));
this->getPhysicsBody()->applyImpulse(Vect(0, (Director::getInstance()->getWinSize().height - 600)/3.5 + 500));
}
示例13: Scale
void PumpkinObject::transform(void)
{
// create temp matrices
Matrix Scale(SCALE, 0.75f, 0.75f, 0.75f);
Matrix Trans(TRANS, this->pos[x], this->pos[y], this->pos[z]);
// create local to world matrix (ie Model)
this->World = Scale * Trans;
// camera or object can move over, combined is one relationship ---> ModelView (World * View)
// some pipelines have the project concatenated, others don't
// best to keep them separated, you can always join them with a multiply
this->ModelView = this->World * pCamera->getViewMatrix();
// *************Culling against Frustum**********************
Vect center = this->model->getModelCenter();
center = Vect(0,0,0); // an object's local center will always be its origin?
frustumCalc->setRadius(1.0f);
// update the center and radius of object's bounding sphere with the same World matrix
this->frustumCalc->updateSphere(this->World, center);
// test by picking two corners of camera frustum, test against normals, return true/false (in/out)
this->inView = this->frustumCalc->insideFrustum(center, pCamera);
};
示例14: Vect
Scene* SceneGame::create() {
auto scene = Scene::createWithPhysics();
scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
auto visibleSize = Director::getInstance()->getVisibleSize();
auto body = PhysicsBody::createEdgeBox(visibleSize,
PHYSICSBODY_MATERIAL_DEFAULT, 5.0f);
auto edgeNode = Node::create();
edgeNode->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
edgeNode->setPhysicsBody(body);
scene->addChild(edgeNode);
Vect gravity = Vect(0.0f, 0.0f);
scene->getPhysicsWorld()->setGravity(gravity);
auto layerBg = LayerOfBg::create();
scene->addChild(layerBg, 10);
auto layerRole = LayerOfRole::create();
scene->addChild(layerRole, 20);
return scene;
}
示例15: ignoreAnchorPointForPosition
// on "init" you need to initialize your instance
bool PopUp::init()
{
//////////////////////////////
// 1. super init first
if (!PopUp::initWithColor(Color4B(255, 102, 0, 255)))
{
return false;
}
this->setVisible(false);
ignoreAnchorPointForPosition(false);
this->setAnchorPoint(Vect(0.5, 0.5));
this->setContentSize(Size(300,200));
this->titleLabel = Label::createWithTTF("", "fonts/Marker Felt.ttf", 32);
this->titleLabel->setTextColor(Color4B(255, 255, 255, 255));
this->messageLabel = Label::createWithTTF("", "fonts/Marker Felt.ttf", 32);
this->messageLabel->setTextColor(Color4B(255, 255, 255, 255));
button = ui::Button::create("option.png", "option.png");
Size dialogSize = this->getContentSize();
titleLabel->setPosition(Vec2(dialogSize.width / 2, dialogSize.height - 20));
messageLabel->setPosition(Vec2(dialogSize.width / 2, dialogSize.height - 70));
button ->setPosition(Vec2(dialogSize.width / 2, dialogSize.height - 150));
this->addChild(titleLabel);
this->addChild(messageLabel);
this->addChild(button);
return true;
}