Textured Sphere, reverse engineering texture?

Started by
0 comments, last by stuh505 17 years, 5 months ago
Situation is this, the camera moves through world space and a textured sphere which we specified to have back face on moves with us with radius 5000. Basically skysphere. Now there are many objects outside the sphere, we find where those objects would intersect the sphere as noted below. Now what i would like to do is edit the texture which is bound to sphere, where there is an intersect i would color a couple pixels white on the rectangular texture. How to reverse map the intersect on the sphere to the rectangular texture? Im using GLUquadricsObj sphere. //ray sphere intersect, exploits some special cases that are always present void SolidEntity::raySphereIntersect(Vec3 sphereOrigin, float sphereRadius){ Vec3 dir = _vec-sphereOrigin; float distance = dir.innerProduct(dir); if(sqrtf(distance) < sphereRadius){ _coords = _vec; return; } else{ dir.normalize(); float t0 = sqrtf(sphereRadius*sphereRadius*4)/2; _coords.set(sphereOrigin.x + dir.x*t0, sphereOrigin.y + dir.y*t0, sphereOrigin.z + dir.z*t0); } } I hope that was clear enough, Thanks for any help
Advertisement
determine the barycentric coordinates of the intersection point relative to the three vertices of the face that you interected with, and use this to get the weighted average of the UV coordinates defined at those vertices

This topic is closed to new replies.

Advertisement