Archive: "LookAt" function for 3d camera.


13th July 2004 04:01 UTC

"LookAt" function for 3d camera.
I'm working on a 3d flower-type thingy for the AVS right now, and I'm about to implement camera movement and rotation(right now it's just static). Well, first off, you can find it here:
http://www.lggaming.com/user/xerol/a...rumflower2.zip
Now, I know how to point the camera and all, but I'm having trouble figuring out how to get those rotation angles so that the camera is always looking at a certain point(or any point, actually).

The other thing I'm having trouble with, and this is more of a brain-freeze issue than anything else, but I'm trying to figure out a good way to make the camera move. Once I've got the LookAt function in place, I don't know what I'm going to do with my camera. I could always just have it rotate around the flower, but that'd just be boring. Any suggestions on what I could do with my camera?


13th July 2004 08:46 UTC

extremely good start at the concept of coding, but frankly you need to get a better handle on the aesthetic aspects. first of all, the slow incrementation of the number of "petals" is a bad idea - soon enough you'll end with something that is really messy and not very nice to look at. the color scheme isn't my cup of tea either...and speaking of colors, in a scope like this, you should fade things out according to depth and use a max render mode.
i'd usually say for beginners that a camera motion for this type of scope is out of their reach, but i'm not sure that's true for you...are you familiar with rotation matrices?
x'=x*cos(theta)+y*sin(theta)
y'=x*sin(theta)-y*cos(theta)
this will provide you with a simple way of pointing the camera at the origin from any point on the unit sphere, and then you can deal with translation/scaling. algorithms for pointing the camera at a certain point with yaw/pitch/roll are more complicated than most choose to deal with (certainly not i), but if you want to get involved with that on your own you can...
good stuff though, just keep a mind for the aesthetic side of things


13th July 2004 15:46 UTC

It's really a lot easier if you switch your model around. Right now you just rotate the superscope around its center point, like it was dangling in a fixed position in front of the camera.

For synching 3D scopes and DMs, I use a model where the scopes are in a fixed position, and the camera moves through them. The trick is for the scope to translate before rotating, and to apply the rotations in reverse order.

Anyway for look-at code with euler angles, just use two atan2's (arctangent with correct quadrant) and pythagoras' theorem. It's been explained elsewhere too.

When looking at a point, one of the rotation angles (most likely z, depends on how you order them) can still be changed as much as you like.

The preset is really not my cup of tea: it's just a basic spectrum on a shape. Also, your usage of replace blend mode makes the back appear over the front. You can switch to additive or maximum, or you can try one of many tricks to make it look correct.

Oh and you need to fix the aspect ratio by multiplying y by w/h at the end (easiest method). Otherwise your scope looks squished in rectangular windows.


14th July 2004 04:23 UTC

It's really a lot easier if you switch your model around. Right now you just rotate the superscope around its center point, like it was dangling in a fixed position in front of the camera.
That's because I am just dangling the model in front of the camera. It has its own rotation about it's origin, if you were looking from top-down it would be rotating clockwise. I do have a very firm grasp on how to do 3d camera, I did make one of the first mostly-functional 3d engines in QBasic. (http://www.lggaming.com/user/xerol/bridge5f.jpg <--entirely rendered in QB. What I actually did with that was render to a bitmap file, so that's how I was able to get the high resolution, but all of the real work was done in the program.)

Anyway, in the comments section I stuck in there, it shows how the camera's going to be implemented, and basically what this does is rotate the points about the camera, which is essentially moving/rotating the model.

I don't know much about render modes, but I see what you mean. When I was doing my previous work I programmed in a zbuffer but I dont think that's going to work here(too slow). However, in fullscreen the lines are spread out enough to give it a 'transparent' feel, although that's not the case in lower resolutions.

Are there any effects that can give an anti-aliasing feel? I tried using blur(too much), a zero-movement roto blitter(too slow), and an expressionless Trans/Movement with Blend on(too slow/too much).

I did some changes to it today, used a trans/movement on it and turned it into a 'fireflower' of sorts. Here's the new version: http://www.lggaming.com/user/xerol/a...zingflower.zip

The lightsources now move around in this, with the Blue and Green always being opposite each other(they give a drab grey appearance when they appear next to each other) and circling the origin, while the red one just moves up and down the z-axis. The Movement and Fadeout combine to make it look like it's giving off blue smoke, and the speed varies greatly depending on how 'active' the music is, due to a few changes in the superscope. I also changed it to all dots.

For some reason, though, the blue and green lightsources aren't acting like they should. Here's the equations:

cgx=cos(t3)*colr;
cgy=sin(t3)*colr;

cbx=cos(t3+$PI)*colr;
cby=sin(t3+$PI)*colr;


colr is the radius of the blue and green lightsources; t3 is a number increasing by .004 on each Frame. cgx, cgy are X and Y coordinates of green lightsource, cbx & cby are for the blue. However, there only seems to be one of the two lightsources active at a time(set rb to 0 in the Init box of the superscope and disable the movement & fadeout, and you'll see what I mean). Depsite the fact that i'm keeping them Pi radians apart, it seems like they're just right next to each other and switching intensities(although i know that can't be true, since bb and gb are staying at 5 the whole time). I might've just made a mistake here, but I can't find it.