I am trying to give an object a velocity spread (e.g. shotgun bullets or particle effect).
//dir is the initial direction
float angle1 = atan(dir.x, dir.z) + spread;
float angle2 = atan(dir.y, abs(dir.z)) + spread;
vec3 xz_dir = vec3(sin(angle1, 0.0, cos(angle2));
vec3 yz_dir = vec3(0.0, sin(angle2), cos(angle2));
vec3 new_dir = vec3(xz_dir.x * yz_dir.z, yz_dir.y, xz_dir.z * yz_dir.z);
new_dir.normalize();
The new_dir
spread works fine in the XY and YZ planes but if there is a Y component in the direction, the spread along the XY plane doesn't work.
float angle3 = atan(dir.y, dir.x) + spread; vec3 xy_dir vec3(cos(angle1_rad), sin(angle1_rad), 0.0);
How would I add this xy vector to the other two vectors? \$\endgroup\$