本文整理汇总了C++中AVector::Z方法的典型用法代码示例。如果您正苦于以下问题:C++ AVector::Z方法的具体用法?C++ AVector::Z怎么用?C++ AVector::Z使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AVector
的用法示例。
在下文中一共展示了AVector::Z方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetVelocity
//----------------------------------------------------------------------------
void FMODSound::SetVelocity (const AVector &velocity)
{
FMOD_VECTOR vec;
vec.x = velocity.X();
vec.y = velocity.Y();
vec.z = velocity.Z();
if (mChannel)
mChannel->set3DAttributes(0, &vec);
}
示例2: _MoveCamera
//----------------------------------------------------------------------------
void EditRenderView_Scene::_MoveCamera(float horz, float vert)
{
Scene *scene = PX2_PROJ.GetScene();
if (!scene) return;
CameraActor *camActor = scene->GetUseCameraActor();
if (camActor)
{
APoint position = camActor->LocalTransform.GetTranslate();
AVector rVector;
AVector dVector;
AVector uVector;
camActor->GetRDUVector(rVector, dVector, uVector);
if (mViewType == VT_PERSPECTIVE)
{
dVector.Z() = 0.0f;
dVector.Normalize();
rVector.Z() = 0.0f;
rVector.Normalize();
position += dVector * vert;
position -= rVector * horz;
}
else if (mViewType == VT_TOP)
{
position.Y() += vert * 1.0f;
position.X() -= horz * 1.0f;
}
else if (mViewType == VT_LEFT)
{
position.Z() += vert * 1.0f;
position.Y() += horz * 1.0f;
}
else if (mViewType == VT_FRONT)
{
position.Z() += vert * 1.0f;
position.X() -= horz * 1.0f;
}
camActor->LocalTransform.SetTranslate(position);
}
}
示例3: _MoveCamera
//----------------------------------------------------------------------------
void EU_CanvasStage::_MoveCamera(float horz, float vert)
{
if (!Project::GetSingletonPtr()) return;
Scene *scene = PX2_PROJ.GetScene();
if (!scene) return;
if (mStageCameraNode)
{
APoint position = mStageCameraNode->LocalTransform.GetTranslate();
AVector rVector;
AVector dVector;
AVector uVector;
mStageCameraNode->LocalTransform.GetRDUVector(rVector, dVector, uVector);
if (mViewType == VT_PERSPECTIVE)
{
dVector.Z() = 0.0f;
dVector.Normalize();
rVector.Z() = 0.0f;
rVector.Normalize();
position += dVector * vert;
position -= rVector * horz;
}
else if (mViewType == VT_TOP)
{
position.Y() += vert * 1.0f;
position.X() -= horz * 1.0f;
}
else if (mViewType == VT_LEFT)
{
position.Z() += vert * 1.0f;
position.Y() += horz * 1.0f;
}
else if (mViewType == VT_FRONT)
{
position.Z() += vert * 1.0f;
position.X() -= horz * 1.0f;
}
mStageCameraNode->LocalTransform.SetTranslate(position);
}
}
示例4: UpdateWorldData
//----------------------------------------------------------------------------
void Soundable::UpdateWorldData(double applicationTime, double elapsedTime)
{
Movable::UpdateWorldData(applicationTime, elapsedTime);
if (mSound)
mSound->SetPosition(WorldTransform.GetTranslate());
const APoint &listenPos = SoundSystem::GetSingleton().GetListenerPos();
if (!Is3D())
{
AVector dir = WorldTransform.GetTranslate() - listenPos;
if (!mDistanceUseX)
dir.X() = 0.0f;
if (!mDistanceUseY)
dir.Y() = 0.0f;
if (!mDistanceUseZ)
dir.Z() = 0.0f;
float dist = dir.Length();
SoundableController *sCtrl = DynamicCast<SoundableController>(GetEffectableController());
const SoundableObject *sObj = sCtrl->GetSoundableObject();
if (sObj)
{
float curVolume = sObj->Volume;
float volume = curVolume;
if (dist < mMinDistance)
{
volume = curVolume;
}
else if (mMinDistance<=dist && dist<=mMaxDistance)
{
float range = mMaxDistance - mMinDistance;
if (range <= 0.0f)
range = 0.0f;
volume = curVolume * (1.0f - (dist - mMinDistance)/range);
}
else if (dist > mMaxDistance)
{
volume = 0.0f;
}
if (mSound)
{
mSound->SetVolume(volume);
}
}
}
}
示例5: OnMoving
//----------------------------------------------------------------------------
bool PushTransformController::Update(double applicationTime,
double elapsedTime1)
{
if (!Controller::Update(applicationTime, elapsedTime1))
return false;
if (mVelocity == AVector::ZERO)
return true;
float elapsedTime = (float)elapsedTime1;
AVector velocityDis = mVelocity*elapsedTime;
AVector movedDis;
if (IsXY())
{
movedDis.X() = velocityDis.X();
movedDis.Y() = velocityDis.Y();
}
else
{
movedDis.X() = velocityDis.X();
movedDis.Z() = velocityDis.Z();
}
OnMoving(movedDis);
// 减小速度
AVector vecTemp = mVelocity;
float vecLength = vecTemp.Normalize();
vecLength -= mFriction * elapsedTime;
if (vecLength <= 0.0f)
{
SetVelocity(AVector::ZERO);
}
else
{
SetVelocity(vecTemp * vecLength);
}
return true;
}
示例6: MoveCamera
//----------------------------------------------------------------------------
void GamePlayApp::MoveCamera (Camera *cam, const float &horz,
const float &vert)
{
if (!cam)
return;
Vector3f position = cam->GetPosition();
AVector dVector = cam->GetDVector();
AVector uVector = cam->GetUVector();
AVector rVector = cam->GetRVector();
dVector.Z() = 0.0f;
dVector.Normalize();
rVector.Z() = 0.0f;
rVector.Normalize();
position += dVector * vert;
position += rVector * horz;
cam->SetPosition(position);
}
示例7: GetSmallTransDir
//----------------------------------------------------------------------------
AVector InputPushTransformController::GetSmallTransDir()
{
Movable *movable = DynamicCast<Movable>(mObject);
if (!movable)
AVector::ZERO;
APoint curPos = movable->LocalTransform.GetTranslate();
AVector moveDir = AVector::ZERO;
if (curPos.X() < mMinPosSmall.X())
{
moveDir.X() = mMinPosSmall.X() - curPos.X();
}
if (curPos.Y() < mMinPosSmall.Y())
{
moveDir.Y() = mMinPosSmall.Y() - curPos.Y();
}
if (curPos.Z() < mMinPosSmall.Z())
{
moveDir.Z() = mMinPosSmall.Z() - curPos.Z();
}
if (curPos.X()>mMaxPosSmall.X())
{
moveDir.X() = mMaxPosSmall.X() - curPos.X();
}
if (curPos.Y() > mMaxPosSmall.Y())
{
moveDir.Y() = mMaxPosSmall.Y() - curPos.Y();
}
if (curPos.Z() > mMaxPosSmall.Z())
{
moveDir.Z() = mMaxPosSmall.Z() - curPos.Z();
}
return moveDir;
}
示例8: OnMotion
//----------------------------------------------------------------------------
void EditRenderView_Scene::OnMotion(const APoint &pos)
{
if (!IsEnable()) return;
APoint curPos = pos;
APoint lastPos = mLastMousePoint;
AVector delta = curPos - lastPos;
mLastMousePoint = curPos;
if (delta == AVector::ZERO) return;
Edit::EditType et = PX2_EDIT.GetEditType();
if (et == Edit::ET_TERRAIN)
{
_UpdateBrushPos(pos);
}
if (mIsMiddleDown || mIsRightDown)
{
float speedVal = 3.0f;
if (VT_PERSPECTIVE == mViewType)
{
if (PX2_EDIT.IsAltDown)
{
_RolateCamera(delta.X()*mPixelToWorld.first*speedVal*0.25f, -delta.Z()*mPixelToWorld.second*speedVal*0.25f);
}
else if (PX2_EDIT.IsCtrlDown)
{
Movable *mov = DynamicCast<Movable>(PX2_SELECTION.GetFirstObject());
if (mov)
{
_RoundCamera(delta.X()*speedVal*0.02f, -delta.Z()*speedVal*0.02f);
}
else
{
_PanCamera(-delta.X()*mPixelToWorld.first*speedVal, delta.Z()*mPixelToWorld.second*speedVal);
}
}
else if (PX2_EDIT.IsShiftDown)
{
_ZoomCamera(-delta.Z()*mPixelToWorld.second*PX2_EDIT.GetCameraMoveSpeed());
}
else
{
_PanCamera(-delta.X()*mPixelToWorld.first*speedVal, delta.Z()*mPixelToWorld.second*speedVal);
}
}
else
{
_PanCamera(delta.X()*mPixelToWorld.first, delta.Z()*mPixelToWorld.second);
}
}
else if (mIsLeftDown)
{
PX2_EDIT.GetTerrainEdit()->Apply(false);
}
Edit::EditMode em = PX2_EDIT.GetEditMode();
if ((Edit::EM_TRANSLATE == em || Edit::EM_ROLATE == em || Edit::EM_SCALE == em))
{
if (mSceneNodeCtrl)
mSceneNodeCtrl->OnMotion(mIsLeftDown, mRenderStepCtrl, curPos, lastPos);
if (mIsLeftDown)
{
mIsSelectMovableTransChanged = true;
}
}
}
示例9: UpdateLayout
//----------------------------------------------------------------------------
void SizeNode::UpdateLayout(Movable *parent)
{
Movable *par = parent;
if (!par) return;
SizeNode *parNode = DynamicCast<SizeNode>(par);
// parent pvoit决定了从那一点作为原点,计算当前Frame原点位置
// 例如
// (0.0f, 0.0f)是左下角
// (0.5f, 0.5f)是中心点
Sizef parentSize;
AVector parentLeftBottomOffset;
if (parNode)
{
parentSize = parNode->GetSize();
parentLeftBottomOffset = parNode->LeftBottomCornerOffset;
}
APoint localPos = LocalTransform.GetTranslate();
Sizef localSize = GetSize();
APoint newPos;
Sizef newSize = localSize;
if (parNode)
{
float width = 0.0f;
float height = 0.0f;
bool isHEqual = (mAnchorHor[0] == mAnchorHor[1]);
bool isVEqual = (mAnchorVer[0] == mAnchorVer[1]);
if (isHEqual)
{
width = localSize.Width;
newPos.X() = parentLeftBottomOffset.X() +
parentSize.Width * mAnchorHor[0] + mAnchorParamHor[0];
}
else
{
// 如果是范围,直接取中心点,作为原点
width = parentSize.Width * (mAnchorHor[1] - mAnchorHor[0]) - mAnchorParamHor[0] + mAnchorParamHor[1];
newPos.X() = parentLeftBottomOffset.X() + parentSize.Width*mAnchorHor[0] + mAnchorParamHor[0] + width / 2.0f;
}
if (isVEqual)
{
height = localSize.Height;
newPos.Z() = parentLeftBottomOffset.Z() +
parentSize.Height * mAnchorVer[0] + mAnchorParamVer[0];
}
else
{
// 如果是范围,直接取中心点,作为原点
height = parentSize.Height * (mAnchorVer[1] - mAnchorVer[0]) - mAnchorParamVer[0] + mAnchorParamVer[1];
newPos.Z() = parentLeftBottomOffset.Z() + parentSize.Height*mAnchorVer[0] + mAnchorParamVer[0] + height / 2.0f;
}
newSize = Sizef(width, height);
}
newPos.Y() = localPos.Y();
LocalTransform.SetTranslate(newPos);
if (newSize != localSize)
{
SetSize(newSize);
}
}
示例10: trackRotate
//----------------------------------------------------------------------------
void WindowApplication3::RotateTrackBall (float x0, float y0, float x1,
float y1)
{
if ((x0 == x1 && y0 == y1) || !mCamera)
{
// Nothing to rotate.
return;
}
// Get the first vector on the sphere.
float length = Mathf::Sqrt(x0*x0 + y0*y0), invLength, z0, z1;
if (length > 1.0f)
{
// Outside the unit disk, project onto it.
invLength = 1.0f/length;
x0 *= invLength;
y0 *= invLength;
z0 = 0.0f;
}
else
{
// Compute point (x0,y0,z0) on negative unit hemisphere.
z0 = 1.0f - x0*x0 - y0*y0;
z0 = (z0 <= 0.0f ? 0.0f : Mathf::Sqrt(z0));
}
z0 *= -1.0f;
// Use camera world coordinates, order is (D,U,R), so point is (z,y,x).
AVector vec0(z0, y0, x0);
// Get the second vector on the sphere.
length = Mathf::Sqrt(x1*x1 + y1*y1);
if (length > 1.0f)
{
// Outside unit disk, project onto it.
invLength = 1.0f/length;
x1 *= invLength;
y1 *= invLength;
z1 = 0.0f;
}
else
{
// Compute point (x1,y1,z1) on negative unit hemisphere.
z1 = 1.0f - x1*x1 - y1*y1;
z1 = (z1 <= 0.0f ? 0.0f : Mathf::Sqrt(z1));
}
z1 *= -1.0f;
// Use camera world coordinates, order is (D,U,R), so point is (z,y,x).
AVector vec1(z1, y1, x1);
// Create axis and angle for the rotation.
AVector axis = vec0.Cross(vec1);
float dot = vec0.Dot(vec1);
float angle;
if (axis.Normalize() > Mathf::ZERO_TOLERANCE)
{
angle = Mathf::ACos(dot);
}
else // Vectors are parallel.
{
if (dot < 0.0f)
{
// Rotated pi radians.
invLength = Mathf::InvSqrt(x0*x0 + y0*y0);
axis.X() = y0*invLength;
axis.Y() = -x0*invLength;
axis.Z() = 0.0f;
angle = Mathf::PI;
}
else
{
// Rotation by zero radians.
axis = AVector::UNIT_X;
angle = 0.0f;
}
}
// Compute the world rotation matrix implied by trackball motion. The
// axis vector was computed in camera coordinates. It must be converted
// to world coordinates. Once again, I use the camera ordering (D,U,R).
AVector worldAxis =
axis.X()*mCamera->GetDVector() +
axis.Y()*mCamera->GetUVector() +
axis.Z()*mCamera->GetRVector();
HMatrix trackRotate(worldAxis, angle);
// Compute the new local rotation. If the object is the root of the
// scene, the new rotation is simply the *incremental rotation* of the
// trackball applied *after* the object has been rotated by its old
// local rotation. If the object is not the root of the scene, you have
// to convert the incremental rotation by a change of basis in the
// parent's coordinate space.
const Spatial* parent = mMotionObject->GetParent();
HMatrix localRot;
if (parent)
{
const HMatrix& parWorRotate = parent->WorldTransform.GetRotate();
//.........这里部分代码省略.........
示例11: OnMotion
//----------------------------------------------------------------------------
void EditRenderView_TimeLine::OnMotion(const APoint &pos)
{
AVector diff = pos - mLastMousePoint;
if (AVector::ZERO == diff) return;
float movedX = -diff.X() / mPixelOverCamIn;
float movedZ = -diff.Z() / mPixelOverCamOut;
Rectf rect(0, 0, mLeftWidth, mSize.Height);
bool leftContain = rect.IsInsize(Float2(pos.X(), pos.Z()));
bool isCtrlDown = PX2_EDIT.IsCtrlDown;
CurveCtrl *selectedCtrl = PX2_EDIT.GetTimeLineEdit()->GetSelectedCurveCtrl();
if (isCtrlDown && !leftContain && selectedCtrl && mIsLeftDown)
{
Camera *camera = mRenderStep->GetCamera();
const APoint &outVal = selectedCtrl->GetOutVal();
Vector2f posInViewPort = mUIViewGrid->PointWorldToViewPort(outVal);
float xDiss = pos.X() - posInViewPort.X();
float zDiss = pos.Z() - posInViewPort.Y();
float xDissReal = xDiss / mPixelOverCamIn;
float zDissReal = zDiss / mPixelOverCamOut;
AVector arrive = AVector(-xDissReal, 0.0f, -zDissReal);
arrive.Normalize();
AVector leave = AVector(xDissReal, 0.0f, zDissReal);
leave.Normalize();
if (CurveCtrl::SM_ARRIVE == selectedCtrl->GetSelectMode())
{
if (xDiss < 0.0f)
{
selectedCtrl->SetArriveTangent(arrive);
InterpCurveMode mode = selectedCtrl->GetInterpCurveMode();
if (ICM_CURVE_AUTO == mode || ICM_CURVE_AUTOCLAMPED == mode)
{
selectedCtrl->SetInterpCurveMode(ICM_CURVE_USER);
//UnToggleAllInterps();
//ToggleInterp(ICM_CURVE_USER);
}
}
}
else if (CurveCtrl::SM_LEAVE == selectedCtrl->GetSelectMode())
{
if (xDiss > 0.0f)
{
selectedCtrl->SetLeaveTangent(leave);
InterpCurveMode mode = selectedCtrl->GetInterpCurveMode();
if (ICM_CURVE_AUTO == mode || ICM_CURVE_AUTOCLAMPED == mode)
{
selectedCtrl->SetInterpCurveMode(ICM_CURVE_USER);
//UnToggleAllInterps();
//ToggleInterp(ICM_CURVE_USER);
}
}
}
else if (CurveCtrl::SM_CENTER == selectedCtrl->GetSelectMode())
{
APoint camPos = camera->GetPosition();
Vector2f camScreenPos = mUIViewGrid->PointWorldToViewPort(camPos);
float xDissCam = pos.X() - camScreenPos.X();
float zDissCam = pos.Z() - camScreenPos.Y();
float xDissCamReal = xDissCam / mPixelOverCamIn;
float zDissCamReal = zDissCam / mPixelOverCamOut;
APoint pointPos = camPos + AVector(xDissCamReal, 0.0f, zDissCamReal);
pointPos.Y() = 0.0f;
selectedCtrl->SetInVal(pointPos.X()); // ctrl may changed
selectedCtrl = PX2_EDIT.GetTimeLineEdit()->GetSelectedCurveCtrl(); // ctrl may changed, can it again
if (selectedCtrl) selectedCtrl->SetOutVal(pointPos);
}
}
bool doMovCal = false;
if (mIsMiddleDown && !leftContain)
doMovCal = true;
if (mIsRightDown && !leftContain)
doMovCal = true;
if (doMovCal)
{
if (MM_PAN == mMoveMode)
{
APoint pos = mUIViewGrid->GetCameraNode()->LocalTransform.GetTranslate();
pos += AVector(movedX, 0.0f, movedZ);
mUIViewGrid->GetCameraNode()->LocalTransform.SetTranslate(pos);
mUIViewGrid->GetCameraNode()->Update(GetTimeInSeconds(), 0.0f);
_RefreshGrid(false);
}
else if (MM_ZOOM == mMoveMode)
{
//.........这里部分代码省略.........
示例12: GetWorldRect
//----------------------------------------------------------------------------
void EU_CanvasStage::OnMotion(const APoint &worldPos)
{
if (!IsEnable())
return;
const Rectf &rectWorld = GetWorldRect();
if (!rectWorld.IsInsize(worldPos.X(), worldPos.Z()))
return;
UICanvas::OnMotion(worldPos);
if (!Project::GetSingletonPtr()) return;
if (!PX2_PROJ.GetScene()) return;
if (mMoveDelta == AVector::ZERO) return;
Edit::EditType et = PX2_EDIT.GetEditType();
if (et == Edit::ET_TERRAIN)
{
APoint viewPortPos = WorldPosToViewPortPos(worldPos);
_UpdateBrushPos(viewPortPos);
}
APoint curViewPortPos = WorldPosToViewPortPos(mCurPickPos);
APoint lastViewPortPos = WorldPosToViewPortPos(mLastPickPos);
AVector delta = mMoveDelta;
float speedVal = 0.01f;
SceneNodeCtrl::DragType dt = mSceneNodeCtrl->GetDragType();
if (dt == SceneNodeCtrl::DT_NONE)
{
if (AVector::ZERO != delta && (mIsRightPressed || mIsMiddlePressed))
{
SetCameraDraging(true);
}
}
else
{
SetCameraDraging(false);
}
if (IsCameraDraging())
{
if (VT_PERSPECTIVE == mViewType)
{
if (PX2_EDIT.IsAltDown)
{
if (mIsLeftPressed)
{
Movable *mov = DynamicCast<Movable>(PX2_SELECTM_E->GetFirstObject());
if (mov)
{
_RoundCamera(delta.X()*speedVal*0.02f, -delta.Z()*speedVal*0.02f);
}
else
{
_PanCamera(delta.X()*mPixelToWorld.first*speedVal, delta.Z()*mPixelToWorld.second*speedVal);
}
}
else if (mIsRightPressed)
{
_ZoomCamera(-delta.Z()*mPixelToWorld.second*PX2_EDIT.GetCameraMoveSpeed()*speedVal);
}
}
else
{
if (mIsRightPressed)
{
_RolateCamera(delta.X()*mPixelToWorld.first*speedVal*0.25f, -delta.Z()*mPixelToWorld.second*speedVal);
}
else if (mIsMiddlePressed)
{
_PanCamera(-delta.X()*mPixelToWorld.first*speedVal, delta.Z()*mPixelToWorld.second*speedVal);
}
}
}
else
{
_PanCamera(-delta.X()*mPixelToWorld.first, delta.Z()*mPixelToWorld.second*speedVal);
}
}
else
{
if (mIsLeftPressed)
{
PX2_EDIT.GetTerrainEdit()->Apply(false);
}
Edit::EditMode em = PX2_EDIT.GetEditMode();
if ((Edit::EM_TRANSLATE == em || Edit::EM_ROTATE == em || Edit::EM_SCALE == em))
{
Camera *camera = mSceneNodeCtrlCanvas->GetOverCamera();
if (mSceneNodeCtrl)
mSceneNodeCtrl->OnMotion(mIsLeftPressed, camera,
curViewPortPos, lastViewPortPos, GetSize());
if (mIsLeftPressed)
//.........这里部分代码省略.........
示例13: SetVelocity
//----------------------------------------------------------------------------
bool InputPushTransformController::Update(double applicationTime,
double elapsedTime1)
{
if (!Controller::Update(applicationTime, elapsedTime1))
return false;
float elapsedTime = (float)elapsedTime1;
if (mIsPressedValid)
{
mSampingTiming += elapsedTime;
if (mSampingTiming >= 0.03f)
{
AVector deltaVec = mCurTouchPos - mLastSamplePos;
mLastSamplePos = mCurTouchPos;
mTouchMoveSpeed = deltaVec / 0.03f;
mSampingTiming = 0.0f;
}
}
if (!IsSmallTransScope())
{
// 减小速度
AVector vecTemp = mVelocity;
float vecLength = vecTemp.Normalize();
vecLength -= mFriction * elapsedTime;
if (vecLength <= 0.0f)
{
SetVelocity(AVector::ZERO);
}
else
{
SetVelocity(vecTemp * vecLength);
}
}
else
{
if (!mIsPressedValid) // 没有按下
{
if (0.0f == mSideMoveLength)
mSideMoveLength = 1.0f;
AVector smallDir = GetSmallTransDir();
if (AVector::ZERO != smallDir)
{
float moveDirLength = smallDir.Normalize();
float adjuge = moveDirLength / mSideMoveLength;
mVelocity += smallDir * mFriction * adjuge * adjuge * elapsedTime;
}
}
else
{
mVelocity = AVector::ZERO;
}
}
AVector velocityDis = mVelocity*elapsedTime;
AVector movedDis;
if (IsXY())
{
movedDis.X() = velocityDis.X();
movedDis.Y() = velocityDis.Y();
}
else
{
movedDis.X() = velocityDis.X();
movedDis.Z() = velocityDis.Z();
}
AVector beforeSmallDir = GetSmallTransDir();
OnMoving(movedDis);
if (IsSmallTransScope())
{
AVector smallDir = GetSmallTransDir();
if (smallDir == AVector::ZERO && beforeSmallDir != AVector::ZERO)
{
SetVelocity(AVector::ZERO);
}
}
return true;
}
示例14: if
//----------------------------------------------------------------------------
void InputPushTransformController::OnEvent(Event *event)
{
if (!Active) return;
if (!IsPlaying()) return;
Movable *mov = DynamicCast<Movable>(GetControlledable());
if (!mov) return;
if (InputEventSpace::IsEqual(event, InputEventSpace::LevelView))
{
mIsPressedValid = false;
}
else if (InputEventSpace::IsEqual(event, InputEventSpace::MousePressed) ||
InputEventSpace::IsEqual(event,InputEventSpace::TouchPressed))
{
InputEventData data = event->GetData<InputEventData>();
mIsPressedValid = true;
mSampingTiming = 0.0f;
mPressedTime = (float)Time::GetTimeInSeconds();
mPressedPos = data.MTPos;
if (mConvertCallback)
{
mConvertCallback(mPressedPos, (int)data.MTPos.X(), (int)data.MTPos.Z());
}
mCurTouchPos = mPressedPos;
mLastTouchPos = mCurTouchPos;
mLastSamplePos = mCurTouchPos;
SetVelocity(AVector::ZERO);
}
else if (InputEventSpace::IsEqual(event, InputEventSpace::MouseReleased) ||
InputEventSpace::IsEqual(event, InputEventSpace::TouchReleased))
{
InputEventData data = event->GetData<InputEventData>();
mSampingTiming = 0.0f;
if (!mIsPressedValid) return;
mIsPressedValid = false;
mReleasedTime = (float)Time::GetTimeInSeconds();
mReleasedPos = data.MTPos;
if (mConvertCallback)
{
mConvertCallback(mPressedPos, (int)data.MTPos.X(), (int)data.MTPos.Z());
}
float deltaTime = mReleasedTime - mPressedTime;
if (deltaTime <= 0.0f) deltaTime = 1.0f;
//AVector speed = mReleasedPos - mPressedPos;
//speed /= deltaTime;
AVector speed = mTouchMoveSpeed;
float judge = 0.0f;
if (mLockDir != AVector::ZERO)
{
judge = mLockDir.Dot(speed);
}
else
{
judge = speed.Length();
}
judge = Mathf::FAbs(judge);
if (judge >= mPushTriggerSpeed)
{
if (mLockDir != AVector::ZERO)
{
speed.X() *= mLockDir.X();
speed.Y() *= mLockDir.Y();
speed.Z() *= mLockDir.Z();
}
SetReleaseVelocity(speed * judge);
}
if (IsSmallTransScope() && GetSmallTransDir() != AVector::ZERO)
{
SetReleaseVelocity(AVector::ZERO);
}
}
else if (InputEventSpace::IsEqual(event, InputEventSpace::MouseMoved) ||
InputEventSpace::IsEqual(event, InputEventSpace::TouchMoved))
{
InputEventData data = event->GetData<InputEventData>();
if (!mIsPressedValid) return;
mCurTouchPos = data.MTPos;
if (mConvertCallback)
{
mConvertCallback(mPressedPos, (int)data.MTPos.X(), (int)data.MTPos.Z());
//.........这里部分代码省略.........
示例15: OnMotion
//----------------------------------------------------------------------------
void SceneNodeCtrl::OnMotion(bool leftDown, RenderStep *renderStep,
PX2::APoint posNow, PX2::APoint posBefore)
{
PX2_UNUSED(leftDown);
PX2_UNUSED(renderStep);
Renderer *renderer = renderStep->GetRenderer();
Camera *camera = renderStep->GetCamera();
// 光标移动更新
if (DT_NONE == mDragType)
{
GeoObjFactory factory;
DragType dt = GetDragType(renderStep, posNow);
Movable *ctrlMov = 0;
Float4 colorYellowAlpha = Float4(1.0f, 1.0f, 0.0f, 0.3f);
if (DT_X == dt)
{
ctrlMov = GetCurrentCtrlX();
factory.UpdateCtrlColor(renderer, ctrlMov, Float4::YELLOW);
}
else if (DT_Y == dt)
{
ctrlMov = GetCurrentCtrlY();
factory.UpdateCtrlColor(renderer, ctrlMov, Float4::YELLOW);
}
else if (DT_Z == dt)
{
ctrlMov = GetCurrentCtrlZ();
factory.UpdateCtrlColor(renderer, ctrlMov, Float4::YELLOW);
}
else if (DT_XY == dt)
{
factory.UpdateCtrlColor1(renderer, GetCurrentCtrlXY(), colorYellowAlpha);
factory.UpdateCtrlColor1(renderer, GetCurrentCtrlYZ(), Float4::ZERO);
factory.UpdateCtrlColor1(renderer, GetCurrentCtrlXZ(), Float4::ZERO);
}
else if (DT_YZ == dt)
{
factory.UpdateCtrlColor1(renderer, GetCurrentCtrlYZ(), colorYellowAlpha);
factory.UpdateCtrlColor1(renderer, GetCurrentCtrlXY(), Float4::ZERO);
factory.UpdateCtrlColor1(renderer, GetCurrentCtrlXZ(), Float4::ZERO);
}
else if (DT_XZ == dt)
{
factory.UpdateCtrlColor1(renderer, GetCurrentCtrlXZ(), colorYellowAlpha);
factory.UpdateCtrlColor1(renderer, GetCurrentCtrlXY(), Float4::ZERO);
factory.UpdateCtrlColor1(renderer, GetCurrentCtrlYZ(), Float4::ZERO);
}
else if (DT_XYZ == dt)
{
factory.UpdateCtrlColor1(renderer, GetCurrentCtrlXYZ(), Float4::YELLOW);
}
else if (DT_NONE == dt)
{
factory.UpdateCtrlColor(renderer, GetCurrentCtrlX(), Float4::RED);
factory.UpdateCtrlColor(renderer, GetCurrentCtrlY(), Float4::GREEN);
factory.UpdateCtrlColor(renderer, GetCurrentCtrlZ(), Float4::BLUE);
factory.UpdateCtrlColor1(renderer, GetCurrentCtrlXY(), Float4::ZERO);
factory.UpdateCtrlColor1(renderer, GetCurrentCtrlYZ(), Float4::ZERO);
factory.UpdateCtrlColor1(renderer, GetCurrentCtrlXZ(), Float4::ZERO);
factory.UpdateCtrlColor1(renderer, GetCurrentCtrlXYZ(), Float4::WHITE);
}
if (DT_NONE == dt)
{
Event *ent = EditEventSpace::CreateEventX(EditEventSpace::SceneNodeDrag);
ent->SetData<int>(0);
EventWorld::GetSingleton().BroadcastingLocalEvent(ent);
}
else
{
Event *ent = EditEventSpace::CreateEventX(EditEventSpace::SceneNodeDrag);
ent->SetData<int>(1);
EventWorld::GetSingleton().BroadcastingLocalEvent(ent);
}
}
if (DT_NONE == mDragType) return;
else
{
Event *ent = EditEventSpace::CreateEventX(EditEventSpace::SceneNodeDrag);
ent->SetData<int>(1);
EventWorld::GetSingleton().BroadcastingLocalEvent(ent);
}
int numObjs = PX2_SELECTION.GetNumObjects();
if (0 == numObjs)
return;
// get pickPoint with the plane
TriMesh *meshHelp = PX2_GR.GetXYPlane();
if (DT_X == mDragType)
{
if (LT_PERSPECTIVE == mLookType || LT_TOP == mLookType)
meshHelp = PX2_GR.GetXYPlane();
else if (LT_FRONT == mLookType)
//.........这里部分代码省略.........