Example #1
0
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;
}
Example #2
0
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 );
}
Example #3
0
// 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));
}
Example #4
0
void IControllable::walk( float d )
{
    XMVECTOR s = XMVectorReplicate(d);
    XMVECTOR l = XMLoadFloat3(mRotation.getFrontVector());
    XMVECTOR p = XMLoadFloat3(&mTranslation);
    XMStoreFloat3(&mTranslation, XMVectorMultiplyAdd(s, l, p));
}
Example #5
0
void IControllable::strafe( float d )
{
    XMVECTOR s = XMVectorReplicate(d);
    XMVECTOR r = XMLoadFloat3(mRotation.getRightVector());
    XMVECTOR p = XMLoadFloat3(&mTranslation);
    XMStoreFloat3(&mTranslation, XMVectorMultiplyAdd(s, r, p));
}
Example #6
0
void Entity::Jump(float d)
{
	XMVECTOR s = XMVectorReplicate(d);
	XMVECTOR u = XMLoadFloat3(&mUp);
	XMVECTOR p = XMLoadFloat3(&mPosition);
	XMStoreFloat3(&mPosition, XMVectorMultiplyAdd(s, u, p));
}
Example #7
0
void Aircraft::Move() {
    _movementVector = XMVectorReplicate(_thrust);
    _lookVector = XMLoadFloat3(&_look);
    _positionVector = XMLoadFloat3(&_position);

    XMStoreFloat3(&_position, XMVectorMultiplyAdd(_movementVector, _lookVector, _positionVector));
}
Example #8
0
// 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));
}
Example #9
0
void Aircraft::UpMovement(float movement)
{
    _movementVector = XMVectorReplicate(movement);
    _upVector = XMLoadFloat3(&_up);
    _positionVector = XMLoadFloat3(&_position);

    XMStoreFloat3(&_position, XMVectorMultiplyAdd(_movementVector, _upVector, _positionVector));
}
Example #10
0
void Aircraft::Strafe(float movement)
{
    _movementVector = XMVectorReplicate(_thrust);
    _rightVector = XMLoadFloat3(&_right);
    _positionVector = XMLoadFloat3(&_position);

    XMStoreFloat3(&_position, XMVectorMultiplyAdd(_movementVector, _rightVector, _positionVector));
}
Example #11
0
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));
}
Example #12
0
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));
}
Example #13
0
// @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));
}
Example #14
0
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));
}
Example #15
0
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));
}
Example #16
0
// @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));
}
Example #17
0
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));
}
Example #18
0
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));
}
Example #19
0
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;
}
Example #20
0
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));
}
Example #21
0
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));
}
Example #22
0
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; }
}
Example #23
0
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));
}
Example #24
0
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();
}
Example #26
0
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;
}
Example #28
0
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);*/

}
Example #29
0
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 ) );
}
Example #30
0
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 ));
}