Hey Bat, that's a very good solution, I never even thought of doing stuff "out-of-view" like that. Hmm..you could have the camera set to the same view in relation to a plane (so that plane is always in the full view of the camera). It would not become part of the final shadow image, but just used for reference in placing the pin for a snapshot. But the way I was thinking would be to have just 1 extra pin (grey, like you said), and position that in the same orientation as the current pin you're checking, and snap a picture (grab an image) for the shadow. But I believe that would mean either:
a.) grabbing 10 images, once per frame (ouch?)
or
b.) having 10 seperate cameras, one for each pin? Though intriguing, i'm not sure it's possible (10 cameras). Too bad though, because "Set Camera To Image" works much better than trying to grab images...
Of the two, I'd like to think I could get something working with the b. method because it seems like that could work. You did manage to hit on an idea I hadn't considered yet though, so points for that...good job.
But I think you'll find this method even more efficient. And this will apply to any DB project, so any DB'ers who miss this thread will be missing a very effective technique:
There are only 2 drawbacks: This method can only work on any kind of cylindrically shaped object. It has to be possible to turn the shape on a lathe, no protrusions. And the other is that it can only work on 1 plane, it cannot follow contours (since the shadow objects are planes, after all). Other than that, you can have perfect-looking shadows, very efficiently. If there are contours to the scene, then you have to use image-hiding and Z techniqes to mask out the over-spill of shadows where you don't want them to show, like I've done in the Bowling program. (Unless people know other tricks...). But, there are definitely situations where it could be used extensively, I'm thinking something like 2D games, or some kind of action-puzzle game where all the gameplay takes place on 1 plane...this technique would be perfect for it. So on to the procedure...
I can give most of it away by mentioning 1 phrase: remember I said the object HAS to be cylindrical? ....
...
...
...
...
Pre-rendered shadows.
I have a series of 30 images, rendered from Lightwave, from a top view of a pin rotating from vertical to horizontal. The pin is colored completely black, but it affects the alpha channel. What I end up with is 30 TGA's of each of the frames from staning straight up to laying completely horizontally. You can imaging the 1st frame is pretty much just a circle, as it's the straight-down view of the pin at 90 degrees. Next frame, you start to see a little bit of the head in the shadow. Next frame, the head is showing a bit more "out" in the shadow...next, next, next...until you reach the last frame which just looks like a silhouette of a pin from the side (this is when it's at its maximum length). This is the shadow for the pin at its various stages of falling over. I mentioned before this technique works for a light that is overhead, but more on that later...
So you can see that these frames represent the shadow as it would be in its various stages of the pin rotating to horizontal. Good, but it has to be applied to the shadow plane rather specifically, or that is, the shadow plane has to be handled very carefully:
It starts out as a plane that is the same width and height of a pin, like a bounding box except that it's a plane (it matches the width and height dimensions of a pin exactly). It also starts out laying flat on the ground (like a shadow), and facing the Z axis so that it can be pointed correctly. Also, its axis is at the very end of the plane, not centered. Think of it as the origin of the shadow, and the shadow extends out from it (like a real shadow). Of course, this origin is placed at the object's location.
Now that the shadow plane is placed comes the more complicated part. The plane has to extend in the direction that the object is leaning. Think again of the pin going from vertical to horizontal. If the pin is standing vertically, then the plane (which begins as the full length of a pin) is too long...it should be more (or exactly) like a square. Remember, the light source is directly overhead. And for the pin laying horizontally, the shadow would be at its full length (size). So not only does the shadow plane need to point in the direction of the object, it has to change size to match the length of the shadow created by the pin. If you picture it directly from the side (the point falling to the right, for example), and imagine the 'straight down light', you can see how the shadow's length would change. Then, instead of the pin falling exactly right, imagine it falling to the right, but a bit away from you, toward the back. This is where the pointing comes in, because the plane has to go in the direction of the object to match. Both are important, the point AND the scaling. And remember about having to be cylindrical? It's funny, by being cylindrical, you effectively remove an axis that has to accounted for in the shadow: the width. The width will never change depending on the light, only the length.
So after come complicated calculations, the plane is pointing correctly, and is sized correctly (length), but it's still in the position of the axis on the object. Think of the pin standing straight up again. We've got the shadow plane scaled to square, and pointing (though it doesn't really matter for this 'frame' of the shadow since it's square {a round shadow, that is} ). But, the shadow is beginning from the center of the object; it needs to be placed a bit further back from where it started, as in, a round shadow underneath a pin standing up. You might think the adjustment to pull it back would come from the width,like I did, but it doesn't....it comes from the method for pointing the shadow:
To determine where to point the shadow (and ultimately which frame of the shadow to use), we need to know which direction the pin is leaned in. You could try to determine this with all kinds of complicated angle calculations, but there is an easier way. Say hello to the "pinbob". It's a small sphere (hidden) that is located
like this:
1.)Place at object's position
2.)Orient to same as object.
3.)Move Object pinbob,dist#.
dist# is the length of the object's positive Y axis. Since the pinbob was oriented in the same direction as the object, what we end up with is the pinbob located at very extents of the pin at the head, whichever way and in whichever direction the pin may be leaning (whether towards or away from you, to the sides, or anywhere in-between). The pinbob is a very important reference locator device, a 'helper', if you will.
The pin bob gives you the direction to point the shadow plane: Point Object shadowOBJ(1),Object Position X(pinbob), .1,Object Position Z(pinbob). The shadow plane was placed at Object Position X(pin(1)), .1,Object Position Z(pin(1)), [[ both .1 on the Y]], so it points to the same height and doesn't become tilted. So now it's pointing correctly, how about the scaling?
There is a maximum distance that the pinbob can ever be away from the pin itself, and that is the full length of pin's positive axis when the pin is laying exactly horizontally. When the pin is standing straight up, then the pinbob's difference is 0. When the pin reaches horizontal, the pin bob is at its maximum difference. Both the image to use (1-30) for the shadow, and the scale (length) of the shadow are determined from the pinbob difference. Obviously a pinbob difference of 0 means the 1st frame (straight up), and the maximum pinbob difference (horizontal) would mean the last frame of the shadows (the longest). The scale and image number of the shadow plane are derived as percentages of the whole, depending on the position of the pinbob in relation to the object's axis.
And the final step, how much to pull the shadow back from the object's axis. Imagine the laying straight horizontal again. The shadow is scaled to the correct length and pointing toward the head, but is begining from the origin of the object, which somewhere around the geometric center of the object. But how much to pull it back? You need the negative axis length of the object, too. So for the horizontal pin, it would need to come back its maximum distance, to match the location of the flat bottom surface of the pin. This is the negative axis. The shadow plane is pulled back on the same percentage scale coming from the pinbob, except that what you're percent-agizing is the negative axis, to know how much to pull the shadow back from the origin. And except that whatever value you get, you need to use the negative of it (pulling back) : Move Object shadowOBJ(1),-(dist#).
And the image to use for the shadow is determined by percentage too, except INT(), on a range of 1-30, since I know I have 30 frames of shadow animation. 0% of pinbob/the maximum = frame 1 (first). 100% of pinbob/the maximum = frame 30 (last). And anywhere in between. You determine how much fidelity you want in your shadows representation by how many frames you decide to have, and it can be any number, doesn't need to be powers of 2 or anything...you could have 47 frames of shadow animation if you wanted. I have 30 frames and it's just about as good as it needs to be. There is only a very slight noticeable jump in frame images for the shadow when the pin is just starting to fall over. There is where is some of the greatest change in the images, so you might see the shadow image change frame if you're close enough with the camera. But it's extremely slight. I'd bet 40 frames would be silky smooth with the minimum number of images required, but I haven't tried that yet. The 30 looks fine.
The frames images range from 8k big at the smallest, and the largest is 17k! All they are is black images with an alpha channel; very small. But they are pretty large, for your reference, my frame #30 is 474x147, and frame 1 is 134x136. Yes, I have to get these images scaled correctly, because DB is having to scale them internally to use them. But these sizes allow for fine detail. You don't really see any pixelization because the images are large enough (and alpha smooth) that they can be viewed much closer than would ever need be, and still allow for clarity (defined edges and not pixely).
So then it's: Texture Object shadowOBJ(1),shadowFrame and Set Alpha Mapping ON shadowOBJ(1),50. You have to call Alpha Mapping every time you re-texture an object, so that's a bit of an extra step, but oh well. And there it's done. What you get is shadows that you can draw yourself, and can also be variable (with degrees of Alpha Mapping) depending on the lights for your scene and how dark you want your shadows.
It's an excellent method, but I've been thinking of it even futher:
Of course it works for a sphere as well, but there's really no need because the shadow would always be a square plane. Or would it? Remember how the light for these shadows is always directly overhead, so that a shadow is projected straight downward onto the floor? Well, what if (looking from the side), you moved that light a little bit to the side...the shadow would stretch in the light, just as it did when the light was directly overhead and the pin was rotating. In other words, the images for the shadows all stay the same...it depends on the light position as to which image to use. So the challenge is....:
What would the considerations be in making the shadows if the light could be anywhere and not just directly over head? The height of the light in relation to the object would affect it, but another effect would come into play: the movement, or placement, of the shadow, would change in relation of the light's position to the object's. I.E: Pin laying horizontally (looking from the side view), but the light position is between the pin and the camera. It would make the same side-laying shadow image, but its position is 'skewed' (instead of being directly underneath the pin), and now the width scale would have to start coming into play.
You can see, the images for this scenario would still remain valid, just that their positioning and scale(s) would need extra consideration for a light that could be anywhere (and have the shadows react properly). I haven't worked it out, but through from pretty fancy figuring, one could figure out a way to make the shadows work for the actual lights in the scene instead of an assumed overhead light...If anyone figures it out (before me), then I'd save some time, though that is not high on the light of priorities for the game. But as a curiosity, and because it is in fact more accurate to the real world, I'd eventually want to look into it...
http://www.geocities.com/crmnlelmnt/