I need help with math.. :D

You must understand the Game Editor concepts, before post here.

I need help with math.. :D

Postby lcl » Mon Jun 04, 2012 4:01 pm

Hello I hope someone can help me with this.

I am trying to make a room which the player will be able to turn full 360 degrees.
Something like the box that Bee-Ant made but one the player is inside, not outside.
Well what I can't figure out is how to make the room turn. I have the coordinates of the
corners but what do I need to do with them to make them rotate? It could be easier without the
perspective messing it up. If I just could get the corners to rotate correctly I am quite sure I could
make the whole thing to work.

Here is picture that shows what corner I should for example to get rotated (with all others of course :lol: )
Oh and that pacman is currently in the middle of the room. (The room continues a little out of the screen. :D )
room.png


EDIT: The problem is that the corners don't settle to a circle but ellipse. It makes it much harder (for me at least)...


Thanks in advance!
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: I need help with math.. :D

Postby Bee-Ant » Tue Jun 05, 2012 9:07 am

Something like this?
http://dl.dropbox.com/u/3997355/Demo/3D ... lipses.ged
The control is arrow keys
I have made this over a year ago as experiment :)
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: I need help with math.. :D

Postby lcl » Wed Jun 06, 2012 7:47 am

Well, something like that..
Your example just doesn't have the perspective in it and the
shape of the room is a little skewed..

The room won't appear like this in reality:
room1.png

The roof and the floor should be a little flatter.
room2.png

And if this had perspective the corners behind should be closer to each other than the
ones in front of.

And well I still can't understand the math.
I guess that's where I need the most help. What do I even need to calculate to get
the corners to fit right on the ellipse? It is very difficult for me to understand where I should start
from..

But thank you anyway, Bee! :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: I need help with math.. :D

Postby Bee-Ant » Sat Jun 09, 2012 1:30 pm

Sorry, I just posted that sucked demo without doing any modification first.
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: I need help with math.. :D

Postby lcl » Sat Jun 09, 2012 11:23 pm

No need to be sorry :)
It just seems that what I'm trying to do is very hard to achieve.. :P
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: I need help with math.. :D

Postby jimmynewguy » Tue Jun 19, 2012 9:34 pm

Well in your first post it says that the main problem for you is that the room is an ellipse instead of a circle. Is this the only problem you have with this? If it is, then you should just do the room as a circle but use the trig of an ellipse.

http://en.wikipedia.org/wiki/Ellipse#Ge ... etric_form

If not then well, maybe that helps somehow?
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: I need help with math.. :D

Postby makslane » Thu Jun 21, 2012 10:21 pm

This is a code of an old program of mine (Visual3D, 1993).
I think this can help you.

Code: Select all
double d = 100; //Perspective distance (you must adjust this value)
double scale = 1; //Object size
int center_x = 500, center_y = 500; //the center of the canvas/screen (view.width / 2, view.height / 2, for example)
double teta_x= 0.8 , teta_y = 0.8; //Vision angle (radians)

void line3d(double x1, double y1, double z1, double x2, double y2, double z2)
{
   double x3d_x1,y3d_y1,z3d_z1,x3d_x2,y3d_y2,z3d_z2;
   double vector_y3d_x1,vector_y3d_y1,vector_y3d_x2,vector_y3d_y2;
   double p1,p2,pers1,pers2;
   LONG point_x_x1,point_y_y1,point_x_x2,point_y_y2;
   
   
   x3d_x1 = x1*scale;
   y3d_y1 = y1*scale;
   z3d_z1 = z1*scale;
   
   x3d_x2 = x2*scale;
   y3d_y2 = y2*scale;
   z3d_z2 = z2*scale;
   
   /* Perspective !!! */
   
   
   p1 = z3d_z1*sin(teta_y)*cos(teta_x)+y3d_y1*sin(teta_x)*cos(teta_y)+x3d_x1*cos(teta_x)*cos(teta_y);
   p2 = z3d_z2*sin(teta_y)*cos(teta_x)+y3d_y2*sin(teta_x)*cos(teta_y)+x3d_x2*cos(teta_x)*cos(teta_y);
   
   p1 = (d+p1)*((d+p1)/d);
   p2 = (d+p2)*((d+p2)/d);
   
   pers1 = ((d+p1)/d)/2;
   pers2 = ((d+p2)/d)/2;
   
   vector_y3d_x1 = center_x+pers1*y3d_y1*scale_x*cos(teta_x);
   vector_y3d_y1 = center_y+pers1*y3d_y1*scale_y*sin(teta_x)*sin(teta_y);
   
   vector_y3d_x2 = center_x+pers2*y3d_y2*scale_x*cos(teta_x);
   vector_y3d_y2 = center_y+pers2*y3d_y2*scale_y*sin(teta_x)*sin(teta_y);
   
   point_x_x1 = vector_y3d_x1-pers1*x3d_x1*scale_x*sin(teta_x);
   point_y_y1 = (vector_y3d_y1+pers1*x3d_x1*scale_y*sin(teta_y)*cos(teta_x))-pers1*z3d_z1*scale_y*cos(teta_y);
   
   point_x_x2 = vector_y3d_x2-pers2*x3d_x2*scale_x*sin(teta_x);
   point_y_y2 = (vector_y3d_y2+pers2*x3d_x2*scale_y*sin(teta_y)*cos(teta_x))-pers2*z3d_z2*scale_y*cos(teta_y);
   
   //Some draw function
   draw(point_x_x2,point_y_y2);
}
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Re: I need help with math.. :D

Postby lcl » Thu Jun 21, 2012 11:08 pm

makslane wrote:This is a code of an old program of mine (Visual3D, 1993).
I think this can help you.

Code: Select all
double d = 100; //Perspective distance (you must adjust this value)
double scale = 1; //Object size
int center_x = 500, center_y = 500; //the center of the canvas/screen (view.width / 2, view.height / 2, for example)
double teta_x= 0.8 , teta_y = 0.8; //Vision angle (radians)

void line3d(double x1, double y1, double z1, double x2, double y2, double z2)
{
   double x3d_x1,y3d_y1,z3d_z1,x3d_x2,y3d_y2,z3d_z2;
   double vector_y3d_x1,vector_y3d_y1,vector_y3d_x2,vector_y3d_y2;
   double p1,p2,pers1,pers2;
   LONG point_x_x1,point_y_y1,point_x_x2,point_y_y2;
   
   
   x3d_x1 = x1*scale;
   y3d_y1 = y1*scale;
   z3d_z1 = z1*scale;
   
   x3d_x2 = x2*scale;
   y3d_y2 = y2*scale;
   z3d_z2 = z2*scale;
   
   /* Perspective !!! */
   
   
   p1 = z3d_z1*sin(teta_y)*cos(teta_x)+y3d_y1*sin(teta_x)*cos(teta_y)+x3d_x1*cos(teta_x)*cos(teta_y);
   p2 = z3d_z2*sin(teta_y)*cos(teta_x)+y3d_y2*sin(teta_x)*cos(teta_y)+x3d_x2*cos(teta_x)*cos(teta_y);
   
   p1 = (d+p1)*((d+p1)/d);
   p2 = (d+p2)*((d+p2)/d);
   
   pers1 = ((d+p1)/d)/2;
   pers2 = ((d+p2)/d)/2;
   
   vector_y3d_x1 = center_x+pers1*y3d_y1*scale_x*cos(teta_x);
   vector_y3d_y1 = center_y+pers1*y3d_y1*scale_y*sin(teta_x)*sin(teta_y);
   
   vector_y3d_x2 = center_x+pers2*y3d_y2*scale_x*cos(teta_x);
   vector_y3d_y2 = center_y+pers2*y3d_y2*scale_y*sin(teta_x)*sin(teta_y);
   
   point_x_x1 = vector_y3d_x1-pers1*x3d_x1*scale_x*sin(teta_x);
   point_y_y1 = (vector_y3d_y1+pers1*x3d_x1*scale_y*sin(teta_y)*cos(teta_x))-pers1*z3d_z1*scale_y*cos(teta_y);
   
   point_x_x2 = vector_y3d_x2-pers2*x3d_x2*scale_x*sin(teta_x);
   point_y_y2 = (vector_y3d_y2+pers2*x3d_x2*scale_y*sin(teta_y)*cos(teta_x))-pers2*z3d_z2*scale_y*cos(teta_y);
   
   //Some draw function
   draw(point_x_x2,point_y_y2);
}

Wow thank you Makslane! :)
I have to try this code! Thanks very much! :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron