# GMS 2Help me build a better parallax background with 3d

M

#### Maru

##### Guest
So, i was working on the backgrounds for my game and it felt kinda odd that all the buildings had the same perspective regardless of where the camera was, so i tought it would be nice if the background had some perspective things, so i tried looking into some tutorials and some forum entries but or they were mostly for making the whole game in 3d, but i was able to make it with primitive triangles (there were no functions for trapezoids that i could find), but the code ended up being an incomprehensible autistic mess (i cleaned up so now it looks kinda better tho), and would be too hard to make textures for each triangle (and also if its even possible), so i think doing it with 3d would be a lot easier
if you want to test to picture what i was saying, the code is
Mx1=mouse_x-30;
My1=mouse_y-30;
Mx2=mouse_x+30;
My2=mouse_y+30;
strenght=0.1 // 0 is no prespective and 1 pulls all the triangles all the way to the center of the camera
//this bit is only for debug or demonstrational porpuses, the final code would have the coordinate in the create event
Mx1=mouse_x-30;
My1=mouse_y-30;
Mx2=mouse_x+30;
My2=mouse_y+30;

//update camera values
Vx = (camera_get_view_x(view_camera[0])+camera_get_view_width(view_camera[0])/2);
Vy = (camera_get_view_y(view_camera[0])+camera_get_view_height(view_camera[0])/2);

#region //right trapezoid

RAx=Mx2;
RBx=lerp(Mx2,Vx,strength);
RCx=lerp(Mx2,Vx,strength);
RDx=Mx2;
REx=Mx2;

RAy=My1;
RBy=lerp(My1,Vy,strength);
RCy=lerp(My2,Vy,strength);
RDy=My2;
REy=(My1+My2)/2;

#endregion

#region //left trapezoid

LAx=Mx1;
LBx=lerp(Mx1,Vx,strength);
LCx=lerp(Mx1,Vx,strength);
LDx=Mx1;
LEx=Mx1;

LAy=My1;
LBy=lerp(My1,Vy,strength);
LCy=lerp(My2,Vy,strength);
LDy=My2;
LEy=(My1+My2)/2;

#endregion

#region //bottom trapezoid

BAx=Mx1;
BBx=lerp(Mx1,Vx,strength);
BCx=lerp(Mx2,Vx,strength);
BDx=Mx2;
BEx=(Mx1+Mx2)/2;

BAy=My2;
BBy=lerp(My2,Vy,strength);
BCy=lerp(My2,Vy,strength);
BDy=My2;
BEy=My2;

#endregion

#region //top trapezoid

TAx=Mx1;
TBx=lerp(Mx1,Vx,strength);
TCx=lerp(Mx2,Vx,strength);
TDx=Mx2;
TEx=(Mx1+Mx2)/2;

TAy=My1;
TBy=lerp(My1,Vy,strength);
TCy=lerp(My1,Vy,strength);
TDy=My1;
TEy=My1;

#endregion
draw_set_color(c_ltgray);

//right trapezoid
draw_triangle(RAx,RAy,RBx,RBy,REx,REy,false);
draw_triangle(RBx,RBy,REx,REy,RCx,RCy,false);
draw_triangle(REx,REy,RDx,RDy,RCx,RCy,false);

//left trapezoid
draw_triangle(LAx,LAy,LBx,LBy,LEx,LEy,false);
draw_triangle(LBx,LBy,LEx,LEy,LCx,LCy,false);
draw_triangle(LEx,LEy,LDx,LDy,LCx,LCy,false);

//bottom trapezoid
draw_triangle(BAx,BAy,BBx,BBy,BEx,BEy,false);
draw_triangle(BBx,BBy,BEx,BEy,BCx,BCy,false);
draw_triangle(BEx,BEy,BDx,BDy,BCx,BCy,false);

//top trapezoid
draw_triangle(TAx,TAy,TBx,TBy,TEx,TEy,false);
draw_triangle(TBx,TBy,TEx,TEy,TCx,TCy,false);
draw_triangle(TEx,TEy,TDx,TDy,TCx,TCy,false);

//main rectangle
draw_set_color(c_white);
draw_rectangle(Mx1,My1,Mx2,My2,false);
also you need to enable the viewport 0 for it to work
thats just to show what i would like to acomplish with a 3d background, can someone help me?
also for a video of the code running /watch?v=nAOU3Dm5FKA (i cant post links yet so ull need to past this to the end of the youtube url)