Vitenka: 1511
I made this / Cat Games - Less lag, more 'thats bad'
[vitenkas.morat.net]
/ MORAT / freespace / Catnews / Editorial
There's nothing to see here except for shadows of the past - and these ones won't be returning.

I'd point you to my next project here - but I'm not that organised. My style is to act and then sort out the consequences, rather than the other way around. Oh, and lying. I do that a lot too. (i.e. if you look closely, you may have seen some links appearing roughly once a week)

Vitenka.com is registered to me for the forseeable future, so you might find something there.

Edited by Vitenka at 2003-04-09 08:22:54

 
Vitenka : Fri 23 02:17:27 2001  
Crystal space, Object space, World space, View-space, Camera space, this space that space and the flippin other space.

I admit it, I'm not good with spaces

I just spent most of today playing around with my nice little demo app. It's got a little spaceship model in it, and some lights, and I wanted to be able to play around with it.

It moves!

So, I thought it'd be nifty to be able to move my little model around a bit. We've already got code for moving the camera around, so it can't be that hard to copy, right?

My first attempt was to use the 'Move' function. Turns out that 'iMeshWrapper' (which is what my spaceship is held as) doesn't have that function. So we dive into the API.

Nothing looks promising, until I notice that iMeshWrapper also implements iMovable. Movable, that sounds good, we want it to move, right?

And yes indeedy, things look good. iMovable gives us the 'SetPosition' and the 'MovePosition' methods. Lubbly.

It's just a minutes work to make the spaceship slide around inside the box - after reassuring my fears that I might have to refer to every key with big CSKEY_BLAHBLAH names, and that I can, in fact, just use 'a' 'b' etc.

Wheee. Slidy spaceship. I can make it go towards the top of the room, or the floor - look around it from any direction... and, if I remember to use the DeferUpdateLighting() call - it even gets the right coloured lighting effects. Call cranky-Joe, I've made a quake-2!

It spins!

Next up, making it rotate. Shouldn't be terribly hard, again - I've got the code the camera uses...

Now, the camera does GetTransform() then RotateThis() - iMeshWrapper doesn't do 'GetTransform' - but iMovable does... just a bit of a hunch and...

mySprite->GetMovable()->GetTransform ().RotateThis ( csVector (1,0,0) , speed );

It works. Takes me a bit longer playing around with the rotations to work out which vector means 'up' and which means 'left' - and whether it should be positive or negative. Not terrible, I probably should have used those names the camera used, but I like to figure stuff out. So I get it mapped out pretty similar to my descent config, and I can point my little spaceship any which way.

Actually, I'll let you in on a little secret, I didn't do it all step-by-step like this, I played around and did this AND the next bit at about the same time. Playing about is the best way to learn what things do.

Relative Movement

Ok, it looks a bit odd having my spaceship fly sideways. Descent notwithstanding, it's only supposed to have engines on the back. And here we hit a problem.

I want the sprite to move relative to its own base vectors. If it's pointing left, then 'forward' should mean left. And yick does it take me a while to figure out how to tell crystal-space that.

In fact, it takes me back to remembering how matrix operations work - what a base vector is, and which is 'this' and which is 'other'

I won't bore you with all my dead end thinking (using the actual rows was bad...) and get on to the description.

See the GetTransform returns something that is basically a matrix that tells you how to get from 'world' space to 'other' space, which is space from the sprites point of view.

Then all you need to do is put 'forward' through that transformation, so that it becomes 'world-forward from the sprites point of view' and then move the sprite about with it.

And actually, I've just described the whole thing backwards. Because what we WANT is 'sprite-forward from the objects point of view' turned into 'some random direction from the worlds point of view'

So, the function we want is 'This2Other' - and there's another dead end. Unless the sprite is sat at the origin (0,0,0 in the world) then from its point of view 'forward' starts a long way away, and that displacement becomes the main thing in its move. That would be bad, so we want to pretend that the object IS at the origin briefly. This2OtherRelative() is what we want.

mySprite->GetMovable()->MovePosition (
mySprite->GetMovable()->GetTransform().This2OtherRelative (
csVector ( 0,1,0 ) * speed ) );

Homework

Right, as an excercise for the reader, see if you can make it move relative to the camera - don't worry about moving further if it's further away - just get it to go in the right direction.

Reference

Here's my version of this - Enjoy my little spaceship thingy!

Edited by Vitenka at 2001-11-23 14:21:55

Older News  
Main News>>>
[M]
[Haiku]

[Rifle]
[MORAT]
[Fa-Teen]

 
[Froody Comics]



[Nifty Links]
[Editorials]
[Guilt Box]
You owe:
00:03
 
['Tenkas Tips]

This HTML design by Vitenka
I'm aware it sucks, but am also too lazy.
Note that now you've changed all the colours, it could be about anything!
BTW - this site looks fine in IE5 and netscape4. If you have a problem, if no one else can help, and if you can find it, maybe you can use - Netscape 2.