Eufloria HD out for Google Play Store now!
0 Members and 1 Guest are viewing this topic.
Code: [Select]t = ((i * (Px1 - Lx1)) + (j * (Py1 - Ly1)) + (k * (Pz1 - Lz1))) / ((i * (Lx2 - Lx1)) + (j * (Ly2 - Ly1)) + (k * (Lz2 - Lz1)))Perhaps this?
t = ((i * (Px1 - Lx1)) + (j * (Py1 - Ly1)) + (k * (Pz1 - Lz1))) / ((i * (Lx2 - Lx1)) + (j * (Ly2 - Ly1)) + (k * (Lz2 - Lz1)))
t = ((i * (Px1 - Lx1)) + (j * (Py1 - Ly1)) + (k * (Pz1 - Lz1))) / ((i * tx) + (j * ty) + (k * tz))
0 = (i * (((t * tx) + Lx1) - Px1)) + (j * (((t * ty) + Ly1) - Py1)) + (k * (((t * tz) + Lz1) - Pz1))u=txv=tyw=tzm=Lx1n=Ly1o=Lz1q=Px1r=Py1s=Pz10 = (i * (((t * u) + m) - q)) + (j * (((t * v) + n) - r)) + (k * (((t * w) + o) - s)) <-- Input for the websitet = (-j * n + j * r - k * o + k * s - i * m + i * q) / (j * v + k * w + i * u) <-- Output from the websitet = (-j * Ly1 + j * Py1 - k * Lz1 + k * Pz1 - i * Lx1 + i * Px1) / (j * ty + k * tz + i * tx)t = ((i * (Px1 - Lx1)) + (j * (Py1 - Ly1)) + (k * (Pz1 - Lz1))) / ((i * tx) + (j * ty) + (k * tz))
-- get plane coordinates Px1 = vertex3dXtransformed[firstvertex] Py1 = vertex3dYtransformed[firstvertex] Pz1 = vertex3dZtransformed[firstvertex] Px2 = vertex3dXtransformed[secondvertex] Py2 = vertex3dYtransformed[secondvertex] Pz2 = vertex3dZtransformed[secondvertex] Px3 = vertex3dXtransformed[thirdvertex] Py3 = vertex3dYtransformed[thirdvertex] Pz3 = vertex3dZtransformed[thirdvertex] -- get line coordinates Lx1 = GetCameraX() Ly1 = GetCameraY() Lz1 = CameraZ Lx2 = vertex3dXtransformed[vertexID] Ly2 = vertex3dYtransformed[vertexID] Lz2 = vertex3dZtransformed[vertexID] -- get 2 vectors along the plane -- PV1x stands for Plane Vector #1, X-coordinate PV1x = Px2 - Px1 PV1y = Py2 - Py1 PV1z = Pz2 - Pz1 PV2x = Px3 - Px1 PV2y = Py3 - Py1 PV2z = Pz3 - Pz1 -- now find the cross product, which is a line perpendicular to the plane -- PV1 X PV2 = normal vector! i = (PV1y * PV2z) - (PV1z * PV2y) j = (PV1z * PV2x) - (PV1x * PV2z) k = (PV1x * PV2y) - (PV1y * PV2x) -- for the line, calculate tx, ty, tz tx = Lx2 - Lx1 ty = Ly2 - Ly1 tz = Lz2 - Lz1 t = ((i * (Lx1 - Px1)) + (j * (Ly1 - Py1)) + (k * (Lz1 - Pz1))) / ((i * (Lx2 - Lx1)) + (j * (Ly2 - Ly1)) + (k * (Lz2 - Lz1))) intersectX = (t * tx) + Lx1 intersectY = (t * ty) + Ly1 intersectZ = (t * tz) + Lz1 -- calculate distance from intersection intersectdistance2d = (GetCameraX() - intersectX)^2 + (GetCameraY() - intersectY)^2 intersectdistance3d = math.sqrt((CameraZ - intersectZ)^2 + (intersectdistance2d)) if intersectdistance3d > distance3d then -- return false if the vertex is in front of the face return false else -- return true if the plane is closer than the vertex return true end
t = ((i * (Lx1 - Px1)) + (j * (Ly1 - Py1)) + (k * (Lz1 - Pz1))) / ((i * (Lx2 - Lx1)) + (j * (Ly2 - Ly1)) + (k * (Lz2 - Lz1)))