本文整理汇总了C++中Vec2类的典型用法代码示例。如果您正苦于以下问题:C++ Vec2类的具体用法?C++ Vec2怎么用?C++ Vec2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vec2类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: Vec2
void CHUD::AutoSnap()
{
const float fRadius = 25.0f;
static Vec2 s_vCursor = Vec2(0,0);
if(fabsf(m_fAutosnapCursorControllerX)>0.1 || fabsf(m_fAutosnapCursorControllerY)>0.1)
{
s_vCursor.x = m_fAutosnapCursorControllerX * 30.0f;
s_vCursor.y = m_fAutosnapCursorControllerY * 30.0f;
}
else
{
s_vCursor.x = m_fAutosnapCursorRelativeX;
s_vCursor.y = m_fAutosnapCursorRelativeY;
}
if(m_bOnCircle && s_vCursor.GetLength() < fRadius*0.5f)
{
m_fAutosnapCursorRelativeX = 0;
m_fAutosnapCursorRelativeY = 0;
m_bOnCircle = false;
}
if(s_vCursor.GetLength() > fRadius)
{
s_vCursor.NormalizeSafe();
m_fAutosnapCursorRelativeX = s_vCursor.x*fRadius;
m_fAutosnapCursorRelativeY = s_vCursor.y*fRadius;
m_bOnCircle = true;
}
const char* autosnapItem = "Center";
if(m_bOnCircle)
{
Vec2 vCursor = s_vCursor;
vCursor.NormalizeSafe();
float fAngle;
if(vCursor.y < 0)
{
fAngle = RAD2DEG(acos_tpl(vCursor.x));
}
else
{
fAngle = RAD2DEG(gf_PI2-acos_tpl(vCursor.x));
}
char szAngle[32];
sprintf(szAngle,"%f",-fAngle+90.0f);
/*
ColorB col(255,255,255,255);
int iW=m_pRenderer->GetWidth();
int iH=m_pRenderer->GetHeight();
m_pRenderer->Set2DMode(true,iW,iH);
m_pRenderer->GetIRenderAuxGeom()->DrawLine(Vec3(iW/2,iH/2,0),col,Vec3(iW/2+vCursor.x*100,iH/2+vCursor.y*100,0),col,5);
m_pRenderer->Set2DMode(false,0,0);
*/
m_animQuickMenu.CheckedSetVariable("Root.QuickMenu.Circle.Indicator._rotation",szAngle);
if(fAngle >= 342 || fAngle < 52)
{
autosnapItem = "Strength";
}
else if(fAngle >= 52 && fAngle < 128)
{
autosnapItem = "Speed";
}
else if(fAngle >= 128 && fAngle < 205)
{
autosnapItem = "Defense";
}
else if(fAngle >= 205 && fAngle < 260)
{
autosnapItem = "Weapon";
}
else if(fAngle >= 260 && fAngle < 342)
{
autosnapItem = "Cloak";
}
}
m_animQuickMenu.CheckedInvoke("Root.QuickMenu.setAutosnapItem", autosnapItem);
}
开发者ID:mrwonko,项目名称:CrysisVR,代码行数:84,代码来源:HUDInterfaceEffects.cpp
示例2: inBounds
bool Level::inBounds(Vec2 pos) const {
return pos.inRectangle(getBounds());
}
开发者ID:Eldhelion,项目名称:keeperrl,代码行数:3,代码来源:level.cpp
示例3: warp
void warp(const QImage& Isrc,
const CachedLine2* lines_src,
const CachedLine2* lines_dst,
int lines_num,
QImage& Idst,
float a,float b,float p)
{
assert(Isrc.size()==Idst.size());
int h=Isrc.height(),w=Isrc.width();
uint rgba;
float u,v;
float dist,wgt,wgt_sum=0.f;
Vec2 D,D_sum;
Point2 Xdst,Xsrc;
Vec2 PX;
for(int y=0;y<h;++y)
{
for(int x=0;x<w;++x)
{
// every pixel in dest image
Xdst.x=x;Xdst.y=y;
D_sum.x=D_sum.y=0.f;wgt_sum=0.f;
for(int ln=0;ln<lines_num;++ln)
{
PX=Xdst-lines_dst[ln].P;
u=PX*lines_dst[ln].vec; // vec/norm2
v=PX*lines_dst[ln].unit_perpendicular;
Xsrc=lines_src[ln].P+
u*lines_src[ln].vec+ // vec
v*lines_src[ln].unit_perpendicular;
D=Xsrc-Xdst;
if(u<0.f)
dist=PX.length();
else if(u>1.f)
dist=(Xdst-lines_dst[ln].Q).length();
else
dist=fabsf(v);
wgt=lines_dst[ln].weight(dist,a,b,p);
D_sum+=D*wgt;
wgt_sum+=wgt;
}
Xsrc=Xdst+(D_sum/wgt_sum);
rgba=bilinear_fetch(Isrc,Xsrc.x,Xsrc.y);
Idst.setPixel(x,y,rgba);
// QRgb rr=Idst.pixel(x,y);
// //if(x>=0&&x<w&&y>=0&&y)
// assert((rr&(0x00ffffff))==(rgba&(0x00ffffff)));
}
}
}
开发者ID:V-Italy,项目名称:viewmorphing,代码行数:65,代码来源:morph.cpp
示例4: isWithinVision
bool Level::isWithinVision(Vec2 from, Vec2 to) const {
return from.distD(to) <= darkViewRadius || getSquare(to)->getLight() > 0.3;
}
开发者ID:Nekoninja,项目名称:keeperrl,代码行数:3,代码来源:level.cpp
示例5: operator
bool operator() (const SSpectacularKillAnimation& killAnim) const
{
const SSpectacularKillCVars& skCVars = g_pGameCVars->g_spectacularKill;
const CActor* pOwner = m_spectacularKill.m_pOwner;
// 0. the anim shouldn't be redundant
if (((gEnv->pTimer->GetFrameStartTime().GetSeconds() - s_lastKillInfo.timeStamp) <= skCVars.minTimeBetweenSameKills) &&
(killAnim.killerAnimation.compare(s_lastKillInfo.killerAnim)))
{
SK_DEBUG_LOG("GetValidAnim - %s is not valid: This animation was last played %.1f ago, a minimum time of %.1f is required",
killAnim.killerAnimation.c_str(), (gEnv->pTimer->GetFrameStartTime().GetSeconds() - s_lastKillInfo.timeStamp), skCVars.minTimeBetweenSameKills);
return true;
}
// 1. the killer needs to be within a certain distance from the target
IEntity* pTargetEntity = m_pTarget->GetEntity();
IEntity* pKillerEntity = pOwner->GetEntity();
const QuatT& killerTransform = pOwner->GetAnimatedCharacter()->GetAnimLocation();
const QuatT& targetTransform = m_pTarget->GetAnimatedCharacter()->GetAnimLocation();
const Vec3& vKillerPos = killerTransform.t;
const Vec3& vTargetPos = targetTransform.t;
Vec2 vKillerToTarget = Vec2(vTargetPos) - Vec2(vKillerPos);
float distance = vKillerToTarget.GetLength();
const float optimalDistance = killAnim.optimalDist;
if ((optimalDistance > 0.0f) && (fabs_tpl(distance - optimalDistance) > skCVars.maxDistanceError))
{
#ifndef _RELEASE
if (g_pGameCVars->g_spectacularKill.debug > 1)
{
// visually shows why it failed
IPersistantDebug* pPersistantDebug = m_spectacularKill.BeginPersistantDebug();
const float fConeHeight = killAnim.optimalDist + skCVars.maxDistanceError;
pPersistantDebug->AddPlanarDisc(vTargetPos, killAnim.optimalDist - skCVars.maxDistanceError, killAnim.optimalDist + skCVars.maxDistanceError, Col_Coral, 6.0f);
pPersistantDebug->AddLine(vKillerPos, vKillerPos + Vec3(0.f, 0.f, 5.0f), Col_Red, 6.f);
}
SK_DEBUG_LOG("GetValidAnim - %s is not valid: Distance between actors should be %.2f, is %.2f (max error is %f)",
killAnim.killerAnimation.c_str(), optimalDistance, distance, skCVars.maxDistanceError);
#endif
return true;
}
// 2. The killer needs to be facing the target within cosLookToConeHalfAngleRadians angle
Vec2 vKillerDir(killerTransform.GetColumn1()); // In decoupled catchup mode we need the animated character's orientation
vKillerDir.Normalize();
if (vKillerToTarget.GetNormalizedSafe().Dot(vKillerDir) <= skCVars.minKillerToTargetDotProduct)
{
SK_DEBUG_LOG("GetValidAnim - %s is not valid: Killer is not looking within %.2f degrees towards the target",
killAnim.killerAnimation.c_str(), RAD2DEG(acos_tpl(skCVars.minKillerToTargetDotProduct) * 2.0f));
return true;
}
// 3. If specified, the killer needs to be within a certain angle range from a given reference orientation from the target
// e.g. Specifying referenceAngle 180 means using the back of the target as the center of the angle range
// (imagine it as a cone) where the killer has to be for the kill to be valid
if (killAnim.targetToKillerAngle >= 0.f)
{
const float referenceAngle = killAnim.targetToKillerAngle;
// Find the reference vector which will be the center of the allowed angle range
Vec2 vTargetDir(targetTransform.GetColumn1());
vTargetDir.Normalize();
// 2D rotation
Vec2 vReferenceDir((vTargetDir.x * cosf(referenceAngle)) - (vTargetDir.y * sinf(referenceAngle)),
(vTargetDir.y * cosf(referenceAngle)) + (vTargetDir.x * sinf(referenceAngle)));
if (vKillerToTarget.GetNormalizedSafe().Dot(-vReferenceDir) <= killAnim.targetToKillerMinDot)
{
#ifndef _RELEASE
if (g_pGameCVars->g_spectacularKill.debug > 1)
{
// visually shows why it failed
IPersistantDebug* pPersistantDebug = m_spectacularKill.BeginPersistantDebug();
const float fConeHeight = killAnim.optimalDist + skCVars.maxDistanceError;
pPersistantDebug->AddCone(vTargetPos + (vReferenceDir * fConeHeight), -vReferenceDir, killAnim.targetToKillerMinDot * fConeHeight * 2.0f, fConeHeight, Col_Coral, 6.f);
pPersistantDebug->AddLine(vKillerPos, vKillerPos + Vec3(0.f, 0.f, 5.0f), Col_Red, 6.f);
}
float targetToKillerDot = vTargetDir.GetNormalizedSafe().Dot(-vKillerToTarget);
SK_DEBUG_LOG("GetValidAnim - %s is not valid: Killer is not within a %.2f degrees cone centered on the target's %.2f degrees. Killer is at %.2f angles respect the target",
killAnim.killerAnimation.c_str(), RAD2DEG(acos_tpl(killAnim.targetToKillerMinDot) * 2.0f), RAD2DEG(killAnim.targetToKillerAngle), RAD2DEG(acos_tpl(targetToKillerDot)));
#endif
return true;
}
}
SK_DEBUG_LOG("GetValidAnim - %s is valid", killAnim.killerAnimation.c_str());
return false;
}
开发者ID:aronarts,项目名称:FireNET,代码行数:100,代码来源:SpectacularKill.cpp
示例6: CalcArea
float Poly::CalcArea(const Vec2& p0, const Vec2& p1) {
return p0.cw(p1) * 0.5f;
}
开发者ID:degarashi,项目名称:boomstick,代码行数:3,代码来源:polygon2D.cpp
示例7: log
bool CCutScene::slice(PhysicsWorld &world, const PhysicsRayCastInfo& info, void *data)
{
log("slice called %f, %f, %lld", info.contact.x, info.contact.y, m_lLastSlice);
if (!m_bHasFood) return true;
if (info.shape->getBody()->getTag() != _sliceTag)
{
return true;
}
long long llLastSlice = 0;
PhysicsBody* pBody = info.shape->getBody();
if (pBody == NULL) return true;
CFoodCut* pFood = (CFoodCut*)info.shape->getBody()->getNode();
if (pFood == NULL) return true;
llLastSlice = pFood->getBirthTime();
if (getCurTime() - llLastSlice <= 200) return true;
m_v2Delta.normalize();
Vec2 v2Start = info.contact - m_v2Delta * 100;
Vec2 v2End = info.contact + m_v2Delta * 500;
if (!info.shape->containsPoint(v2Start) && !info.shape->containsPoint(v2End))
{
Vec2 normal = v2End - v2Start;
normal = normal.getPerp().getNormalized();
float dist = v2Start.dot(normal);
clipPoly(dynamic_cast<PhysicsShapePolygon*>(info.shape), normal, dist);
clipPoly(dynamic_cast<PhysicsShapePolygon*>(info.shape), -normal, -dist);
Vec2 v2Direct = (v2End - v2Start).getNormalized();
Vec2 v2Tmp = Vec2::ZERO;
for (int i = 0; i < PARTICLE_COUNT; i++)
{
v2Tmp = info.contact + v2Direct * 80 * (i - 1);
if (!info.shape->containsPoint(v2Tmp))
{
continue;
}
else
{
m_pEmitter[i]->setPosition(v2Tmp);
m_pEmitter[i]->resetSystem();
}
}
std::vector<CFoodCut*>::iterator it;
for (it = m_vCutFoods.begin(); it != m_vCutFoods.end(); it++)
{
CFoodCut* pTmp = *it;
if (pTmp == info.shape->getBody()->getNode())
{
m_vCutFoods.erase(it);
break;
}
}
m_nSliceCount--;
info.shape->getBody()->removeFromWorld();
info.shape->getBody()->getNode()->removeFromParent();
checkFoodSliced();
}
return true;
}
开发者ID:GitofThunder,项目名称:gitskills,代码行数:66,代码来源:CutScene.cpp
示例8: createSkyline
std::list<Vec2> createSkyline(const Vec2& freeRectangle) {
std::list<Vec2> Skyline;
Skyline.push_back(Vec2(freeRectangle.width(), 0));
return Skyline;
}
开发者ID:danskcarvalho,项目名称:ColorNShapes,代码行数:5,代码来源:Skyline.cpp
示例9: sqrt
void Leukocyte::updateLeukocyte(float dt, const Leukocyte *other)
{
static int lockFrame = 0;
float currentScale = this->getCurrentScale();
if (currentState == LeukocyteState::LOCK) {
lockFrame++;
if (lockFrame >= PLAYER_MOVING_LOCK_FRAME) {
lockFrame = 0;
currentState = LeukocyteState::STOP;
}
}
else {
Vec2 playerPos = this->getPosition();
float distance = playerLastTouchPos.distance(playerPos);
// 距離がしきい値以下なら加速度を再計算して速度固定
if (distance <= ATTRACTED_DISTANCE * (1.0f / currentScale) && currentState == LeukocyteState::MOVE && !isCPU) {
playerAccelerate = this->getCurrentPlayerAccelerateToTouchPosition();
playerVelocity = sqrt(3.0f * MAX_VELOCITY * (1.0f / currentScale)) * playerAccelerate.getNormalized();
}
else {
if (currentState == LeukocyteState::DASH) {
if (playerVelocity.getLengthSq() > MAX_VELOCITY * (1.0f / currentScale)) {
playerAccelerate = this->getCurrentPlayerAccelerateToTouchPosition();
Vec2 addedVelocity = playerVelocity - playerAccelerate * 10 * dt * (1.0f / currentScale);
if (addedVelocity.getLengthSq() > playerVelocity.getLengthSq()) {
addedVelocity = playerVelocity + playerAccelerate * 10 * dt * (1.0f / currentScale);
}
playerVelocity = addedVelocity;
}
else {
currentState = LeukocyteState::MOVE;
}
}
else {
// 加速度から速度計算
playerAccelerate = this->getCurrentPlayerAccelerateToTouchPosition();
Vec2 addedVelocity = playerVelocity + playerAccelerate * dt * (1.0f / currentScale);
// max値を超えない場合のみプレイヤーの速度を更新する
playerVelocity = addedVelocity;
if (playerVelocity.getLengthSq() > MAX_VELOCITY * (1.0f / currentScale)) {
Vec2 normalizedPlayerVelocity = playerVelocity.getNormalized();
playerVelocity = sqrt(MAX_VELOCITY * (1.0f / currentScale)) * normalizedPlayerVelocity;
}
}
}
if (currentState != LeukocyteState::ATTACKED &&
currentState != LeukocyteState::DASH)
{
currentState = playerVelocity.length() > 0.0f ? LeukocyteState::MOVE : LeukocyteState::STOP;
}
// 壁際反射判定
Vec2 updatedPos = playerPos + playerVelocity;
auto playerSprite = this->getChildByName<Sprite*>("player");
Size playerSize = Size(currentScale * playerSprite->getContentSize().width, currentScale * playerSprite->getContentSize().height);
Size visibleSize = Director::getInstance()->getVisibleSize();
if (updatedPos.x - playerSize.width / 2 < 0 || updatedPos.x + playerSize.width / 2 > visibleSize.width) {
SimpleAudioEngine::getInstance()->playEffect(SE_HIT_WALL);
playerVelocity.x *= -1.0f;
if (currentState == LeukocyteState::DASH) {
playerVelocity = sqrt(MAX_VELOCITY * (1.0f / currentScale)) * playerVelocity.getNormalized();
currentState = LeukocyteState::MOVE;
}
}
if (updatedPos.y - playerSize.height / 2 < 0 || updatedPos.y + playerSize.height / 2 > visibleSize.height) {
SimpleAudioEngine::getInstance()->playEffect(SE_HIT_WALL);
playerVelocity.y *= -1.0f;
if (currentState == LeukocyteState::DASH) {
playerVelocity = sqrt(MAX_VELOCITY * (1.0f / currentScale)) * playerVelocity.getNormalized();
currentState = LeukocyteState::MOVE;
}
}
// 他プレイヤー衝突判定
if (other) {
if (other->isCollideByOtherLeukocyte(updatedPos, this->getCollideRadius())) {
// 半径和からプレイヤー間距離を引いた値が補正値
float sumRadius = this->getCollideRadius() + other->getCollideRadius();
float distance = updatedPos.distance(other->getPosition());
Vec2 adjustVec = (sumRadius - distance) * (other->getPosition() - updatedPos).getNormalized();
if (playerVelocity.getLength() > other->getPlayerVelocity().getLength()) {
this->setPosition(updatedPos - adjustVec);
}
}
else {
this->setPosition(playerPos + playerVelocity);
}
}
else {
//.........这里部分代码省略.........
开发者ID:MKomiya,项目名称:Leukocyte,代码行数:101,代码来源:Leukocyte.cpp
示例10: glPushMatrix
void HouseKitchen::Render(Vec3& position, Vec2& dimension, Vec2& texture_coordinate, Vec2& texture_dimension, bool no_floor)
{
// (x, y, z), (w, h), (u, v), , (w, h) , , reflect , front, left, back, right, frontw, leftw, backw, rightw, up, down.
Room::Render(position, dimension, texture_coordinate, texture_dimension, 3, no_floor, true, true, false, false, false, false, false, false, false, false);
// Draw the rest of the room here.
// Inside of the room.
glPushMatrix();
// Creating the stencil before we create the scene.
glEnable(GL_STENCIL_TEST);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glStencilFunc(GL_ALWAYS, 1, 1);
//// We aren't rendering to the frame, so always pass the stencil test.
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
// Disable depth testing.
glDisable(GL_DEPTH_TEST);
// To the floor.
glPushMatrix();
BindTexture(floor_dark_diamonds_, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR);
glTranslatef(0.0f, 0.125f, -dimension.getX());
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
DrawPlane(position, dimension, texture_coordinate, texture_dimension, Vec3(0.0f, 1.0f, 0.0f), 3);
// Back to the kitchen.
glPopMatrix();
glEnable(GL_DEPTH_TEST);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
// Turn on rendering to the frame buffer.
glStencilFunc(GL_EQUAL, 1, 1);
// Don't change the stencil values.
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
// To the reflected worktop.
glPushMatrix();
// Making the kitchen objects upside down.
glScalef(1.0f, -1.0f, 1.0f);
// Placing the worktop exactly where I want it.
glTranslatef((dimension.getX() / 2.0f) - 0.5f, 0.0f, -12.45f);
glScalef(1.25f, 1.75f, 1.0f);
glRotatef(270.0f, 0.0f, 1.0f, 0.0f);
CreateWorkTop(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension);
glRotatef(-270.0f, 0.0f, 1.0f, 0.0f);
glTranslatef(5.0f, 0.0f, 3.75f);
glScalef(1.25f, 1.0f, 1.0f);
glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
CreateWorkTop(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension);
// Back to the reflected kitchen.
glPopMatrix();
// To the reflected teapot model.
glPushMatrix();
glScalef(1.0f, -1.0f, 1.0f);
glTranslatef((dimension.getX() / 2.0f) + 1.0f, 3.125f, (dimension.getX() / 2.0f) - 18.0f);
glScalef(0.03125f, 0.03125f, 0.03125f);
teapot_.Render();
// Back to the reflected kitchen.
glPopMatrix();
// To the reflected cupboards.
glPushMatrix();
glScalef(1.0f, -1.0f, 1.0f);
glTranslatef((dimension.getX() / 2.0f), 5.0f, -12.45f);
glScalef(1.0f, 1.25f, 1.0f);
glRotatef(270.0f, 0.0f, 1.0f, 0.0f);
CreateCupboard(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension);
glTranslatef(0.0f, 0.0f, -3.0f);
CreateCupboard(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension);
glRotatef(-270.0f, 0.0f, 1.0f, 0.0f);
glTranslatef(3.0f, 0.0f, 1.0f);
glScalef(1.5f, 1.0f, 1.0f);
glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
CreateCupboard(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension);
glTranslatef(0.0f, 0.0f, -3.0f);
CreateCupboard(position, Vec2(1.0f, 1.0f), texture_coordinate, texture_dimension);
// Back to the kitchen.
glPopMatrix();
// No longer need the stencil test.
glDisable(GL_STENCIL_TEST);
// To combine the flow and rendered reflection of the object.
//.........这里部分代码省略.........
开发者ID:jmottershead94,项目名称:Farm3DScene,代码行数:101,代码来源:house_kitchen.cpp
示例11: return
inline friend bool operator<=(Vec2& V1, Vec2& V2) { return (V1.getSquaredLength() <= V2.getSquaredLength()); }
开发者ID:Senryoku,项目名称:Physics,代码行数:1,代码来源:Vec2.hpp
示例12: GetRotationDirection
Direction GetRotationDirection(Vec2 heading, Vec2 target) {
Vec2 perp = heading.Perpendicular();
target.Normalize();
return perp.Dot(target) >= 0.0 ? Direction::Right : Direction::Left;
}
开发者ID:daemon,项目名称:monkeybot,代码行数:5,代码来源:Util.cpp
示例13: while
void ExecFrame::execute_ops(int num)
{
int opcode, param;
floatval fa,fb;
int ia, ib, ifor, iparam, ijmp;
//char opfor,pfor;
Vec2 *v1,*v2;
Vec2 v;
VMInterface* obj;
ExecFrame* frame;
CodeObj* cobj;
while(num-- != 0)
{
opcode = (int)code->code[iptr++];
param = (int)code->code[iptr++];
//std::cout << opcode << ':' << param << std::endl;
switch(opcode) {
case OPC_EXIT:
iptr-=2;
return;
case OPC_VMCALL:
cobj = (CodeObj*)popp();
ia = popi();
frame = new ExecFrame(cobj);
frame->restart();
if (param > 0) move(param, frame);
frame->execute();
if (ia > 0) frame->move(ia, this);
delete frame;
break;
case OPC_CONSTF:
pushf(code->conarray_f[param]);
break;
case OPC_CONSTI:
pushi(code->conarray_i[param]);
break;
case OPC_CONSTV:
pushv(code->conarray_v[param]);
break;
case OPC_CONSTP:
pushp(code->conarray_p[param]);
break;
case OPC_PUSHVARF:
pushf(vararray_f[param]);
break;
case OPC_PUSHVARI:
pushi(vararray_i[param]);
break;
case OPC_PUSHVARV:
pushv(vararray_v[param]);
break;
case OPC_PUSHVARP:
pushp(vararray_p[param]);
break;
case OPC_POP:
top -= param;
break;
case OPC_SETVARF:
vararray_f[param] = popf();
break;
case OPC_SETVARI:
vararray_i[param] = popi();
break;
case OPC_SETVARV:
fb = popf();
fa = popf();
vararray_v[param].set(fa,fb);
break;
case OPC_SETVARP:
vararray_p[param] = popp();
break;
case OPC_GETPROP:
obj = (VMInterface*)popp();
obj->VM_GetProp(this, param);
break;
case OPC_SETPROP:
obj = (VMInterface*)popp();
obj->VM_SetProp(this, param);
break;
case OPC_METCALL:
obj = (VMInterface*)popp();
obj->VM_MetCall(this, param);
break;
case OPC_GETPROPV:
v1 = (Vec2*)popp();
v1->VM_GetProp(this, param);
break;
case OPC_SETPROPV:
v1 = (Vec2*)popp();
v1->VM_SetProp(this, param);
break;
case OPC_METCALLV:
v1 = (Vec2*)popp();
v1->VM_MetCall(this, param);
break;
case OPC_JUMP:
iptr += param*2;
//.........这里部分代码省略.........
开发者ID:bcorfman,项目名称:opioid2d,代码行数:101,代码来源:opivm_switch.cpp
示例14: fabs
void RationalBilinearInverter::solve(
Vec2 const & p,
Vec4 const & p00, Vec4 const & p10,
Vec4 const & p01, Vec4 const & p11
)
{
double m[4][6] = {
{ p00.x(), p10.x(), p01.x(), -p.x(), 0, -p11.x() },
{ p00.y(), p10.y(), p01.y(), -p.y(), 0, -p11.y() },
{ p00.z(), p10.z(), p01.z(), -1, 0, -p11.z() },
{ p00.w(), p10.w(), p01.w(), 0, 1, -p11.w() }
};
for (int j = 0; j < 4; ++j) {
double a = 0.0;
std::for_each(m[j], m[j + 1], [&] (double & f) { a = (std::max)(a, fabs(f)); });
std::for_each(m[j], m[j + 1], [&] (double & f) { f /= a; });
}
for (int j = 0; j < 4; ++j) {
int pivot_row = j; double pivot_value = fabsf(m[j][j]);
for (int k = j + 1; k < 4; ++k) {
auto t = fabsf(m[k][j]);
if (t > pivot_value) {
pivot_value = t;
pivot_row = k;
}
}
if (pivot_row != j) { swap(m[j], m[pivot_row]); }
double * row = m[j] + j, * end = m[j + 1];
normalize_front(row, end);
for (int k = j + 1; k < 4; ++k) {
scale_and_subtract_row(m[k] + j, m[k + 1], m[k][j], row);
}
}
for (int i = 3; i > 0; --i) {
for (int j = i - 1; j >= 0; --j) {
scale_and_subtract_row(m[j] + i, m[j + 1], m[j][i], m[i] + i);
}
}
double quad_a = m[0][5] - m[1][5] * m[2][5],
quad_b = m[0][4] - m[1][4] * m[2][5] - m[1][5] * m[2][4],
quad_c = - m[1][4] * m[2][4];
if (-1e-3 < quad_a && quad_a < 1e-3) { quad_a = 0.; }
if (-1e-3 < quad_b && quad_b < 1e-3) { quad_b = 0.; }
if (-1e-3 < quad_c && quad_c < 1e-3) { quad_c = 0.; }
QuadraticSolver<double> q(quad_a, quad_b, quad_c);
for (auto it = q.begin(); it != q.end(); ++it) {
double D = *it,
alpha = m[3][4] + m[3][5] * D;
if (alpha < 1.0 - 1e-3) { continue; }
double A = m[0][4] + m[0][5] * D,
B = m[1][4] + m[1][5] * D,
C = m[2][4] + m[2][5] * D,
d = A + B + C + D;
if (!d || d != d) { continue; }
double r = 1.0 / d,
u = (B + D) * r,
v = (C + D) * r;
if (u < -1e-3 || u >= 1.0-1e-3) { continue; }
if (v < -1e-3 || v >= 1.0-1e-3) { continue; }
solutions_[size_++] = std::make_pair(alpha, Vec2(u, v));
}
if (size_ == 2 && solutions_[0].first > solutions_[1].first)
{ std::swap(solutions_[0], solutions_[1]); }
}
开发者ID:bracket,项目名称:handsome,代码行数:83,代码来源:RationalBilinearInverter.cpp
示例15: if
void ParticleSystemQuad::updateParticleQuads()
{
if (_particleCount <= 0) {
return;
}
Vec2 currentPosition;
if (_positionType == PositionType::FREE)
{
currentPosition = this->convertToWorldSpace(Vec2::ZERO);
}
else if (_positionType == PositionType::RELATIVE)
{
currentPosition = _position;
}
V3F_C4B_T2F_Quad *startQuad;
Vec2 pos = Vec2::ZERO;
if (_batchNode)
{
V3F_C4B_T2F_Quad *batchQuads = _batchNode->getTextureAtlas()->getQuads();
startQuad = &(batchQuads[_atlasIndex]);
pos = _position;
}
else
{
startQuad = &(_quads[0]);
}
if( _positionType == PositionType::FREE )
{
Vec3 p1(currentPosition.x, currentPosition.y, 0);
Mat4 worldToNodeTM = getWorldToNodeTransform();
worldToNodeTM.transformPoint(&p1);
Vec3 p2;
Vec2 newPos;
float* startX = _particleData.startPosX;
float* startY = _particleData.startPosY;
float* x = _particleData.posx;
float* y = _particleData.posy;
float* s = _particleData.size;
float* r = _particleData.rotation;
V3F_C4B_T2F_Quad* quadStart = startQuad;
for (int i = 0 ; i < _particleCount; ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r)
{
p2.set(*startX, *startY, 0);
worldToNodeTM.transformPoint(&p2);
newPos.set(*x,*y);
p2 = p1 - p2;
newPos.x -= p2.x - pos.x;
newPos.y -= p2.y - pos.y;
updatePosWithParticle(quadStart, newPos, *s, *r);
}
}
else if( _positionType == PositionType::RELATIVE )
{
Vec2 newPos;
float* startX = _particleData.startPosX;
float* startY = _particleData.startPosY;
float* x = _particleData.posx;
float* y = _particleData.posy;
float* s = _particleData.size;
float* r = _particleData.rotation;
V3F_C4B_T2F_Quad* quadStart = startQuad;
for (int i = 0 ; i < _particleCount; ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r)
{
newPos.set(*x, *y);
newPos.x = *x - (currentPosition.x - *startX);
newPos.y = *y - (currentPosition.y - *startY);
newPos += pos;
updatePosWithParticle(quadStart, newPos, *s, *r);
}
}
else
{
Vec2 newPos;
float* startX = _particleData.startPosX;
float* startY = _particleData.startPosY;
float* x = _particleData.posx;
float* y = _particleData.posy;
float* s = _particleData.size;
float* r = _particleData.rotation;
V3F_C4B_T2F_Quad* quadStart = startQuad;
for (int i = 0 ; i < _particleCount; ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r)
{
newPos.set(*x + pos.x, *y + pos.y);
updatePosWithParticle(quadStart, newPos, *s, *r);
}
}
//set color
if(_opacityModifyRGB)
{
V3F_C4B_T2F_Quad* quad = startQuad;
float* r = _particleData.colorR;
float* g = _particleData.colorG;
float* b = _particleData.colorB;
float* a = _particleData.colorA;
for (int i = 0; i < _particleCount; ++i,++quad,++r,++g,++b,++a)
//.........这里部分代码省略.........
开发者ID:253056965,项目名称:cocos2d-x-lite,代码行数:101,代码来源:CCParticleSystemQuad.cpp
示例16: Vec2
void AutoWeapon::SeachTarget( float dt )
{
//先按距离排序
GameData::getInstance()->SortByDis();
std::list<PhysicsUnit*> Planelist = GameData::getInstance()->getEnemyPlaneVec();
std::list<PhysicsUnit*>::iterator it = Planelist.begin();
Point targetPos = Vec2(0,0);
if (Planelist.empty())
{
this->setRotation(0);
setBullstType(BulletType::Self_Default);
return;
}
bool isFound = false;
if (m_isLeft)
{
for (it; it != Planelist.end(); it++)
{
targetPos = (*it)->getPosition();
if (targetPos.x <= m_winSize.width*0.5 && targetPos.y > m_winSize.height*0.15 + 100)
{
isFound = true;
break;
}
}
}
else
{
for (it; it != Planelist.end(); it++)
{
targetPos = (*it)->getPosition();
if (targetPos.x >= m_winSize.width*0.5 && targetPos.y > m_winSize.height*0.15 + 100)
{
isFound = true;
break;
}
}
}
//根据目标位置和自己的位置,计算需要旋转的角度
Point myPos = this->convertToWorldSpaceAR(Point::ZERO);
Vec2 newVec = targetPos - myPos;
float r = newVec.getAngle() * Pi2Angle;
r = 90 - r;
if (r > 60)
{
r = 60;
}
else if(r < -60)
{
r = -60;
}
if (!isFound)
{
this->setRotation(0);
}
else
{
this->setRotation(r);
}
setBullstType(BulletType::Self_Default);
}
开发者ID:Chonger8888,项目名称:project,代码行数:66,代码来源:weapon.cpp
示例17:
void VertexArray::SetTo2DBox(float x, float y, float w, float h, float marginwidth, float marginheight, float clipx)
{
const unsigned int quads = 9;
float vcorners[12*quads];
float uvs[8*quads];
int bfaces[6*quads];
//y1 = 1.0 - y1;
//y2 = 1.0 - y2;
Vec2 corner1;
Vec2 corner2;
Vec2 dim;
dim.Set(w,h);
Vec2 center;
center.Set(x,y);
corner1 = center - dim*0.5;
corner2 = center + dim*0.5;
Vec2 margin;
margin.Set(marginwidth, marginheight);
float lxmax = std::max((corner1-margin)[0],std::min(clipx,corner1[0]));
float cxmax = std::max(corner1[0],std::min(clipx,corner2[0]));
float rxmax = std::max(corner2[0],std::min(clipx,(corner2+margin)[0]));
float lumax = (lxmax-(corner1-margin)[0])/(corner1[0]-(corner1-margin)[0])*0.5;
float rumax = (rxmax-corner2[0])/((corner2+margin)[0]-corner2[0])*0.5+0.5;
//upper left
SetVertexData2DQuad((corner1-margin)[0],(corner1-margin)[1],lxmax,corner1[1],
0,0,lumax,0.5, vcorners,uvs,bfaces);
//upper center
SetVertexData2DQuad(corner1[0],(corner1-margin)[1],cxmax,corner1[1],
0.5,0,0.5,0.5,
&(vcorners[12*1]),&(uvs[8*1]),&(bfaces[6*1]),4*1);
//upper right
SetVertexData2DQuad(corner2[0],(corner1-margin)[1],rxmax,corner1[1],
0.5,0,rumax,0.5,
&(vcorners[12*2]),&(uvs[8*2]),&(bfaces[6*2]),4*2);
//center left
SetVertexData2DQuad((corner1-margin)[0],corner1[1],lxmax,corner2[1],
0,0.5,lumax,0.5,
&(vcorners[12*3]),&(uvs[8*3]),&(bfaces[6*3]),4*3);
//center center
SetVertexData2DQuad(corner1[0],corner1[1],cxmax,corner2[1],
0.5,0.5,0.5,0.5,
&(vcorners[12*4]),&(uvs[8*4]),&(bfaces[6*4]),4*4);
//center right
SetVertexData2DQuad(corner2[0],corner1[1],rxmax,corner2[1],
0.5,0.5,rumax,0.5,
&(vcorners[12*5]),&(uvs[8*5]),&(bfaces[6*5]),4*5);
//lower left
SetVertexData2DQuad((corner1-margin)[0],corner2[1],lxmax,(corner2+margin)[1],
0,0.5,lumax,1,
&(vcorners[12*6]),&(uvs[8*6]),&(bfaces[6*6]),4*6);
//lower center
SetVertexData2DQuad(corner1[0],corner2[1],cxmax,(corner2+margin)[1],
0.5,0.5,0.5,1,
&(vcorners[12*7]),&(uvs[8*7]),&(bfaces[6*7]),4*7);
//lower right
SetVertexData2DQuad(corner2[0],corner2[1],rxmax,(corner2+margin)[1],
0.5,0.5,rumax,1,
&(vcorners[12*8]),&(uvs[8*8]),&(bfaces[6*8]),4*8);
SetFaces(bfaces, 6*quads);
SetVertices(vcorners, 12*quads);
SetTexCoordSets(1);
SetTexCoords(0, uvs, 8*quads);
}
开发者ID:HaohaoLau,项目名称:vdrift,代码行数:76,代码来源:vertexarray.cpp
示例18: Widget
Widget(picojson::object& param, const TexMng::tex_ptr texture, const Vec2<int> *size, const float *y_bottom) :
scale_(1,1),
blend_mode_(),
texture_(texture),
layout_(LAYOUT_CENTER),
id_(),
window_size_(size),
y_bottom_(y_bottom)
{
// FIXME: 以下、初期化リストで済ませたい
{
picojson::array& array = param["pos"].get<picojson::array>();
pos_.set(array[0].get<double>(), array[1].get<double>());
pos_orig_ = pos_;
}
{
picojson::array& array = param["size"].get<picojson::array>();
size_.set(array[0].get<double>(), array[1].get<double>());
size_orig_ = size_;
}
{
picojson::array& array = param["uv"].get<picojson::array>();
uv_.set(array[0].get<double>(), array[1].get<double>());
uv_orig_ = uv_;
}
{
picojson::array& array = param["col"].get<picojson::array>();
col_.set(array[0].get<double>(), array[1].get<double>(), array[2].get<double>(), array[3].get<double>());
col_orig_ = col_;
}
{
auto_center_ = !param["center"].is<picojson::array>();
if (!auto_center_)
{
picojson::array& array = param["center"].get<picojson::array>();
center_.set(array[0].get<double>(), array[1].get<double>());
center_orig_ = center_;
}
}
if (param["scale"].is<picojson::array>())
{
picojson::array& array = param["scale"].get<picojson::array>();
scale_.set(array[0].get<double>(), array[1].get<double>());
}
if (param["ofs_size"].is<picojson::array>())
{
// UIで使う時のサイズに対するオフセット
picojson::array& array = param["ofs_size"].get<picojson::array>();
ofs_size_.set(array[0].get<double>(), array[1].get<double>());
}
if (param["x_layout"].is<double>())
{
layout_ |= (param["x_layout"].get<double>() > 0.0) ? LAYOUT_RIGHT : LAYOUT_LEFT;
}
if (param["y_layout"].is<double>())
{
layout_ |= (param["y_layout"].get<double>() > 0.0) ? LAYOUT_BOTTOM : LAYOUT_TOP;
}
if (param["id"].is<double>())
{
id_ = param["id"].get<double>();
}
}
开发者ID:limebreaker,项目名称:KONAHEN,代码行数:66,代码来源:nn_widget.hpp
示例19: isWithinVision
bool Level::isWithinVision(Vec2 from, Vec2 to, VisionId v) const {
return Vision::get(v)->isNightVision() || from.distD(to) <= darkViewRadius || getLight(to) > 0.3;
}
开发者ID:Eldhelion,项目名称:keeperrl,代码行数:3,代码来源:level.cpp
示例20: AddForce
void PhysicsObject::AddForce(Vec2 Force){
Vec2 Arm;
Arm.SetValue(0,0);
AddForce(Force,Arm);
}
开发者ID:rolfrm,项目名称:finite_engine,代码行数:5,代码来源:PhysicsObject.cpp
注:本文中的Vec2类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论