locked
float2 and float3 are undefined C++?

    Question

  • Does anyone know what file to include to use float2 and float3 with a DirectX Store App?

    #define ROTATION_GAIN 0.004f	// sensitivity adjustment for look controller
    #define MOVEMENT_GAIN 0.1f		// sensitivity adjustment for move controller
    
    ref class MoveLookController
    {
    private:
        // properties of the controller object
        float3 m_position;			    // the position of the controller
        float m_pitch, m_yaw;			// orientation euler angles in radians
    
        // properties of the Move control
        bool m_moveInUse;			    // specifies whether the move control is in use
        uint32 m_movePointerID;		    // id of the pointer in this control
        float2 m_moveFirstDown;		    // point where initial contact occurred
        float2 m_movePointerPosition;   // point where the move pointer is currently located
        float3 m_moveCommand;		    // the net command from the move control
    
        // properties of the Look control
        bool m_lookInUse;			    // specifies whether the look control is in use
        uint32 m_lookPointerID;		    // id of the pointer in this control
        float2 m_lookLastPoint;		    // last point (from last frame)
        float2 m_lookLastDelta;		    // for smoothing
    
        bool m_forward, m_back;			// states for movement
        bool m_left, m_right;
        bool m_up, m_down;
    
    
    public:
    
        // Methods to get input from the UI pointers
        void OnPointerPressed(
            _In_ Windows::UI::Core::CoreWindow^ sender,
            _In_ Windows::UI::Core::PointerEventArgs^ args
            );
    
        void OnPointerMoved(
            _In_ Windows::UI::Core::CoreWindow^ sender,
            _In_ Windows::UI::Core::PointerEventArgs^ args
            );
    
        void OnPointerReleased(
            _In_ Windows::UI::Core::CoreWindow^ sender,
            _In_ Windows::UI::Core::PointerEventArgs^ args
            );
    
        void OnKeyDown(
            _In_ Windows::UI::Core::CoreWindow^ sender,
            _In_ Windows::UI::Core::KeyEventArgs^ args
            );
    
        void OnKeyUp(
            _In_ Windows::UI::Core::CoreWindow^ sender,
            _In_ Windows::UI::Core::KeyEventArgs^ args
            );
    

    • Edited by IQ100 Monday, May 26, 2014 11:12 PM
    Monday, May 26, 2014 10:07 PM

Answers

  • There's a "BasicMath.h" header used in a number of the Windows Store samples that has some very simple types: Vector2, Vector3, Vector4, Matrix4x4 which have typedef aliases float2, float3, float4, and float4x4 to make them have the same name as HLSL vector types--although they don't behave exactly the same.

    Another solution is to use DirectXMath's XMFLOAT2 or XMFLOAT3 types or if you prefer the SimpleMath Vector2 or Vector3 wrappers in DirectXTK. If you really wanted, you could use a typedef for either of these as 'float2' or 'float3' but I'd suggest using the 'native' names instead for clarity and maintainability.



    Tuesday, May 27, 2014 5:04 AM

All replies

  • Hi,

    float2 or float3 is not the C++ type. They are the DirectX HLSL type. Please refer to the link below:

    http://msdn.microsoft.com/en-us/library/windows/desktop/bb509707(v=vs.85).aspx

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, May 27, 2014 3:31 AM
  • There's a "BasicMath.h" header used in a number of the Windows Store samples that has some very simple types: Vector2, Vector3, Vector4, Matrix4x4 which have typedef aliases float2, float3, float4, and float4x4 to make them have the same name as HLSL vector types--although they don't behave exactly the same.

    Another solution is to use DirectXMath's XMFLOAT2 or XMFLOAT3 types or if you prefer the SimpleMath Vector2 or Vector3 wrappers in DirectXTK. If you really wanted, you could use a typedef for either of these as 'float2' or 'float3' but I'd suggest using the 'native' names instead for clarity and maintainability.



    Tuesday, May 27, 2014 5:04 AM
  • Thanks for the replies! I found that it may be looking for XNA math which isn't available in the default DirectX app setup. I did realize that I could write the code for the math myself and wrote a solution for it. I  also tried switching to the newer DirectX XMVector2 and XMVector3 and ran into issues with public members. I found a better app model for the controls that is up to date. Thanks for the replies they are both good options!
    • Edited by IQ100 Tuesday, May 27, 2014 8:57 PM
    Tuesday, May 27, 2014 8:48 PM
  • float2 and float3 are in the XNA library for C++ that really needs to go away. The code is an outdated example that was placed on the 8.1 DirectX starter site. Not a very good example. The optional DirectX Template has much better code and is a better place too start. All I saw was HLSL when I searched for them and you are correct.
    • Edited by IQ100 Tuesday, May 27, 2014 8:54 PM
    Tuesday, May 27, 2014 8:54 PM