本文整理汇总了C++中Vector2F类的典型用法代码示例。如果您正苦于以下问题:C++ Vector2F类的具体用法?C++ Vector2F怎么用?C++ Vector2F使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vector2F类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
//=============================================================================
Vector2F Rectangle2::up_() const
{
Vector2F result = width_;
result.setPerpendLeft();
result.setLength(height_);
return result;
}
示例2: FindIntersectedRectangles
const RectangleF* FieldController::FindClosestRectangles(RectangleF* pRectangle, Chromosome* pChromosome, bool bDirection)
{
std::vector<const RectangleF*> pModels = FindIntersectedRectangles(pRectangle, pChromosome, bDirection);
const RectangleF* pResultModel = NULL;
Vector2F projectionAxis;
if (!bDirection)
projectionAxis = Vector2F(0, 1);
else
projectionAxis = Vector2F(1, 0);
Vector2F min, max, modelMin, modelMax;
float minLength = 12345678.f;
GetProjection(pRectangle, projectionAxis, modelMin, modelMax);
for (int i = 0, i_end = pModels.size(); i < i_end; ++i)
{
GetProjection(pModels[i], projectionAxis, min, max);
// we are interested in one side models only
if (min > modelMin)
{
Vector2F lengthVec = (modelMax - min);
float tempLength = lengthVec.X() * lengthVec.X() + lengthVec.Y() * lengthVec.Y();
if (tempLength < minLength)
{
pResultModel = pModels[i];
minLength = tempLength;
}
}
}
return pResultModel;
}
示例3: getDir
//=============================================================================
double Ray2::nearestParam( const Point2F& pt )
{
double parameter = 0.0;
Vector2F dir = getDir();
dir.setPerpendLeft();
intersectParam( *this, Ray2(pt, dir), parameter);
return parameter;
}
示例4: up_
//=============================================================================
void Rectangle2::originIsCenter_()
{
Vector2F dw = width_;
Vector2F dh = up_();
dw.multiply(-0.5);
dh.multiply(-0.5);
origin_.add(dw);
origin_.add(dh);
}
示例5: adjustMenuPos
/*---------------------------------------------------------------------*//**
メニューの位置調整
**//*---------------------------------------------------------------------*/
void FocusMenu::adjustMenuPos(MenuKind mkind)
{
// フォローなしの場合は必要なし
if(_unitFllowRef[mkind] == 0) { return; }
do
{
MenuTreeNode* mtnode = _menu[mkind]->getCurrentMenuNode();
if(mtnode == 0L) { break; }
MenuWindow* mwnd = (MenuWindow*)mtnode->getPanel();
if(mwnd == 0L) { break; }
const RectF32* rectMwnd = mwnd->getRectangle();
// 対象がいなくなった
if(!_unitFllowRef[mkind]->isEnable())
{
break; // メニューを閉じる
}
// スクリーン座標に変換
Vector2F vScr;
CalcUtils::calc3dPosToScreenPos(&vScr, _unitFllowRef[mkind]->getCenterPos());
f32 x = vScr.x();
f32 y = vScr.y();
// ユニット自体が画面外に出たときはメニューを閉じる
if((x < 0) || (x > Game::getGame()->getLogicalWidth()) || (y < 0) || (y > Game::getGame()->getLogicalHeight()))
{
break; // メニューを閉じる
}
// 画面内に収めるように位置修正
if((x + rectMwnd->w()) > Game::getGame()->getLogicalWidth()) { x = Game::getGame()->getLogicalWidth() - rectMwnd->w(); }
else if(x < 0) { x = 0; }
if((y + rectMwnd->h()) > Game::getGame()->getLogicalHeight()) { y = Game::getGame()->getLogicalHeight() - rectMwnd->h(); }
else if(y < 0) { y = 0; }
// 修正を反映
if((x != rectMwnd->x()) || (y != rectMwnd->y()))
{
PointF32 pt(x, y);
mwnd->move(&pt);
}
return; // 正常終了
}
while(false);
// なんらかエラーが発生したのでメニューを閉じる
_menu[mkind]->closeMenu();
}
示例6: LookAt
//----------------------------------------------------------------------------
void Player::LookAt(const Vector2F& rLookAt)
{
mLookAt = rLookAt;
Application* pApp = Application::GetApplication();
const Float width = pApp->GetWidthF() * 0.5F;
Float deadZoneX = width * mLookUpDeadZone.X();
Float xB = width - deadZoneX;
if (rLookAt.X() > deadZoneX)
{
mYawIncrement -= mRotateSpeed * (rLookAt.X() - deadZoneX) / xB;
}
else if (rLookAt.X() < -deadZoneX)
{
mYawIncrement -= mRotateSpeed * (rLookAt.X() + deadZoneX) / xB;
}
const Float height = pApp->GetHeightF() * 0.5F;
Float deadZoneY = height * mLookUpDeadZone.Y();
Float yB = height - deadZoneY;
if (rLookAt.Y() > deadZoneY)
{
mPitchIncrement -= mRotateSpeed * (rLookAt.Y() - deadZoneY) / yB;
}
else if (rLookAt.Y() < -deadZoneY)
{
mPitchIncrement -= mRotateSpeed * (rLookAt.Y() + deadZoneY) / yB;
}
}
示例7: PointInPolygon
int grinliz::PointInPolygon( const Vector2F& p, const Vector2F* vertex, int numVertex )
{
for( int i=0; i<numVertex; ++i )
{
// Inside if every point is to the left.
int j = (i+1)%numVertex;
Vector2F line = vertex[j]-vertex[i];
line.RotatePos90();
if ( DotProduct( line, p - vertex[i] ) < 0.0f )
return REJECT;
}
return INTERSECT;
}
示例8: acos
inline float Vector2F::Angle (Vector2F const& other) const
{
// P.Q = ||P|| * ||Q|| * cos(theta)
// P.Q/(||P|| * ||Q||) = cos(theta)
// Therefore, theta = arccos( P.Q/(||P|| * ||Q||) )
return acos(Dot(other)/(Norm() * other.Norm()));
}
示例9: while
void World::GenerateEnemies(Player &player)
{
GameObjectFactory *factory = GameObjectFactory::GetInstance();
const int numEnemies = GameMath::Random(100, 50);
int x;
int y;
for(int i = 0; i < numEnemies; i++)
{
bool valid = false;
while(!valid)
{
valid = true;
do
{
x = rand() % COLS;
y = rand() % ROWS;
}while(At(x, y).IsObstacle());
Vector2 enemyCoords(x, y);
for(std::vector<Enemy*>::iterator it = enemies.begin(); it != enemies.end(); ++it)
{
if(enemyCoords == (*it)->GetCoords())
{
valid = false;
break;
}
}
if(valid)
{
Vector2F enemyPosition = enemyCoords.toV2F() * Tile::TILE_SIZE;
if(enemyPosition.DistanceTo(player.position) >= 500)
{
Enemy *newEnemy = factory->CreateRandomWorldEnemy(enemyCoords, player.level);
enemies.push_back(newEnemy);
}
}
}
}
}
示例10: switch
bool Scene::Process3DTap(int action, const grinliz::Vector2F& view, const grinliz::Ray& world, Engine* engine)
{
Ray ray;
bool result = false;
switch( action )
{
case GAME_PAN_START:
{
game->GetScreenport().ViewProjectionInverse3D( &dragData3D.mvpi );
engine->RayFromViewToYPlane( view, dragData3D.mvpi, &ray, &dragData3D.start3D );
dragData3D.startCameraWC = engine->camera.PosWC();
dragData3D.end3D = dragData3D.start3D;
dragData3D.start2D = dragData3D.end2D = view;
threeDTapDown = true;
break;
}
case GAME_PAN_MOVE:
case GAME_PAN_END:
{
// Not sure how this happens. Why is the check for down needed??
if( threeDTapDown ) {
Vector3F drag;
engine->RayFromViewToYPlane( view, dragData3D.mvpi, &ray, &drag );
dragData3D.end2D = view;
Vector3F delta = drag - dragData3D.start3D;
GLASSERT( fabsf( delta.x ) < 1000.f && fabsf( delta.y ) < 1000.0f );
delta.y = 0;
drag.y = 0;
dragData3D.end3D = drag;
if ( action == GAME_TAP_UP ) {
threeDTapDown = false;
Vector2F vDelta = dragData3D.start2D - dragData3D.end2D;
if ( vDelta.Length() < 10.f )
result = true;
}
engine->camera.SetPosWC(dragData3D.startCameraWC - delta);
}
break;
}
}
return result;
}
示例11: Exception
void Shader::SendVector2(const std::string &pVarName, const Vector2F &pVector){
float toSend[2];
pVector.XY(toSend);
glUniform2fv(glGetUniformLocation(mProgram, pVarName.c_str()), 1, toSend);
#ifdef _DEBUG
GLenum error = GL_NO_ERROR;
if((error = glGetError()) != GL_NO_ERROR){
throw Exception(String("OpenGL Error: \"")+GetGLErrorStr(error)+"\" in function \"SendVector2\"\n\tDoes \""+pVarName+"\" exists or has the right type?");
}
#endif
}
示例12: GetPickRay
//----------------------------------------------------------------------------
void Camera::GetPickRay(const Vector2F& rPosition, Vector3F& rRayOrigin,
Vector3F& rRayDirection)
{
WIRE_ASSERT(rPosition.X() >= -1.0F && rPosition.X() <= 1.0F);
WIRE_ASSERT(rPosition.Y() >= -1.0F && rPosition.Y() <= 1.0F);
Matrix4F projectionMatrix = GetProjectionMatrix();
Vector3F v(rPosition.X() / projectionMatrix(0, 0),
rPosition.Y() / projectionMatrix(1, 1), 1);
rRayDirection = GetViewMatrixInverse34().Times3(v);
rRayOrigin = GetViewMatrixInverse34().GetColumn(3);
}
示例13:
//=============================================================================
Point2F Ray2::getPoint(double parameter, double offset) const
{
Vector2F delta = dir_;
delta.multiply(parameter);
Point2F result = origin_;
result.add(delta);
if (offset == 0.0) return result;
Vector2F offsetVec = dir_;
offsetVec.setPerpendLeft();
offsetVec.multiply( offset/offsetVec.getLength() );
result.add(offsetVec);
return result;
}
示例14: projectionAxis
void FieldController::GetProjection(const RectangleF* pRect, const Vector2F& dir, Vector2F& min, Vector2F& max)
{
Vector2F projectionAxis(-dir.Y(), dir.X());
float sqrlen = projectionAxis.X() * projectionAxis.X() + projectionAxis.Y() * projectionAxis.Y();
// projection rectangle points to projAxis
float dp = pRect->GetTopLeft().X() * projectionAxis.X() + pRect->GetTopLeft().Y() * projectionAxis.Y();
float tempValue = dp / sqrlen;
min.X() = tempValue * projectionAxis.X();
min.Y() = tempValue * projectionAxis.Y();
dp = pRect->GetBottomRight().X() * projectionAxis.X() + pRect->GetBottomRight().Y() * projectionAxis.Y();
tempValue = dp / sqrlen;
max.X() = tempValue * projectionAxis.X();
max.Y() = tempValue * projectionAxis.Y();
}
示例15: TFW_SET_FLAG
/*---------------------------------------------------------------------*//**
フレーム制御
**//*---------------------------------------------------------------------*/
void MoveCursor::exec(ExecRes* res, const ExecCtx* ec)
{
if(TFW_IS_FLAG(_edchFlags, EDCH_EXT_MASK)) { return; } // 外部からの無効化
// 歩行処理
GameExecCtx* gec = (GameExecCtx*)ec;
TouchPanel* ui = gec->getTouchPanel();
bool isEnableSelf = (!gec->isOpenedLockGui()) && (!gec->isLockOperating());
TFW_SET_FLAG(_edchFlags, EDCH_SELF, !isEnableSelf);
if(isEnableSelf && !ui->isReacted())
{
// 差分を求める
Vector2F vDiff;
do
{
// 最初にクリックしたとこからの差分で移動
bool isTouched = _isTouching;
_isTouching = (ui->getTouchingNum() == 1);
// タッチ時のポイントを得る
if(!isTouched && _isTouching) // タッチした
{
ui->getTouchPosition(_ptTouchStart); // 開始のタッチ位置を得る
ui->setDragOperating(true);
_ext->onTapStart(_ptTouchStart);
}
else if(isTouched && !_isTouching) // 離した
{
// UI 反応済みフラグを立てるかどうかの判定
Vector2F vDiff( (f32)(_ptTouchLast->x() - _ptTouchStart->x()), (f32)(_ptTouchLast->y() - _ptTouchStart->y()) );
f32 lenDiffSq = vDiff.lengthSq();
if(lenDiffSq >= LEN_MIN_SQ) // 最小長さを超えている
{
ui->setReacted(true); // 反応済みフラグを立てる
}
_ptTouchStart->set(F32_PMAX, F32_PMAX);
_ptTouchLast->set(F32_PMAX, F32_PMAX);
_xDiff = 0;
_yDiff = 0;
_ext->onTapEnd();
break; // 差分計算から抜ける
}
if(_isTouching)
{
ui->getTouchPosition(_ptTouchLast); // 現在のタッチ位置を得る
}
// 差分を計算する
vDiff.set( (f32)(_ptTouchLast->x() - _ptTouchStart->x()), (f32)(_ptTouchLast->y() - _ptTouchStart->y()) );
f32 lenDiffPw = vDiff.lengthSq();
if(lenDiffPw > LEN_MAX_SQ) // 最大長さを超えている
{
// 最大長さに収める
vDiff.normalize();
vDiff *= LEN_MAX;
// タッチ位置の補正
_ptTouchLast->x() = _ptTouchStart->x() + (s32)vDiff.x();
_ptTouchLast->y() = _ptTouchStart->y() + (s32)vDiff.y();
ui->setReacted(true); // 反応済みフラグを立てる
}
else if(lenDiffPw < LEN_MIN_SQ) // 最小長さ未満
{
vDiff.set(0.0f, 0.0f);
_xDiff = 0;
_yDiff = 0;
break; // 差分計算から抜ける
}
else
{
ui->setReacted(true); // 反応済みフラグを立てる
}
_xDiff = (s32)vDiff.x();
_yDiff = (s32)vDiff.y();
}
while(false);
// 描画用に角度を得ておく
Calc::calcAngle(&_angle, vDiff.x(), vDiff.y());
}
else if(_isTouching)
{
_xDiff = 0;
_yDiff = 0;
_isTouching = false;
_ext->onTapEnd();
}
// 2点間の距離を求める
f32 lenPw = (f32)((_xDiff * _xDiff) + (_yDiff * _yDiff));
_length = ::sqrtf(lenPw);
_rateLength = _length / LEN_MAX;
// 状態を更新する
if(_length < LEN_WALK)
{
_state = STATE_STOP;
//.........这里部分代码省略.........