android - Opengl screen limits at different depths -
I am trying to create a 3D particle simulation with the detection of collision using OpenL ES 2.0 and I Can not understand how to collision with screen edges.
If I correctly adjust the catastrophe and in the case of the camera I can have the range of X and Y screen between -1.0 and 1.0 more or less when the particle is at 0.0-Z-depth , But the problem is the screen edges when the particle z position is not zero.
Basically, I have to check whether the particle is within the screen boundaries at all depths or not. Does anyone know how to do this?
Thank you!
The answer is frustum planes. Below is a C ++ / Direct 3D example that you can find useful:
ClassFostam {public: plane plane [6]; // Planes array of public: // Default Constructor Freism (for (unsigned int i = 0; i <6; i ++) Aircraft [i] = Aircraft (0,0,0,0,0,0 ) //} perspective projection frustum frustum (matrix * matrix, unsigned int width, unsigned whole height, float fov, closing near float, flota far off clip, float xfactor, float yFactor) // // frustrum plane vector r_organ (matrix- >, _41, matrix -> or_42, matrix-> _4 3) Vector VPN (matrix-> _31, matrix-> ;232, matrix-> _33) vector white (matrix-> _11, matrix-> 2, matrix-> _13) Vector vapor (matrix-> gt; _21, matrix-> gt22, matrix-> _23); // vpn * = - 1, vright * = -1, vup * = for right hand coordination system - 1; // Somewhat Offset Float Organify = D3xX3 Dot (& amp; R.Oorigin, & VPN); // Airplane Air; [4] .a = -vpn.x; Aircraft [4] .b = -vpn.y; aircraft [4] .c = -vpn.z; plane [4] .d = - paw clip-organ Fset; // aircraft carriers [5]. A = VPN.X; Aircraft [5]. B = VPNI; Aircraft [5]. C = VPNs; Aircraft [5]. D = passclip + organ offset; // Area of view flov Fovx = fov * xFactor; Float fuzzy = fawnx * height / width * yFactor; Fawks * = 0.5 F, Fawwi * = 0.5 F; Float tanx = tan (d3dactoradian (FOX)); Float tan = tan (d3ctoreradiyan (faji)); // left plane vector n = (VPN * tight) + right; D3DXVec3 Normal (& amp; N, & amp; एन); Plane [0]. A = NX; Plane [0]. B = NE; Plane [0]. C = N Jazz; // Right plane n = (VPN * tanx) - Veera; D3DXVec3 Normal (& amp; N, & amp; एन); Aircraft [1]. A = NX; Aircraft [1]. B = NE; Aircraft [1]. C = N Jazz; // Bottom plane n = (VPN * tani) + Vip; D3DXVec3 Normal (& amp; N, & amp; एन); Aircraft [2]. A = NX; Aircraft [2]. B = NE; Aircraft [2]. C = N Jazz; // Top plane n = (VPN * tani) - Vip; D3DXVec3 Normal (& amp; N, & amp; एन); Aircraft [3]. A = NX; Aircraft [3]. B = NE; Aircraft [3]. C = N Jazz; {N.x = plane [i] .a; for unsigned int i = 0; i & lt; 4; i ++) N.y = plane [i] .b; N.z = Aircraft [I] C; Plane [ii] D = D3 DXVC3 dot (& amp; N, & R_Origin); }}};
Note that to calculate the intersection with the trivial planes, you should use the WorldSpace coordinates of the particles.
Comments
Post a Comment