DirectX Math Examples

Explore fundamental math operations within the DirectX ecosystem.

Vector Addition

Demonstrates how to add two 3D vectors.

Vector Addition Example
                    #include <d3d11.h>
                    #include <d3dx11.h>

                    int main() {
                        D3DXVECTOR3 v1(1.0f, 2.0f, 3.0f);
                        D3DXVECTOR3 v2(4.0f, 5.0f, 6.0f);
                        D3DXVECTOR3 sum = v1 + v2;

                        // Print the sum
                        printf("Sum: (%f, %f, %f)\n", sum.x, sum.y, sum.z);

                        return 0;
                    }
                

Dot Product

Calculates the dot product of two vectors.

Dot Product Example
                    #include <d3d11.h>
                    #include <d3dx11.h>

                    int main() {
                        D3DXVECTOR3 v1(1.0f, 2.0f, 3.0f);
                        D3DXVECTOR3 v2(4.0f, 5.0f, 6.0f);
                        float dotProduct = v1.dot(v2);

                        // Print the dot product
                        printf("Dot Product: %f\n", dotProduct);

                        return 0;
                    }
                

Cross Product

Calculates the cross product of two vectors.

Cross Product Example
                    #include <d3d11.h>
                    #include <d3dx11.h>

                    int main() {
                        D3DXVECTOR3 v1(1.0f, 2.0f, 3.0f);
                        D3DXVECTOR3 v2(4.0f, 5.0f, 6.0f);
                        D3DXVECTOR3 crossProduct = v1.cross(v2);

                        // Print the cross product
                        printf("Cross Product: (%f, %f, %f)\n", crossProduct.x, crossProduct.y, crossProduct.z);

                        return 0;
                    }