Exemplo n.º 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;
}
Exemplo n.º 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 );
}
Exemplo n.º 3
0
void Aircraft::Move() {
    _movementVector = XMVectorReplicate(_thrust);
    _lookVector = XMLoadFloat3(&_look);
    _positionVector = XMLoadFloat3(&_position);

    XMStoreFloat3(&_position, XMVectorMultiplyAdd(_movementVector, _lookVector, _positionVector));
}
Exemplo n.º 4
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));
}
Exemplo n.º 5
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));
}
Exemplo n.º 6
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));
}
Exemplo n.º 7
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));
}
void Camera::Render()
{
	// Load the rotation and make radian vectors.
	XMVECTOR rotationVector = XMLoadFloat3( &m_Rotation );
	XMVECTOR radianVector = XMVectorReplicate( 0.0174532925f );

	// Setup the vector that points upwards.
	XMVECTOR upVector = XMVectorSet( 0.f, 1.f, 0.f, 0.f );

	// Load the position into an XMVECTOR structure.
	XMVECTOR positionVector = XMLoadFloat3(&m_Position);

	// Setup where the camera is looking by default.
	XMVECTOR lookAtVector = XMVectorSet( 0.f, 0.f, 1.f, 0.f );

	// Create the rotation matrix from the product of the rotation vector and the radian vector.
	// This converts the rotations to radians before creating the rotation matrix
	XMMATRIX rotationMatrix = XMMatrixRotationRollPitchYawFromVector(rotationVector * radianVector);

	// Transform the lookAt and up vector by the rotation matrix so the view is correctly 
	// rotated at the origin.
	lookAtVector = XMVector3TransformCoord(lookAtVector, rotationMatrix);
	upVector = XMVector3TransformCoord(upVector, rotationMatrix);

	// Translate the rotated camera position to the location of the viewer.
	lookAtVector = XMVectorAdd(positionVector, lookAtVector);

	// Finally create the view matrix from the three updated vectors.
	m_ViewMatrix = XMMatrixLookAtLH(positionVector, lookAtVector, upVector);
}
Exemplo n.º 9
0
void Entity::Jump(float d)
{
	XMVECTOR s = XMVectorReplicate(d);
	XMVECTOR u = XMLoadFloat3(&mUp);
	XMVECTOR p = XMLoadFloat3(&mPosition);
	XMStoreFloat3(&mPosition, XMVectorMultiplyAdd(s, u, p));
}
Exemplo n.º 10
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));
}
Exemplo n.º 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));
}
Exemplo n.º 12
0
void Aircraft::UpMovement(float movement)
{
    _movementVector = XMVectorReplicate(movement);
    _upVector = XMLoadFloat3(&_up);
    _positionVector = XMLoadFloat3(&_position);

    XMStoreFloat3(&_position, XMVectorMultiplyAdd(_movementVector, _upVector, _positionVector));
}
Exemplo n.º 13
0
void Aircraft::Strafe(float movement)
{
    _movementVector = XMVectorReplicate(_thrust);
    _rightVector = XMLoadFloat3(&_right);
    _positionVector = XMLoadFloat3(&_position);

    XMStoreFloat3(&_position, XMVectorMultiplyAdd(_movementVector, _rightVector, _positionVector));
}
Exemplo n.º 14
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));
}
Exemplo n.º 15
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));
}
Exemplo n.º 16
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));
}
Exemplo n.º 17
0
void Camera::MoveLookVec(float dist){

	XMVECTOR pos = XMLoadFloat3(&m_position);
	XMVECTOR look = XMLoadFloat3(&m_look);
	pos += look * XMVectorReplicate(dist);
	
	XMStoreFloat3(&m_position, pos);
}
Exemplo n.º 18
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));
}
Exemplo n.º 19
0
void Camera::MoveRightVec(float dist){

	XMVECTOR pos = XMLoadFloat3(&m_position);
	XMVECTOR right = XMLoadFloat3(&m_right);
	pos += right * XMVectorReplicate(dist);
	
	XMStoreFloat3(&m_position, pos);
}
Exemplo n.º 20
0
void Camera::MoveUpVec(float dist){

	XMVECTOR pos = XMLoadFloat3(&m_position);
	XMVECTOR up = XMLoadFloat3(&m_up);
	pos += up * XMVectorReplicate(dist);
	
	XMStoreFloat3(&m_position, pos);
}
Exemplo n.º 21
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));
}
Exemplo n.º 22
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));
}
Exemplo n.º 23
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;
}
Exemplo n.º 24
0
	//---------------------------------------------------------------------
	bool LooseOctreeZone::isFitInChildZone(const Util::AABBPtr & aabb)
	{
		XMVECTOR halfSideSize = XMVectorReplicate((LOOSE_K * WORLD_SIZE / (2 << mDepth)) * 0.5f);

		XMVECTOR nodeSize = aabb->getSize();

		/// "&& true" to kill the warning C4800: 'BOOL' : forcing value to bool 'true' or 'false' (performance warning).
		return XMVector3LessOrEqual(nodeSize, halfSideSize) && true;
	}
Exemplo n.º 25
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));
}
Exemplo n.º 26
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; }
}
Exemplo n.º 27
0
	// Recommended frequencies are ...
	//
	//  lowfreq  = 880  Hz
	//  highfreq = 5000 Hz
	//
	// Set mixfreq to whatever rate your system is using (eg 48Khz)
	void init_3band_state(EQSTATE* es, int lowfreq, int highfreq, int mixfreq)
	{
	  // Clear state 

	  memset(es,0,sizeof(EQSTATE));

	  // Set Low/Mid/High gains to unity

	  es->lg = XMVectorReplicate(1.0f);
	  es->mg = XMVectorReplicate(1.0f);
	  es->hg = XMVectorReplicate(1.0f);

	  // Calculate filter cutoff frequencies
	  float	lf = 2 * sinf(cPi * ((float)lowfreq / (float)mixfreq)); 
	  float	hf = 2 * sinf(cPi * ((float)highfreq  / (float)mixfreq)); 

	  es->lf = XMVectorReplicate(lf);
	  es->hf = XMVectorReplicate(hf);
	}
Exemplo n.º 28
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));
}
Exemplo n.º 29
0
	//---------------------------------------------------------------------
	bool LooseOctreeZone::isInside(const Util::AABBPtr & aabb)
	{
		XMVECTOR size = XMVectorReplicate((LOOSE_K * WORLD_SIZE / (2 << mDepth)));

		XMVECTOR minPoint = mAABB->getCenterPoint() - size;
		XMVECTOR maxPoint = mAABB->getCenterPoint() + size;

		return XMVector3LessOrEqual(minPoint, aabb->getMinPoint()) && 
			XMVector3LessOrEqual(aabb->getMaxPoint(), maxPoint);
	}
Exemplo n.º 30
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));
}