FORUMS TUTORIALS FEATURES VIDEOS PODCASTS EVENTS SERVICES NEWSLETTER NEWS BLOGS
 MAYA: MAYA Forum MAYA Tutorials MAYA

# Re: Sprites, Camera Rotations, and Images: aka Fake 3D

COW Forums : MAYA

 Re: Sprites, Camera Rotations, and Images: aka Fake 3Dby Steve on Feb 14, 2003 at 7:46:49 am

Ah, Clear, you know I can't resist a good challenge. :)

Make some particles, set them to Numeric type, add Numeric attributes, and change 'attributeName' from 'particleId' to 'mass'.

Now try this as a runtime expression:

// Get the camera's position, save it to a vector.
float \$camPosX = persp.translateX;
float \$camPosY = persp.translateY;
float \$camPosZ = persp.translateZ;
vector \$camPos = <<\$camPosX, \$camPosY, \$camPosZ>>;

// Now subtract the particle's position to find the
// vector separating the two.
vector \$toCamera = \$camPos - particleShape1.position;

// Now find the horizontal angle between them.
// The atan2d function will by default return a value
// from -180 to 180. We prefer 0 to 360, so convert:
float \$angleH = atan2d(\$toCamera.x, \$toCamera.z);
if (\$angleH < 0)
\$angleH = \$angleH + 360;

// Now we do the same with the vertical angle. First
// we need the horizontal distance between camera and
// particle. Pythagoras gets that for us, and as a
// bonus (it's always positive) prevents the result
// from going outside of the 0-180 range we're looking
// for.
float \$distanceH = `hypot (\$toCamera.x) (\$toCamera.z)`;
float \$angleV = atan2d(\$distanceH, \$toCamera.y);

// This last section is for illustration ONLY: you
// won't use this in your real expression. What this
// does is map the horizontal angle to the whole number
// of the particle's mass, and map the vertical angle
// to the decimal. For your real setup, you'll want to
// sum them (probably) and map them to the image
// extension attribute of your sprite particle object.
particleShape1.mass = trunc(\$angleH) + (\$angleV / 1000);

Run that bugger, and you should get the results you're looking for. For the clearest illustration, focus on one particle and tumble the camera around it.

Hope this is what you were looking for. Good luck!

-Steve