Esempio n. 1
0
btCollisionShape * Helium::BulletShapeBox::CreateShape() const
{
	static const Simd::Vector3 half(0.5f, 0.5f, 0.5f);
	btVector3 extents;
	ConvertToBullet( half.Multiply(m_Extents), extents );
	return new btBoxShape(extents);
}
Esempio n. 2
0
void UpdateAI_ChasePlayer( AIComponentChasePlayer *pAiComponent, AvatarControllerComponent *pController )
{
	PlayerComponent *pTarget = NULL;
	float pTargetDistanceSquared = NumericLimits<float>::Maximum;
	Simd::Vector3 targetPosition = Simd::Vector3::Zero;
	Simd::Vector3 myPosition = Simd::Vector3::Zero;

	TransformComponent *pTransform = pAiComponent->GetComponentCollection()->GetFirst<TransformComponent>();
	
	if ( pTransform )
	{
		myPosition = pTransform->GetPosition();
		for (PlayerList::Iterator iter = g_PlayerList.Begin(); iter != g_PlayerList.End(); ++iter)
		{
			float d = (iter->Second() - myPosition).GetMagnitudeSquared();
			if ( d < pTargetDistanceSquared )
			{
				pTargetDistanceSquared = d;
				pTarget = iter->First();
				targetPosition = iter->Second();
			}
		}
	}
	
	if ( pTarget )
	{
		Simd::Vector3 moveDir = (targetPosition - myPosition).GetNormalized();

		pController->m_MoveDir.SetX( moveDir.GetElement(0));
		pController->m_MoveDir.SetY( moveDir.GetElement(1));
		pController->m_AimDir = Simd::Vector3::Zero;
		pController->m_bShoot = false;
	}
	else
	{
		pController->m_MoveDir = Simd::Vector2::Zero;
		pController->m_AimDir = Simd::Vector3::Zero;
		pController->m_bShoot = false;
	}
}
Esempio n. 3
0
/// Serialize an AaBox.
///
/// @param[in,out] rValue  AaBox to serialize.
///
/// @return  Reference to this object.
Serializer& Serializer::operator<<( Simd::AaBox& rValue )
{
    Simd::Vector3 minimum = rValue.GetMinimum();
    Simd::Vector3 maximum = rValue.GetMaximum();

    BeginStruct( STRUCT_TAG_AA_BOX );
    *this << Tag( TXT( "min" ) ) << minimum;
    *this << Tag( TXT( "max" ) ) << maximum;
    EndStruct();

    if( GetMode() == MODE_LOAD )
    {
        maximum.SetElement( 0, Max( minimum.GetElement( 0 ), maximum.GetElement( 0 ) ) );
        maximum.SetElement( 1, Max( minimum.GetElement( 1 ), maximum.GetElement( 1 ) ) );
        maximum.SetElement( 2, Max( minimum.GetElement( 2 ), maximum.GetElement( 2 ) ) );

        rValue.Set( minimum, maximum );
    }

    return *this;
}
Esempio n. 4
0
void GatherInput( PlayerInputComponent *pPlayerInput )
{
	float x = 0.0f;
	float y = 0.0f;

	if ( Helium::Input::IsKeyDown(Input::KeyCodes::KC_LEFT) )
	{
		x -= 1.0f;
	}
	
	if ( Helium::Input::IsKeyDown(Input::KeyCodes::KC_RIGHT) )
	{
		x += 1.0f;
	}

	if ( Helium::Input::IsKeyDown(Input::KeyCodes::KC_UP) )
	{
		y += 1.0f;
	}

	if ( Helium::Input::IsKeyDown(Input::KeyCodes::KC_DOWN) )
	{
		y -= 1.0f;
	}
	
	pPlayerInput->m_ScreenSpaceFocusPosition = Helium::Input::GetMousePosNormalized();


	GraphicsManagerComponent *pGraphics = pPlayerInput->GetWorld()->GetComponents().GetFirst<GraphicsManagerComponent>();
	GraphicsSceneView *pSceneView = pGraphics->GetGraphicsScene()->GetSceneView(0);

	Simd::Vector3 from;
	Simd::Vector3 to;
	pSceneView->ConvertNormalizedScreenCoordinatesToRaycast(pPlayerInput->m_ScreenSpaceFocusPosition, from, to);

	Simd::Plane plane(Simd::Vector3::BasisZ, -750.0f);
	Simd::Vector3 raycastNormalized = (to - from).GetNormalized();
	Simd::Vector3 pointOnPlane;
	
	if ( plane.CalculateLineIntersect( from, raycastNormalized, pointOnPlane) )
	{
#if GRAPHICS_SCENE_BUFFERED_DRAWER
		SimpleVertex verts[2];
		verts[0].position[0] = pointOnPlane.GetElement(0) - 30.0f;
		verts[0].position[1] = pointOnPlane.GetElement(1);
		verts[0].position[2] = pointOnPlane.GetElement(2);
		verts[0].color[0] = 0xFF;
		verts[0].color[1] = 0xFF;
		verts[0].color[2] = 0xFF;
		verts[0].color[3] = 0xFF;

		verts[1].position[0] = pointOnPlane.GetElement(0) + 30.0f;
		verts[1].position[1] = pointOnPlane.GetElement(1);
		verts[1].position[2] = pointOnPlane.GetElement(2);
		verts[1].color[0] = 0xFF;
		verts[1].color[1] = 0xFF;
		verts[1].color[2] = 0xFF;
		verts[1].color[3] = 0xFF;

		pGraphics->GetBufferedDrawer().DrawLineStrip(verts, 2);

		verts[0].position[0] = pointOnPlane.GetElement(0);
		verts[0].position[1] = pointOnPlane.GetElement(1) - 30.0f;

		verts[1].position[0] = pointOnPlane.GetElement(0);
		verts[1].position[1] = pointOnPlane.GetElement(1) + 30.0f;

		pGraphics->GetBufferedDrawer().DrawLineStrip(verts, 2);
#endif

		pPlayerInput->m_bFirePrimary = Helium::Input::IsMouseButtonDown( Helium::Input::MouseButtons::Left );
		pPlayerInput->m_WorldSpaceFocusPosition = pointOnPlane;
		pPlayerInput->m_bHasWorldSpaceFocus = true;
	}
	else
	{
		pPlayerInput->m_bFirePrimary = false;
		pPlayerInput->m_WorldSpaceFocusPosition = Simd::Vector3::Zero;
		pPlayerInput->m_bHasWorldSpaceFocus = false;
	}
	
	pPlayerInput->m_MoveDir = Simd::Vector2(x, y);
	pPlayerInput->m_MoveDir.NormalizeOrZero();

}
Esempio n. 5
0
void Curve::Render( RenderVisitor* render )
{
    HELIUM_ASSERT( render );

    DrawArgs* args = render->GetArgs();
    HELIUM_ASSERT( args );

    Helium::BufferedDrawer* drawInterface = render->GetDrawInterface();
    HELIUM_ASSERT( drawInterface );

    const VertexResource* vertices = m_Vertices;

    uint32_t countCurvePoints    = (uint32_t)m_Points.size();
    uint32_t countControlPoints  = GetNumberControlPoints();

    //
    //  Draw start end end locators
    //

    Helium::Color materialColor = GetMaterialColor( s_Material );

    Simd::Matrix44 globalTransform( GetGlobalTransform().array1d );

    if ( !m_Closed )
    {
        Simd::Matrix44 m;

        if ( countCurvePoints > 0 )
        {
            Simd::Vector3 point( &m_Points[ 0 ].x );
            m.MultiplySet( Simd::Matrix44( Simd::Matrix44::INIT_TRANSLATION, point ), globalTransform );
            m_Locator->Draw( drawInterface, args, materialColor, m );
        }

        if ( countCurvePoints > 1 )
        {
            Simd::Vector3 point( &m_Points[ countCurvePoints - 1 ].x );
            m.MultiplySet( Simd::Matrix44( Simd::Matrix44::INIT_TRANSLATION, point ), globalTransform );
            m_Locator->Draw( drawInterface, args, materialColor, m );

            Simd::Vector3 p1( &m_Points[ countCurvePoints - 2 ].x );
            Simd::Vector3 p2( &m_Points[ countCurvePoints - 1 ].x );
            Simd::Vector3 dir = ( p2 - p1 ).GetNormalized();
            AngleAxis angleAxis = AngleAxis::Rotation(
                OutVector,
                Vector3( dir.GetElement( 0 ), dir.GetElement( 1 ), dir.GetElement( 2 ) ) );
            m.SetRotationTranslation(
                Simd::Quat( Simd::Vector3( &angleAxis.axis.x ), angleAxis.angle ),
                p2 - ( dir * ( m_Cone->m_Length * 0.5f ) ) );
            m *= globalTransform;

            m_Cone->Draw( drawInterface, args, materialColor, m );
        }
    }

    if ( countCurvePoints > 0 ) 
    {
        //
        //  Draw Curve
        //
        uint32_t countCurveLines = m_Closed ? countCurvePoints : countCurvePoints - 1;

        if ( countCurveLines > 0 )
        {
            drawInterface->DrawUntextured(
                Helium::RENDERER_PRIMITIVE_TYPE_LINE_STRIP,
                globalTransform,
                vertices->GetBuffer(),
                NULL,
                vertices->GetBaseIndex() + countControlPoints + 1,
                countCurveLines + 1,
                0,
                countCurveLines,
                materialColor,
                Helium::RenderResourceManager::RASTERIZER_STATE_WIREFRAME_DOUBLE_SIDED );
            args->m_LineCount += countCurveLines;
        }

        //
        //  Draw Curve points 
        //
        drawInterface->DrawPoints(
            globalTransform,
            vertices->GetBuffer(),
            vertices->GetBaseIndex() + countControlPoints + 1,
            countCurvePoints,
            materialColor );
    }


    //
    //  Draw Control points
    //

    if ( countControlPoints > 0 )
    {
        //
        // Draw points hull
        //

        if ( m_Type != CurveType::Linear )
        {
            uint32_t countControlLines = m_Closed ? countControlPoints : countControlPoints - 1;

            if ( countControlLines > 0 )
            {
                drawInterface->DrawUntextured(
                    Helium::RENDERER_PRIMITIVE_TYPE_LINE_STRIP,
                    globalTransform,
                    vertices->GetBuffer(),
                    NULL,
                    vertices->GetBaseIndex(),
                    countControlLines + 1,
                    0,
                    countControlLines,
                    s_HullMaterial,
                    Helium::RenderResourceManager::RASTERIZER_STATE_WIREFRAME_DOUBLE_SIDED );
                args->m_LineCount += countControlLines;
            }
        }


        //
        // Draw all points
        //

        drawInterface->DrawPoints(
            globalTransform,
            vertices->GetBuffer(),
            vertices->GetBaseIndex(),
            countControlPoints,
            Viewport::s_ComponentMaterial );


        //
        //  Overdraw selected points
        //
        {
            Helium::Color textColor( 0xffffffff );

            OS_HierarchyNodeDumbPtr::Iterator childItr = GetChildren().Begin();
            OS_HierarchyNodeDumbPtr::Iterator childEnd = GetChildren().End();
            for ( uint32_t i = 0; childItr != childEnd; ++childItr )
            {
                CurveControlPoint* point = Reflect::SafeCast< CurveControlPoint >( *childItr );
                if ( point )
                {
                    if ( point->IsSelected() )
                    {
                        drawInterface->DrawPoints(
                            globalTransform,
                            vertices->GetBuffer(),
                            vertices->GetBaseIndex() + i,
                            1,
                            Viewport::s_SelectedComponentMaterial,
                            Helium::RenderResourceManager::DEPTH_STENCIL_STATE_NONE );
                    }

                    if ( GetControlPointLabel() != ControlPointLabel::None )
                    {
                        tstringstream label;
                        switch ( GetControlPointLabel() )
                        {
                        case ControlPointLabel::CurveAndIndex:
                            label << GetName() << TXT( "[" ) << i << TXT( "]" );
                            break;

                        case ControlPointLabel::IndexOnly:
                            label << "[" << i << "]";
                            break;
                        }

                        Simd::Vector3 position( &point->GetPosition().x );

                        // local to global
                        globalTransform.TransformPoint( position, position );

                        const int32_t offsetX = 0;
                        const int32_t offsetY = 15;

                        drawInterface->DrawProjectedText(
                            position,
                            offsetX,
                            offsetY,
                            String( label.str().c_str() ),
                            textColor,
                            Helium::RenderResourceManager::DEBUG_FONT_SIZE_SMALL );
                    }
                    ++i;
                }
            }
        }

        //
        //  Overdraw highlighted points
        // 
        {
            OS_HierarchyNodeDumbPtr::Iterator childItr = GetChildren().Begin();
            OS_HierarchyNodeDumbPtr::Iterator childEnd = GetChildren().End();
            for ( uint32_t i = 0; childItr != childEnd; ++childItr )
            {
                CurveControlPoint* point = Reflect::SafeCast< CurveControlPoint >( *childItr );
                if ( point )
                {
                    if ( point->IsHighlighted() )
                    {
                        drawInterface->DrawPoints(
                            globalTransform,
                            vertices->GetBuffer(),
                            vertices->GetBaseIndex() + i,
                            1,
                            Viewport::s_HighlightedMaterial,
                            Helium::RenderResourceManager::DEPTH_STENCIL_STATE_NONE );
                    }
                    ++i;
                }
            }
        }
    }

    Base::Render( render );
}
Esempio n. 6
0
/// Update the various view- and projection-related transform matrices from the view settings if necessary.
void GraphicsSceneView::UpdateViewProjection()
{
	// Don't update the transform matrices if the view parameters are not dirty.
	if( !m_bDirtyView )
	{
		return;
	}

	m_bDirtyView = false;

	// Compute the projection matrix.
	if ( m_horizontalFov < HELIUM_EPSILON )
	{
		m_projectionMatrix.SetOrthographicProjection( static_cast<float>(m_viewportWidth), static_cast<float>(m_viewportHeight), m_nearClip, m_farClip);
	}
	else
	{
		float32_t horizontalFovRadians = m_horizontalFov * static_cast< float32_t >( HELIUM_DEG_TO_RAD );
		if( m_farClip >= 0.0f )
		{
			m_projectionMatrix.SetPerspectiveProjection( horizontalFovRadians, m_aspectRatio, m_nearClip, m_farClip );
		}
		else
		{
			m_projectionMatrix.SetPerspectiveProjection( horizontalFovRadians, m_aspectRatio, m_nearClip );
		}
	}

	// Orthonormalize the view basis and compute the view matrix.
	Simd::Vector3 forward = m_forward.GetNormalized();

	Simd::Vector3 right;
	right.CrossSet( m_up, forward );
	right.Normalize();

	Simd::Vector3 up;
	up.CrossSet( forward, right );

	m_viewMatrix = Simd::Matrix44(
		right.GetElement( 0 ),    right.GetElement( 1 ),    right.GetElement( 2 ),    0.0f,
		up.GetElement( 0 ),       up.GetElement( 1 ),       up.GetElement( 2 ),       0.0f,
		forward.GetElement( 0 ),  forward.GetElement( 1 ),  forward.GetElement( 2 ),  0.0f,
		m_origin.GetElement( 0 ), m_origin.GetElement( 1 ), m_origin.GetElement( 2 ), 1.0f );

	// Compute the inverse view and combined inverse view/projection matrices.
	m_viewMatrix.GetInverse( m_inverseViewMatrix );
	m_inverseViewProjectionMatrix.MultiplySet( m_inverseViewMatrix, m_projectionMatrix );

	// Initialize the view frustum.
	m_frustum.Set( m_inverseViewProjectionMatrix.GetTranspose() );
}