Nicht eingeloggt.
Passwort vergessen?


Bitte erst registrieren. Danach ist es möglich Beiträge zu schreiben.



 Nach unten   Vorheriges Thema   Nächstes Thema

#1
Affine Mode Question
Geschrieben am: 24.03.2009 14:10
Administrator
Dabei seit 08.01.2000
Deutschland
2515 Beiträge
Highscore Top10Highscore Top ScoreHOTY09 1stLong Time User (15 Years)
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:

Zitat:

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);


Zitat:

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;
}

Datei anhängen:



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

#2
Re: Affine Mode Question
Geschrieben am: 25.03.2009 0:50
PVB Elite
Dabei seit 26.07.2003
USA
1464 Beiträge
PVBCC EntryContributorSpecial AchievementHOTY09 EntryLong Time User (15 Years) PVBCC 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.
Bearbeitet von RunnerPack am 25.03.2009 1:07:35
Bearbeitet von RunnerPack am 25.03.2009 1:09:12
Bearbeitet von RunnerPack am 25.03.2009 1:12:18
Nach oben

#3
Re: Affine Mode Question
Geschrieben am: 25.03.2009 15:09
Nintendoid!
Dabei seit 15.03.2006
Ecuador
233 Beiträge
PVBCC 3rdLong 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
Nach oben

#4
Re: Affine Mode Question
Geschrieben am: 26.03.2009 14:29
Administrator
Dabei seit 08.01.2000
Deutschland
2515 Beiträge
Highscore Top10Highscore Top ScoreHOTY09 1stLong Time User (15 Years)
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?
Nach oben

#5
Re: Affine Mode Question
Geschrieben am: 26.03.2009 15:14
PVB Elite
Dabei seit 25.07.2003
USA
1507 Beiträge
PVBCC 1stContributorHOTY09 EntryLong Time User (15 Years) PVBCC 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
Nach oben

#6
Re: Affine Mode Question
Geschrieben am: 26.03.2009 16:15
Administrator
Dabei seit 08.01.2000
Deutschland
2515 Beiträge
Highscore Top10Highscore Top ScoreHOTY09 1stLong Time User (15 Years)
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.

Datei anhängen:



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

#7
Re: Affine Mode Question
Geschrieben am: 27.03.2009 5:20
PVB Elite
Dabei seit 26.07.2003
USA
1464 Beiträge
PVBCC EntryContributorSpecial AchievementHOTY09 EntryLong Time User (15 Years) PVBCC 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
Nach oben

#8
Re: Affine Mode Question
Geschrieben am: 27.03.2009 5:48
PVB Elite
Dabei seit 25.07.2003
USA
1507 Beiträge
PVBCC 1stContributorHOTY09 EntryLong Time User (15 Years) PVBCC 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
Nach oben

#9
Re: Affine Mode Question
Geschrieben am: 27.03.2009 6:51
PVB Elite
Dabei seit 25.07.2003
USA
1507 Beiträge
PVBCC 1stContributorHOTY09 EntryLong Time User (15 Years) PVBCC 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
Nach oben

#10
Re: Affine Mode Question
Geschrieben am: 27.03.2009 11:57
Administrator
Dabei seit 08.01.2000
Deutschland
2515 Beiträge
Highscore Top10Highscore Top ScoreHOTY09 1stLong Time User (15 Years)
Awesome, that looks perfect! I will get into it next week. Thanks Pat! :)
Nach oben

 Nach oben   Vorheriges Thema   Nächstes Thema


Bitte erst registrieren. Danach ist es möglich Beiträge zu schreiben.