3D 3d Transformations

Neverday

Member
I'm having some trouble getting d3d transformations down. Some game elements are billboarded sprites, however, they appear mirrored, and I can't figure out how to fix them.

This is my ground texture.


This is how I want it to appear. Top left is north in-game, so it would make sense that the top of the texture is pointing that direction.



This is how it appears in-game



I understand that d3d drawing is different than 2d drawing. Could someone explain how to compensate so that it doesn't get flipped? I know how to disable backface culling, but it's a bad practice because it draws twice as much as it needs to.

Here is the relevant code I'm using.
Code:
  //Camera projection
  //cam_xoff=-1000
  //cam_yoff=1000
  //cam_zoff=1500
  d3d_set_projection(cam_x+cam_xoff,cam_y+cam_yoff,cam_zoff,cam_x,cam_y,0,0,0,1)
Code:
  //Drawing the floor
  draw_set_color(c_white);
  //draw_set_color(make_colour_hsv(0,100,clamp((floor_noise[i,j]+1)*255,100,255)));  
  d3d_transform_set_identity();
  d3d_set_depth(0);
  d3d_transform_add_translation(i*128,j*128,-15)
  d3d_transform_add_rotation_x(0)
  d3d_transform_add_rotation_y(0)
  d3d_transform_add_rotation_z(0)  
  d3d_draw_floor(0,128,0,128,0,0,background_get_texture(background17),1,1)
  d3d_transform_set_identity();
 
Last edited:
if you used d3d_start, then the y axis is reversed. One way to counteract that is to reverse the y axis on your texture mapping of your primities. Or you could use a negative aspect ratio in your projection, which will mirror your whole world. (which by the way will affect backface culling). Or you could just flip your background image upside down.
 

Neverday

Member
Reversing the texture mapping seems to be the easiest option. I had an idea and changed the vrepeat in d3d_draw_floor from 1 to -1. I was surprised to find that it actually worked, even though having the texture repeat negative 1 times seems wrong in my head. Is there a more straightforward method, or is this correct?

Edit: I tried to use this method with my animated billboards, and it screws them up. It appears to grab frames in the opposite direction, causing all sorts of images to pop up.

Edit 2: I believe I solved my own question. Here is the code I used for anyone reading this thread in the future.

Code:
  var x1,x2,y1,y2;
  
  x2=sprite_xoffset
  y2=sprite_yoffset+sprite_height
  
  x1=x2+lengthdir_x(sprite_height,90)
  y1=y2+lengthdir_y(sprite_height,90)
  d3d_transform_set_identity();  
  draw_set_colour(c_white);
  d3d_transform_add_rotation_x(0); 
  d3d_transform_add_rotation_z(0);
  d3d_transform_add_rotation_y(0); 
  d3d_transform_add_translation(x, y, z+20)  
  d3d_primitive_begin_texture(pr_trianglefan, sprite_get_texture(sprite_index,image_index));  
  d3d_vertex_texture(x1, y1, 0, 0, 0);
  d3d_vertex_texture((x2+sprite_width), y1, 0, 1, 0);
  d3d_vertex_texture((x2+sprite_width), y2, 0, 1, 1);
  d3d_vertex_texture(x1, y2, 0, 0, 1);
  d3d_primitive_end();
  d3d_transform_set_identity();
 
Last edited:

FrostyCat

Redemption Seeker
You shouldn't have changed what's drawn, change the camera position instead. Set the camera to look in the direction (0, 0, 1) and use (0, -1, 0) as the up vector. Draw a diagram and see for yourself.

There are no absolute ups in 3D, stop working like there is one.
 
Top