You are not logged in.
Lost Password?


Register To Post



 Bottom   Previous Topic   Next Topic

#1
Affine Mode Question
Posted on: 2009/3/24 14:10
Administrator
Joined 2000/1/8
Germany
2511 Posts
Highscore Top10Highscore Top ScoreCoder#1 PosterHOTY09 1stLong Time User (15 Years) App Coder90+ Game Ratings
I am trying to get Affine Mode working for a new game project, but I am having some problems with it. I want to "tilt" an image into the screen, as seen on the attached mock-up. I have the param table and world header correctly set up and i can use the affine_fast_scale() function from David Tucker's Affine Demos. But when I try to use the Affine functions found included in the vbJAEngine, I don't get any results rendered on the screen. So, how do I call, for example, affineRotateZ() correctly to achieve the desired results? Below is my code and the Affine function:

Quote:

u16* const param = (u16*)0x0003C000;

copymem((void*)CharSeg0, (void*)CHTEST, 512*16);
copymem((void*)BGMap(0), (void*)BGTEST, 512*16);

WORLD_HEAD(31, WRLD_ON | WRLD_AFFINE | WRLD_OVR);
WORLD_MSET(31, 0, 0, 0);
WORLD_GSET(31, 0, 0, 0);
WORLD_SIZE(31, 384, 224);
WORLD_PARAM(31, (u32)param);
WORLD_OVER(31, 0x90);

WORLD_HEAD(30, WRLD_END);

affineRotateZ(31, ITOFIX7_9(1), ITOFIX7_9(1), 384, 224, 0, 0, 45);


Quote:

void affineRotateZ(u16 param, fix7_9 zoomX, fix7_9 zoomY, s16 bg_x, s16 bg_y, s16 fg_x, s16 fg_y, int alpha)
{
--PDx_ST pdx;--

--CACHE_ENABLE;

--
--if(zoomX < 0)
--{--
----fg_x *= (-1);
--}

--pdx.pa = FIX7_9_DIV(COS(alpha), zoomX);
--pdx.pb = FIX7_9TOFIX13_3(FIX7_9_DIV(SIN(alpha), zoomY));
--pdx.pc = FIX7_9_DIV(SIN(alpha), zoomY);
--pdx.pd = abs(FIX7_9TOFIX13_3(pdx.pa));
--
--pdx.dx = ITOFIX13_3(bg_x - (FIX7_9TOI(pdx.pa) * fg_x + FIX13_3TOI(pdx.pb) * fg_y));
--pdx.dy = ITOFIX13_3(bg_y - (FIX7_9TOI(pdx.pc) * fg_x + FIX13_3TOI(pdx.pd) * fg_y));


--pdx.paralax = 0x0000;
--
--{--
----AFFINE_ST *affine = (AFFINE_ST*)PARAM(param);
--
----AFFINE_ST source = {
--------pdx.dx,
--------pdx.paralax,
--------pdx.dy,
--------pdx.pa,
--------pdx.pc
--------
----};

----int i = FIX7_9TOI(FIX7_9_MULT(ITOFIX7_9(fg_y << 1), zoomY)) + 2;
----
----affine[0] = source;
----
----for (; --i; )
----{
------fix13_3 iFix = ITOFIX13_3(i);------
------source.pb_y = FIX13_3_MULT(iFix, pdx.pb) + pdx.dx;
------source.pd_y = FIX13_3_MULT(iFix, pdx.pd) + pdx.dy;
------affine[i] = source;
----}
--}
--CACHE_DISABLE;
}

Attach file:



png  affine.png (28.55 KB)
1_49c8dac87a16e.png 386X520 px
Top

#2
Re: Affine Mode Question
Posted on: 2009/3/25 0:50
PVB Elite
Joined 2003/7/26
USA
1464 Posts
PVBCC EntryCoderContributorSpecial AchievementTop10 PosterHOTY09 EntryLong Time User (15 Years) App Coder20+ Game RatingsPVBCC 2013 Entry
Try setting param to 0xE000:


u16
* const param = (u16*)0x0000E000;


Also,


I think the first parameter of affineRotateZ is supposed to be the address of the parameter table, not the number of the world.


affineRotateZ
(paramITOFIX7_9(1), ITOFIX7_9(1), 3842240045);


But, since the param address stored in the World attributes has to be:


(addr 0x00020000) >> 1


where "addr" is the address in VB space, and since I don't know what Jorge's PARAM macro does, you might have to tweak those. But, I'm pretty sure it's the address of the table that's at fault.

Also, is it really "rotateZ" that you want? Your mockup looks more like a rotate around the X axis...

EDIT: Turns out it's actually the libgccvb PARAM macro and all it does is mask a value and add it to the base of the parameter table. So, basically, affineRotateZ wants the actual param table address, but the World attributes want the one as calculated above.

So just...


//...change:

WORLD_PARAM(31, (u32)param);

// to:
WORLD_PARAM(31, (u32)((param 0x00020000) >> 1));


and the call to affineRotateZ and that should work.
Edited by RunnerPack on 2009/3/25 1:07
Edited by RunnerPack on 2009/3/25 1:09
Edited by RunnerPack on 2009/3/25 1:12
Top

#3
Re: Affine Mode Question
Posted on: 2009/3/25 15:09
Nintendoid!
Joined 2006/3/15
Ecuador
229 Posts
PVBCC 3rdCoderLong Time User (13 Years)
Hi Krisse, If I recall correctly, there are some affine functions which are not complete or don't work as I expected, but I got bored and didn't take the time to polish them, so that could be the problem :-).

jorgeche
Top

#4
Re: Affine Mode Question
Posted on: 2009/3/26 14:29
Administrator
Joined 2000/1/8
Germany
2511 Posts
Highscore Top10Highscore Top ScoreCoder#1 PosterHOTY09 1stLong Time User (15 Years) App Coder90+ Game Ratings
Thanks RunnerPack! It still does not work, so it looks like this function is incomplete. I want a rotation around the X axis, yeah, but sadly there's no function for that. :(

Jorge, is there a chance that you look at your functions again? :)
Or would it be possible to generate a parameter table for an image rotated 45° around the x axis by hand?
Top

#5
Re: Affine Mode Question
Posted on: 2009/3/26 15:14
PVB Elite
Joined 2003/7/25
USA
1507 Posts
PVBCC 1stCoderContributor#3 PosterHOTY09 EntryLong Time User (15 Years) App CoderPVBCC 2010 EntryPVBCC 2013 Entry
Are you looking to do something like the view in Mario Kart (except just on an image)? I optimized my function a bunch, but David has a demo posted on his site that had that perspective (affine demo 2 in: http://www.goliathindustries.com/vb/download/affine_demos.zip ). IIRC, the main thing you need to do is divide pa and pd by the pdx loop counter. I don't have time to look at it right now, but if I get a sec, I'll try to help out if you still need it.

DogP
Top

#6
Re: Affine Mode Question
Posted on: 2009/3/26 16:15
Administrator
Joined 2000/1/8
Germany
2511 Posts
Highscore Top10Highscore Top ScoreCoder#1 PosterHOTY09 1stLong Time User (15 Years) App Coder90+ Game Ratings
Yup, that's about what I want to do. Attached is a mockup of the game I was thinking of: 3D Blockout! I assume that, once a World is Affine transformed, I can change it in any way I want without losing the transformation?

I looked at David's demos but couldn't get the right transformation working.

Attach file:



png  test.png (5.28 KB)
1_49cb9bfe883a2.png 384X224 px
Top

#7
Re: Affine Mode Question
Posted on: 2009/3/27 5:20
PVB Elite
Joined 2003/7/26
USA
1464 Posts
PVBCC EntryCoderContributorSpecial AchievementTop10 PosterHOTY09 EntryLong Time User (15 Years) App Coder20+ Game RatingsPVBCC 2013 Entry
I know very little about the math involved in affine transforms. But, if you could do without the perspective "fore-shortening" effect, you could do the same thing with just the h-bias mode. I've done a "tiled sidewalk" that way, and it looks fairly decent. You could even simulate the perspective part by designing your bgmaps/sprites correctly, but that would probably be more work than using affine...

Blockout looks cool, but I would like to see support for the SNES mouse or maybe custom spinner hardware
Top

#8
Re: Affine Mode Question
Posted on: 2009/3/27 5:48
PVB Elite
Joined 2003/7/25
USA
1507 Posts
PVBCC 1stCoderContributor#3 PosterHOTY09 EntryLong Time User (15 Years) App CoderPVBCC 2010 EntryPVBCC 2013 Entry
Yeah, that's definitely doable, assuming you're actually modifying the BGMap. The problem that I ran across in Mario Kart is placing other objects on the screen that line up with the rendered BGMap, but not flat on the BGMap (ie karts upright, while track is laying down). Of course even that'd be easy if you have a static image like that, and aren't rotating the playfield. Lemme see if I can throw something together for you.

DogP
Top

#9
Re: Affine Mode Question
Posted on: 2009/3/27 6:51
PVB Elite
Joined 2003/7/25
USA
1507 Posts
PVBCC 1stCoderContributor#3 PosterHOTY09 EntryLong Time User (15 Years) App CoderPVBCC 2010 EntryPVBCC 2013 Entry
Alright... is this what you're trying to do (Up/Down adjust the tilt)? I quickly hacked this together from DT's demos: http://home.comcast.net/~virtual.boy/VB/affine_demo_k.zip . I basically combined the affine_set_all function with the affine_scale function, so I could have it generate a different scale for each line (determined by the loop counter). Of course it's far from optimal, since it still uses floating point and has redundant code/unnecessary intermediate variables, but that should get you started.

DogP
Top

#10
Re: Affine Mode Question
Posted on: 2009/3/27 11:57
Administrator
Joined 2000/1/8
Germany
2511 Posts
Highscore Top10Highscore Top ScoreCoder#1 PosterHOTY09 1stLong Time User (15 Years) App Coder90+ Game Ratings
Awesome, that looks perfect! I will get into it next week. Thanks Pat! :)
Top

 Top   Previous Topic   Next Topic


Register To Post