DIV ARENA FORUMS

Complicated mode 8 question...

BreadCaster - 21-11-2016 at 01:04 AM

Hi all you gals n pals :D

So I've been getting a little carried away in mode 8... again.

I initially programmed something called "Basic Mode 8 Viewer" which was essentially just a way to walk around a mode 8 world with standard modern day FPS sort of functions - mouse look, run, walk, jump and crouch, as well as footstep sound effects and automatically stepping up and down steps.

However, since then, it's grown a little bit - I'm now making a full suite of processes to flesh out a mode 8 world. Invisible walls, automatically opening doors, wall switches that can be tied to other processes, lifts, raising and lowering bars, horizontally sliding doors and even an extending bridge to get you across a large gap between two sectors. (They're all tied to processes, so provided you have the information you need - for example, which sectors will be used to trigger an automatic door, which sector will be the door, and how far the door should go up - then you can just call the process and it'll sit in the background, managing that one door. :) ) Through all these, I'm now rather confident with Set_point_m8.

However, there's one thing which I'd really like to do, but I have NO idea how to go about doing it, and it's not because of set_point_m8. Basically, I want to see if I can be able to make a swinging open door, using set_point_m8, in mode 8. I really just have... no idea where to begin.

I included a diagram to show you what I mean - I know that only three of the four points of the sector would have to move, but that's literally all I know. I don't have even the slightest idea how I'd calculate the arc and all that, or how I'd somehow plot it in DivDX - not exactly a maths person here :p

If anyone could help out with some advice, that'd be fantastic! I'd really like to add this feature in, in the future I may give out all these as code snippets in the subforum so anyone can make their own awesome mode 8 worlds :D


- BC



[Edited on 21-11-2016 by BreadCaster]

curvequestion.png - 16kB

Peter - 21-11-2016 at 10:35 AM

Have you thought about using sliding doors instead of revolving doors?

If you use revolving doors, you have to take into account the space that is needed for the player if he/she is standing on the other side of the door. I'm referring to the blue area in the first picture. (That's assuming the door only rotates one way, and not both ways. (see the diagram for this)

If you decide on using sliding doors, then you have two options (see diagram, second & third picture)
picture 2) a door that consists of one piece that slides back and forth (think Star Trek)

OR

picture 3) a door that consists of two pieces that slide back and forth.... away from & to each other.

However if you really really really want to use revolving doors, I may have some code lying around. I'll do my best to track it down, it may take some time though :sniffle: . Ok?



Doors.png - 7kB

Peter - 21-11-2016 at 11:13 AM

Yo,

Just had an idea...

Can't you just...
1) place a pivot at the base of the door and
2) parent the points of the doors to that process (using father... son... )

This way you only have to rotate the pivot and not the door.

I'll keep looking btw. :smilegrin:

BreadCaster - 21-11-2016 at 09:11 PM

Quote: Originally posted by Peter  
Yo,

Just had an idea...

Can't you just...
1) place a pivot at the base of the door and
2) parent the points of the doors to that process (using father... son... )

This way you only have to rotate the pivot and not the door.

I'll keep looking btw. :smilegrin:


Thank you PEader!! Yeah I'd like that very much - provided you can explain how it basically works so I'm not just fumbling around with it haha :)

I don't understand what you mean about a "pivot" - do you mean a rectangular process and somehow tracking three control points in it? :S


By the way, I already have sliding doors in the program! :D You can either use two or one in conjunction to have a single sliding door or two sliding doors like in Star Trek :)

CicTec - 21-11-2016 at 11:52 PM

Hi BreadCaster,

What you need it is a formula to rotate and translare the vertices to form an opening/closing arc.

Have you tried to look at the examples of GET_DISTX and SET_POINT_M8 functions ? are very similar to each other, especially the first, if you look carefully, moving with the LEFT and RIGHT keys, the triangle turns forming arches in the background circle, and uses her as a pivot point for turning (control point 0), you should apply a similar formula for each vertex of the door to be moved using the SET_POINT_M8 function, try to do some experiments.

BreadCaster - 22-11-2016 at 02:35 PM

Quote: Originally posted by CicTec  
Hi BreadCaster,

What you need it is a formula to rotate and translare the vertices to form an opening/closing arc.

Have you tried to look at the examples of GET_DISTX and SET_POINT_M8 functions ? are very similar to each other, especially the first, if you look carefully, moving with the LEFT and RIGHT keys, the triangle turns forming arches in the background circle, and uses her as a pivot point for turning (control point 0), you should apply a similar formula for each vertex of the door to be moved using the SET_POINT_M8 function, try to do some experiments.


Hah, actually I DO remember those now... wow, it's been a long time, thanks for the reccomendation Cictec :) I'll have a look!!!

CicTec - 22-11-2016 at 04:12 PM

it is a pleasure, keep us informed of the test results etc.. :)

BreadCaster - 28-11-2016 at 07:19 PM

Hmm, I can't seem to get it working. What I'd been trying to do is get all the vertexes cordinates and put them into vert_x[0..3] and vert_y[0..3] then use set_m8_point and get_dist_x(dooropenangle, distance between two vertexes)

but all I keep getting is crashes and really long warped sectors. Guh! I can't seem to translate the get_distx example into something that changes all four vertexes of a sector...

CicTec - 28-11-2016 at 07:37 PM

You have a small example to be able to try? it would be useful to see if the formula that you want to apply it correctly, or need to add some features to engine to get this.

BreadCaster - 28-11-2016 at 08:00 PM

get_point_m8(vert_0, OFFSET vert_x[0], OFFSET vert_y[0]);
get_point_m8(vert_1, OFFSET vert_x[1], OFFSET vert_y[1]);
get_point_m8(vert_2, OFFSET vert_x[2], OFFSET vert_y[2]);
get_point_m8(vert_3, OFFSET vert_x[3], OFFSET vert_y[3]);

...

angle+=500;

pivot_x=vert_x[0]+get_distx(angle, open_speed);
pivot_y=vert_y[0]+get_disty(angle, open_speed);

set_point_m8(vert_0, vert_x[0], vert_y[0]);
set_point_m8(vert_1, vert_x[1]+pivot_x, vert_y[1]+pivot_y);
set_point_m8(vert_2, vert_x[2]+pivot_x, vert_y[2]+pivot_y);
set_point_m8(vert_3, vert_x[3]+pivot_x, vert_y[3]+pivot_y);



That's the current version, not working well. lol. Everything goes sort of black and weird like it's a huge sector, walking into it makes the game crash. I can mess around with the variables and adding pivot_x and pivot_y to all of the vertices, but then I just get a sector that gently spins in circles (not actually spinning, but moving in a circle, haha).

[Edited on 28-11-2016 by BreadCaster]

CicTec - 28-11-2016 at 09:58 PM

it is difficult to test the code without an exmple, you have a small wld + assets + prg that you can send to verify the problems ?

BreadCaster - 29-11-2016 at 01:08 AM

Okay sure, here you go! I just slapped this together for you.



Attachment: swingdoorexample.zip (1010kB)
This file has been downloaded 2998 times


CicTec - 29-11-2016 at 10:41 AM

Thanks, I shall examine it in the coming days to see possible solutions.

BreadCaster - 30-11-2016 at 04:43 PM

Thanks Cictec. I've tried playing around with it more but to no avail, the closest I can get is the door sector kind of hinging open too far one way and not enough the other way, kind of spinning in a circle again =(

dom cook - 30-11-2016 at 06:53 PM

I've just had a quick look at your code and as far as I can tell you're not doing the maths, as it were.

I don't know if it's the only way but I would use 2d rotation transformations.
For that you need the relative x and y rest co-ordinates of the points you want to rotate with respect to the axis. (dx and dy)
Then you can calculate the new coordinates relative to the rotation angle like this.

x1=x0+dx*cos(angle)+dy*sin(angle)
y1=y0+dx*sin(angle)-dy*cos(angle)


sin and cos correspond to get_dist x() and get_dist y() or the m8 versions thereof.
Beware: if you use sin/cos you need to make a correction for the fact that it will give you the value*1000:

I'm sure this will work.


[Edited on 30-11-2016 by dom cook]

BreadCaster - 30-11-2016 at 07:16 PM

Quote: Originally posted by dom cook  
I've just had a quick look at your code and as far as I can tell you're not doing the maths, as it were.

I don't know if it's the only way but I would use 2d rotation transformations.
For that you need the relative x and y rest co-ordinates of the points you want to rotate with respect to the axis. (dx and dy)
Then you can calculate the new coordinates relative to the rotation angle like this.

x1=x0+dx*cos(angle)+dy*sin(angle)
y1=y0+dx*sin(angle)-dy*cos(angle)


sin and cos correspond to get_dist x() and get_dist y() or the m8 versions thereof.
Beware: if you use sin/cos you need to make a correction for the fact that it will give you the value*1000:



Bloody hell dom, thanks a lot! I actually haven't used sin and cos since secondary school, so as far as I know sin is what goes on on a particularly good Saturday night out and COS is a high street clothing shop. :P

When you say will give the value * 1000, you mean I should simply stick a /1000 behind the formula (so it'd be x1=x0+(dx*cos(angle)+dy*sin(angle))/1000 ) ?

[Edited on 30-11-2016 by BreadCaster]

dom cook - 30-11-2016 at 07:34 PM

There you go Mister.

I've stripped down what you had and have made a struct to hold the necessary data.

Press 'e' to see the door swinging in all its glory.

Attachment: swingdoordemo.PRG (2kB)
This file has been downloaded 2979 times


BreadCaster - 30-11-2016 at 07:43 PM

Quote: Originally posted by dom cook  
There you go Mister.

I've stripped down what you had and have made a struct to hold the necessary data.

Press 'e' to see the door swinging in all its glory.


Ahhh fantastic, thanks a lot dom. I wasn't expecting this solved for me but I'm very grateful, I generally stand no chance with math problems. I'll stick your name in the credits when this demo is up and running =)

dom cook - 30-11-2016 at 07:57 PM

I couldn't resist the challenge. You seem to be having so much fun with Mode 8 that you've got me wanting to play with it too.

BreadCaster - 30-11-2016 at 07:58 PM

Quote: Originally posted by dom cook  
I couldn't resist the challenge. You seem to be having so much fun with Mode 8 that you've got me wanting to play with it too.


Well once I've finished this program here I'll send it to mike and we can all have a look at it in an online demo, hopefully :D ;)

MikeDX - 30-11-2016 at 07:59 PM

Dom is a bit of a genius when it comes to this it seems :)

dom cook - 30-11-2016 at 08:04 PM

Quote: Originally posted by MikeDX  
Dom is a bit of a genius when it comes to this it seems :)


Hardly. but thanks for the compliment.

CicTec - 30-11-2016 at 08:10 PM

Well done dom cook. :)

[Edited on 30-11-2016 by CicTec]

dom cook - 1-12-2016 at 06:02 AM

There's actually a mistake in that code.
The lines about vert(i)=vert_i; should say vert(i).v=vert_i; It doesn't seem to affect the prog but I think that's because v happens to be the first value in the vert struct so vert(i)=vert(i).v anyway. (Just in case you want to add more stuff)

(*square brackets of course)

Another thing that occurred to me was that one could probably have achieved the same results by getting the initial angle from each vert to the pivot and then rotating them by this angle plus the door angle i.e x1=get_distx(door_angle+angle0,dx); That would make the code simpler.




[Edited on 1-12-2016 by dom cook]

BreadCaster - 1-12-2016 at 10:50 AM

Can't say I see what you mean there Dom - I did search for vert[ i ]=vert_i and DivDX found nothing. I've modified the code a bit since but that's just nesting it inside other things to make a more user friendly and flexible door process, are you sure that's what you meant? Or am I a bit dense? :S

[Edited on 1-12-2016 by BreadCaster]

dom cook - 1-12-2016 at 01:32 PM

Quote: Originally posted by BreadCaster  
Can't say I see what you mean there Dom - I did search for vert[ i ]=vert_i and DivDX found nothing. I've modified the code a bit since but that's just nesting it inside other things to make a more user friendly and flexible door process, are you sure that's what you meant? Or am I a bit dense? :S

[Edited on 1-12-2016 by BreadCaster]


I was being lazy and using shorthand.
The code didn't actually say
vert[ i ]=vert_i

it said
vert[ 0 ] = vert_0;
vert[ 1 ] = vert_1;
vert[ 2 ] = vert_2;
vert[ 3 ] = vert_3;

It ought to say
vert[ 0 ].v = vert_0;
vert[ 1 ].v = vert_1;
vert[ 2 ].v = vert_2;
vert[ 3 ].v = vert_3;

But, as long as you don't add a new variable at the beginning of the struct vert, I don't think it's going to make any difference.

dom cook - 1-12-2016 at 02:36 PM

By the way, are there any instructions on how to use the WLD editor?

BreadCaster - 1-12-2016 at 03:11 PM

Ah right okay, I've edited the code accordingly =) I might want to add a steel trim if I make any outside looking doors, like a little raised bit at the bottom and top, so it could come in handy as that'd be another sector.

Quote: Originally posted by dom cook  
By the way, are there any instructions on how to use the WLD editor?


Not bundled with DivDX, no! Generally it's pretty straight forward however. The two boxes on the right correspond to the floor and ceiling textures, and the numbered boxes correspond to the height. The box above that is the current wall texture.

You can create all kinds of cool things with it, but you do have to bare in mind that you can't do "sector over sector" level design - though you can fake it by using teleports/flags and loading/unloading new WLDs as you enter and exit areas.

You can have sectors INSIDE sectors, however - though do be careful when using the set_point_m8 command, as generally nesting a moving sector inside any more than one other sector is a recipe for disaster.

Oh, also - move around using arrow keys and use Z/X to zoom. I'd advise against clicking the right mouse button as that's liable to crash DivDX at present. In fact, it's likely to crash regardless - save often :p

dom cook - 1-12-2016 at 08:28 PM

Thanks, that should be enough for me to get started.

BreadCaster - 1-12-2016 at 09:40 PM

Quote: Originally posted by dom cook  
Thanks, that should be enough for me to get started.


That's alright, need any more help gimmie a shout - I'm indebted to you for helping with the swinging door code :D

dom cook - 2-12-2016 at 03:24 PM

Quote: Originally posted by BreadCaster  

That's alright, need any more help gimmie a shout - I'm indebted to you for helping with the swinging door code :D


Just a quick question then.
How the heck do you delete a vertex in the editor?

BreadCaster - 2-12-2016 at 04:42 PM

Quote: Originally posted by dom cook  
Quote: Originally posted by BreadCaster  

That's alright, need any more help gimmie a shout - I'm indebted to you for helping with the swinging door code :D


Just a quick question then.
How the heck do you delete a vertex in the editor?


You have to delete the sector it's a part of. You can't delete sectors or walls on their own, possibly as this would allow for people testing it with really badly broken sectors, which would be hell for the poor engine to try to interpret.

If you can't delete a sector, then your WLD is corrupted, and trying to load it will usually crash the program. D: Save and back up your WLDs often folks! Mode 8 is a temperamental betch. :p


[Edited on 2-12-2016 by BreadCaster]

dom cook - 8-12-2016 at 03:27 PM

Quote: Originally posted by BreadCaster  



Save and back up your WLDs often folks! Mode 8 is a temperamental betch. :p


[Edited on 2-12-2016 by BreadCaster]


That's putting it mildly.
I'm re-downgrading my ambitions to mode 7,



BreadCaster - 8-12-2016 at 04:05 PM

Quote: Originally posted by dom cook  
Quote: Originally posted by BreadCaster  



Save and back up your WLDs often folks! Mode 8 is a temperamental betch. :p


[Edited on 2-12-2016 by BreadCaster]


That's putting it mildly.
I'm re-downgrading my ambitions to mode 7,


Just you wait til you see what I've made in it and you'll change your mind back, aha ;) it's pretty dang cool if I say so myself... not long til it's completed, just a few more things I wanna put into it =)

dom cook - 8-12-2016 at 07:24 PM

Looking forward to it.