btVector3 v(1.0, 2.0, 3.0); float z_component = v.getZ(); std::cout << "The Z component of the vector is: " << z_component << std::endl;
btVector3 positions[3]; positions[0] = btVector3(0.0, 0.0, 0.0); positions[1] = btVector3(1.0, 2.0, 3.0); positions[2] = btVector3(4.0, 5.0, 6.0); float z_sum = 0.0; for (int i = 0; i < 3; i++) { float z_component = positions[i].getZ(); z_sum += z_component; } std::cout << "The sum of the Z components is: " << z_sum << std::endl;This example creates an array of btVector3 objects called `positions`, which contains three vectors with different values. The getZ function is called inside a loop to obtain the Z component of each vector, which is added to a running total in the `z_sum` variable. Finally, the sum of the Z components is printed to the console. Package/library: Bullet Physics.