void Ball::Update(float dt) { //d = v*t //v = a*t; //d = v*t*t+c //dp = v*dt //pos = pos + a XMVECTOR force_vec = XMVectorAdd(force,impulse); XMVECTOR mass_vec = XMVectorReplicate(mass); XMVECTOR time_vec = XMVectorReplicate(dt*0.001f); impulse = XMVectorZero(); acceleration = XMVectorDivide(force_vec,mass_vec); velocity = XMVectorMultiplyAdd(acceleration,time_vec,velocity); position = XMVectorMultiplyAdd(velocity,time_vec,position); // auto coll = IntersectCircleAxisAlignedBox(this,&system->table); //if (coll == 0) { //velocity = XMVectorNegate(velocity); //} object_time += dt; }
mxUNDONE #if 0 void BatchRenderer::DrawRing( const XMFLOAT3& Origin, const XMFLOAT3& MajorAxis, const XMFLOAT3& MinorAxis, const FColor& Color ) { static const DWORD dwRingSegments = 32; XMFLOAT3 verts[ dwRingSegments + 1 ]; XMVECTOR vOrigin = XMLoadFloat3( &Origin ); XMVECTOR vMajor = XMLoadFloat3( &MajorAxis ); XMVECTOR vMinor = XMLoadFloat3( &MinorAxis ); FLOAT fAngleDelta = XM_2PI / ( float )dwRingSegments; // Instead of calling cos/sin for each segment we calculate // the sign of the angle delta and then incrementally calculate sin // and cosine from then on. XMVECTOR cosDelta = XMVectorReplicate( cosf( fAngleDelta ) ); XMVECTOR sinDelta = XMVectorReplicate( sinf( fAngleDelta ) ); XMVECTOR incrementalSin = XMVectorZero(); static const XMVECTOR initialCos = { 1.0f, 1.0f, 1.0f, 1.0f }; XMVECTOR incrementalCos = initialCos; for( DWORD i = 0; i < dwRingSegments; i++ ) { XMVECTOR Pos; Pos = XMVectorMultiplyAdd( vMajor, incrementalCos, vOrigin ); Pos = XMVectorMultiplyAdd( vMinor, incrementalSin, Pos ); XMStoreFloat3( ( XMFLOAT3* )&verts[i], Pos ); // Standard formula to rotate a vector. XMVECTOR newCos = incrementalCos * cosDelta - incrementalSin * sinDelta; XMVECTOR newSin = incrementalCos * sinDelta + incrementalSin * cosDelta; incrementalCos = newCos; incrementalSin = newSin; } verts[ dwRingSegments ] = verts[0]; // Copy to vertex buffer assert( (dwRingSegments+1) <= MAX_VERTS ); XMFLOAT3* pVerts = NULL; HRESULT hr; V( g_pVB->Lock( 0, 0, (void**)&pVerts, D3DLOCK_DISCARD ) ) memcpy( pVerts, verts, sizeof(verts) ); V( g_pVB->Unlock() ) // Draw ring D3DXCOLOR clr = Color; g_pEffect9->SetFloatArray( g_Color, clr, 4 ); g_pEffect9->CommitChanges(); pd3dDevice->DrawPrimitive( D3DPT_LINESTRIP, 0, dwRingSegments ); }
// mPosition += d*mLook void Camera::Walk(float d) { XMVECTOR s = XMVectorReplicate(d); XMVECTOR l = XMLoadFloat3(&mLook); XMVECTOR p = XMLoadFloat3(&mPosition); XMStoreFloat3(&mPosition, XMVectorMultiplyAdd(s, l, p)); }
void IControllable::walk( float d ) { XMVECTOR s = XMVectorReplicate(d); XMVECTOR l = XMLoadFloat3(mRotation.getFrontVector()); XMVECTOR p = XMLoadFloat3(&mTranslation); XMStoreFloat3(&mTranslation, XMVectorMultiplyAdd(s, l, p)); }
void IControllable::strafe( float d ) { XMVECTOR s = XMVectorReplicate(d); XMVECTOR r = XMLoadFloat3(mRotation.getRightVector()); XMVECTOR p = XMLoadFloat3(&mTranslation); XMStoreFloat3(&mTranslation, XMVectorMultiplyAdd(s, r, p)); }
void Entity::Jump(float d) { XMVECTOR s = XMVectorReplicate(d); XMVECTOR u = XMLoadFloat3(&mUp); XMVECTOR p = XMLoadFloat3(&mPosition); XMStoreFloat3(&mPosition, XMVectorMultiplyAdd(s, u, p)); }
void Aircraft::Move() { _movementVector = XMVectorReplicate(_thrust); _lookVector = XMLoadFloat3(&_look); _positionVector = XMLoadFloat3(&_position); XMStoreFloat3(&_position, XMVectorMultiplyAdd(_movementVector, _lookVector, _positionVector)); }
// mPosition += d*mRight void Camera::Strafe(float d) { XMVECTOR s = XMVectorReplicate(d); XMVECTOR r = XMLoadFloat3(&mRight); XMVECTOR p = XMLoadFloat3(&mPosition); XMStoreFloat3(&mPosition, XMVectorMultiplyAdd(s,r,p)); }
void Aircraft::UpMovement(float movement) { _movementVector = XMVectorReplicate(movement); _upVector = XMLoadFloat3(&_up); _positionVector = XMLoadFloat3(&_position); XMStoreFloat3(&_position, XMVectorMultiplyAdd(_movementVector, _upVector, _positionVector)); }
void Aircraft::Strafe(float movement) { _movementVector = XMVectorReplicate(_thrust); _rightVector = XMLoadFloat3(&_right); _positionVector = XMLoadFloat3(&_position); XMStoreFloat3(&_position, XMVectorMultiplyAdd(_movementVector, _rightVector, _positionVector)); }
void Camera::walk(float d) { // mPosition += d*mLook XMVECTOR s = XMVectorReplicate(d); // become (d,d,d,d) XMVECTOR l = XMLoadFloat3(&m_look); XMVECTOR p = XMLoadFloat3(&m_position); XMStoreFloat3(&m_position, XMVectorMultiplyAdd(s, l, p)); }
void Camera::Strafe(FLOAT d) { // mPosition += d*mRight XMVECTOR s = XMVectorReplicate(d); XMVECTOR r = XMLoadFloat3(&m_right); XMVECTOR p = XMLoadFloat3(&m_position); XMStoreFloat3(&m_position, XMVectorMultiplyAdd(s, r, p)); }
// @brief 前后平移操作 // // @param dis 为正: 前进; 为负: 后退 void Camera::Walk(float dis) { // mPos += dis * mLook XMVECTOR s = XMVectorReplicate(dis); XMVECTOR l = XMLoadFloat3(&mLook); XMVECTOR p = XMLoadFloat3(&mPos); XMStoreFloat3(&mPos, XMVectorMultiplyAdd(s, l, p)); }
void Entity::Strafe(float d) { // mPosition += d*mRight XMVECTOR s = XMVectorReplicate(d); XMVECTOR r = XMLoadFloat3(&mRight); XMVECTOR p = XMLoadFloat3(&mPosition); XMStoreFloat3(&mPosition, XMVectorMultiplyAdd(s, r, p)); }
void Camera::Walk(FLOAT d) { // mPosition += d*mLook XMVECTOR s = XMVectorReplicate(d); XMVECTOR l = XMLoadFloat3(&m_look); XMVECTOR p = XMLoadFloat3(&m_position); XMStoreFloat3(&m_position, XMVectorMultiplyAdd(s, l, p)); }
// @brief 左右平移操作 // // @param dis 为正: Strafe Right; 为负: Strafe Left void Camera::Strafe(float dis) { // mPos += dis * mRight XMVECTOR s = XMVectorReplicate(dis); XMVECTOR r = XMLoadFloat3(&mRight); XMVECTOR p = XMLoadFloat3(&mPos); XMStoreFloat3(&mPos, XMVectorMultiplyAdd(s, r, p)); }
void Camera::moveVert(float d) { // mPosition += d*mRight XMVECTOR s = XMVectorReplicate(d); XMVECTOR r = XMLoadFloat3(&mUp); XMVECTOR p = XMLoadFloat3(&mPosition); XMStoreFloat3(&mPosition, XMVectorMultiplyAdd(s, r, p)); }
void Entity::Walk(float d) { if (goToPos){ mDistanceLeft -= d; } XMVECTOR s = XMVectorReplicate(d); XMVECTOR l = XMLoadFloat3(&mLook); XMVECTOR p = XMLoadFloat3(&mPosition); XMStoreFloat3(&mPosition, XMVectorMultiplyAdd(s, l, p)); }
void Camera::Strafe(float p_Distance) { XMVECTOR t_Singed = XMVectorReplicate(p_Distance); XMVECTOR t_Right = XMLoadFloat3(&m_Right); XMVECTOR t_Pos = XMLoadFloat3(&m_Position); XMStoreFloat3(&m_Position, XMVectorMultiplyAdd(t_Singed, t_Right, t_Pos)); m_HasMoved = true; }
void Aircraft::Lift() { float liftSpeed = (-_rotation.x) * _thrust; XMVECTOR movement = XMVectorReplicate(liftSpeed); XMVECTOR up = XMLoadFloat3(&_up); XMVECTOR position = XMLoadFloat3(&_position); XMStoreFloat3(&_position, XMVectorMultiplyAdd(movement, up, position)); }
void Aircraft::Bank() { float bankSpeed = _rotation.z * _thrust; XMVECTOR movement = XMVectorReplicate(bankSpeed); XMVECTOR right = XMLoadFloat3(&_right); XMVECTOR position = XMLoadFloat3(&_position); XMStoreFloat3(&_position, XMVectorMultiplyAdd(movement, right, position)); }
void Camera::Walk(float d) { XMVECTOR s = XMVectorReplicate(d); XMVECTOR l = XMLoadFloat3(&mLook); XMVECTOR p = XMLoadFloat3(&mPosition); XMFLOAT3 test; XMStoreFloat3(&test, XMVectorMultiplyAdd(s, l, p)); if (mUseConstraints){ if (BoundsCheck(test)){ mPosition = test; } } else{ mPosition = test; } }
void Camera::strafe(float d) { // mPosition += d*mRight XMVECTOR s = XMVectorReplicate(d); // become (d,d,d,d) XMVECTOR r = XMLoadFloat3(&m_right); XMVECTOR p = XMLoadFloat3(&m_position); // Do compenent wise multiplication of d and m_right, if m_right is (1,0,0,0) // this give (d,0,0,0). // Each component of m_right is needed in the case of a rotated cam. XMStoreFloat3(&m_position, XMVectorMultiplyAdd(s, r, p)); }
void Camera::Walk(float p_Distance) { //prettey damn good XMVECTOR t_Singed = XMVectorReplicate(p_Distance); XMVECTOR t_Look = XMLoadFloat3(&m_Look); XMVECTOR t_Pos = XMLoadFloat3(&m_Position); XMStoreFloat3(&m_Position, XMVectorMultiplyAdd(t_Singed, t_Look, t_Pos)); m_HasMoved = true; }
VOID DebugDraw::DrawRing( const XMFLOAT3& Origin, const XMFLOAT3& MajorAxis, const XMFLOAT3& MinorAxis, D3DCOLOR Color ) { static const DWORD dwRingSegments = 32; MeshVertexP verts[ dwRingSegments + 1 ]; XMVECTOR vOrigin = XMLoadFloat3( &Origin ); XMVECTOR vMajor = XMLoadFloat3( &MajorAxis ); XMVECTOR vMinor = XMLoadFloat3( &MinorAxis ); FLOAT fAngleDelta = XM_2PI / ( float )dwRingSegments; // Instead of calling cos/sin for each segment we calculate // the sign of the angle delta and then incrementally calculate sin // and cosine from then on. XMVECTOR cosDelta = XMVectorReplicate( cosf( fAngleDelta ) ); XMVECTOR sinDelta = XMVectorReplicate( sinf( fAngleDelta ) ); XMVECTOR incrementalSin = XMVectorZero(); static const XMVECTOR initialCos = { 1.0f, 1.0f, 1.0f, 1.0f }; XMVECTOR incrementalCos = initialCos; for( DWORD i = 0; i < dwRingSegments; i++ ) { XMVECTOR Pos; Pos = XMVectorMultiplyAdd( vMajor, incrementalCos, vOrigin ); Pos = XMVectorMultiplyAdd( vMinor, incrementalSin, Pos ); XMStoreFloat3( ( XMFLOAT3* )&verts[i], Pos ); // Standard formula to rotate a vector. XMVECTOR newCos = incrementalCos * cosDelta - incrementalSin * sinDelta; XMVECTOR newSin = incrementalCos * sinDelta + incrementalSin * cosDelta; incrementalCos = newCos; incrementalSin = newSin; } verts[ dwRingSegments ] = verts[0]; SimpleShaders::SetDeclPos(); SimpleShaders::BeginShader_Transformed_ConstantColor( g_matViewProjection, Color ); g_pd3dDevice->DrawPrimitiveUP( D3DPT_LINESTRIP, dwRingSegments, ( const VOID* )verts, sizeof( MeshVertexP ) ); SimpleShaders::EndShader(); }
void Camera::Strafe(float d) { XMVECTOR s = XMVectorReplicate(d); XMVECTOR r = XMLoadFloat3(&mRight); XMVECTOR p = XMLoadFloat3(&mPosition); XMStoreFloat3(&mPosition, XMVectorMultiplyAdd(s, r, p)); /*float y = mTerrain->GetHeight(mPosition.x,mPosition.z); mPosition = XMFLOAT3(mPosition.x, y, mPosition.z);*/ }
// Transform the triangle coordinates so that they remain centered and at the right scale. // (mapping a [0,0,1,1] square into a [0,0,1,1] rectangle) inline XMFLOAT3 D3D12HDR::TransformVertex(XMFLOAT2 point, XMFLOAT2 offset) { auto scale = XMFLOAT2(min(1.0f, 1.0f / m_aspectRatio), min(1.0f, m_aspectRatio)); auto margin = XMFLOAT2(0.5f * (1.0f - scale.x), 0.5f * (1.0f - scale.y)); auto v = XMVectorMultiplyAdd( XMLoadFloat2(&point), XMLoadFloat2(&scale), XMVectorAdd(XMLoadFloat2(&margin), XMLoadFloat2(&offset))); XMFLOAT3 result; XMStoreFloat3(&result, v); return result; }
void Camera::Walk(float d) { //prettey damn good XMVECTOR s = XMVectorReplicate(d); XMVECTOR l = XMLoadFloat3(&mLook); XMVECTOR p = XMLoadFloat3(&mPosition); XMStoreFloat3(&mPosition, XMVectorMultiplyAdd(s, l, p)); /*float y = mTerrain->GetHeight(mPosition.x,mPosition.z); mPosition = XMFLOAT3(mPosition.x, y, mPosition.z);*/ }
void XM_CALLCONV Camera::Strafe( float distance ) { XMVECTOR s = XMVectorReplicate( distance ); XMVECTOR r = XMLoadFloat3( &right ); XMVECTOR p = XMLoadFloat3( &pos ); XMStoreFloat3( &pos, XMVectorMultiplyAdd( s, r, p ) ); }
void XM_CALLCONV Camera::Walk( float distance ) { XMVECTOR s = XMVectorReplicate( distance ); XMVECTOR l = XMLoadFloat3( &look ); XMVECTOR p = XMLoadFloat3( &pos ); XMStoreFloat3( &pos, XMVectorMultiplyAdd( s, l, p )); }