M
moogthedog
Guest
I'm trying to start out with a spot of 3d, and I'm close... but it's defeating me at the last moment.
I've got a room set up with a camera layer and an instances layer. The camera layer is at the bottom of the heap, as I've read the camera object needs to be the furthest away.
In the room, I have six objects:
Camera layer: oCamera (?)
Instances: oPlayer (>), 3 oBlocks, and an oGlb (?) to hold any 'globals'
Grid's 32.
The player responds to keyboard commands (WASD to move, arrow keys to look, with up and down doing pitch), and that's working fine - there's no camera jiggery pokery in the player.
The block object has this in create:
which is aimed to create a single 3D triangle standing up in the Z direction, at the block's location.
This is in draw
which (I hope) submits the triangle to the default shader for rendering, as well as plotting the block to the default camera which is used to make a mini map (see below)
The oGlb object sets up the viewports in its create:
Which sets up the view port for what's to be the roaming 3D camera, and a second standard camera for the mini-map.
The camera object has this for creation:
Where the camera is created and assigned to its viewport, and given a default set of matrices which will change as the player moves.
And then this in its draw event
which forces the camera to track the player's position and 'head' (view direction).
Desired operation: Given the start positions, I'd expect the 3D camera to show me three triangles side by side, and I should be able to move around the world to look at them from different angles
In 'version 1' in the camera::draw, I get very close - the minimap is rendered in the sky, but is displayed sensibly - I think I know why that happens. As the player moves, the 'sky' tracks in and around the view correctly. If you pitch up, you can actually see the player's arrow following him around. Unfortunately the 'blocks' aren't rendered in the 3D realm at all - just as sprites in the sky. I've tried moving around to see if I've got the axes messed up, but they're just not there.
In 'version 2', I can see a single pure white triangle, but it stays solidly in the centre of the screen, changing shape slightly on player movement, and stretching oddly when the pitch changes. Changing the vertexes in block::create to change its width seems to have no effect, so I'm thinking I may not actually be looking at a block object at all.
Looking for any and all help, and please don't think anything's too obvious - I've spun this together from what I know of 2D cameras from my previous project and the tutorials, and the help. If it's easier, I can zip and upload the project to a server.
I've got a room set up with a camera layer and an instances layer. The camera layer is at the bottom of the heap, as I've read the camera object needs to be the furthest away.
In the room, I have six objects:
Camera layer: oCamera (?)
Instances: oPlayer (>), 3 oBlocks, and an oGlb (?) to hold any 'globals'
Grid's 32.
The player responds to keyboard commands (WASD to move, arrow keys to look, with up and down doing pitch), and that's working fine - there's no camera jiggery pokery in the player.
The block object has this in create:
Code:
height=32;
// define the vertex format - just position and colour for the moment
vertex_format_begin();
vertex_format_add_position_3d();
vertex_format_add_colour();
form=vertex_format_end();
// create a buffer
buf=vertex_create_buffer();
// add my primitives - just a standy-up triangle at the moment
vertex_begin(buf,form);
vertex_position_3d(buf,x,y-sprite_height,height);
vertex_colour(buf,c_white,1);
vertex_position_3d(buf,x,y-sprite_height,height);
vertex_colour(buf,c_red,1);
vertex_position_3d(buf,x,y,0);
vertex_colour(buf,c_blue,1);
vertex_end(buf);
This is in draw
Code:
vertex_submit(buf,pr_trianglelist,-1);
// also plot ourselves to the default camera (for the minimap)
draw_self();
The oGlb object sets up the viewports in its create:
Code:
player=instance_nearest(0,0,oPlayer)
camera=instance_nearest(0,0,oCamera);
view_enabled=true;
///camera view
view_xport[0]=0;
view_yport[0]=0;
view_wport[0]=1024;
view_hport[0]=1024;
view_visible[0]=true;
///map view
view_xport[1]=0;
view_yport[1]=20;
view_wport[1]=100;
view_hport[1]=100;
view_visible[1]=true;
camera_set_view_pos(view_camera[1],0,0);
camera_set_view_size(view_camera[1],1024,1024);
The camera object has this for creation:
Code:
cam=camera_create();
camera_set_proj_mat(cam,matrix_build_projection_perspective(640,480,1,32000));
camera_set_view_mat(cam,matrix_build_lookat(0,0,0,1,0,0,0,0,1));
view_camera[0]=cam;
And then this in its draw event
Code:
x=oGlb.player.x;
y=oGlb.player.y;
var _cz=oGlb.player.z+oGlb.player.height;
direction=oGlb.player.direction;
var _tx=x+lengthdir_x(1,direction);
var _ty=y+lengthdir_y(1,direction);
var _tz=_cz+lengthdir_y(1,oGlb.player.pitch);
// version 1
camera_set_proj_mat(cam,matrix_build_projection_perspective_fov(90,1,1,32000));
// version 2
//camera_set_proj_mat(cam,matrix_build_projection_perspective(1024,1024,1,32000));
camera_set_view_mat(cam,matrix_build_lookat(x,y,_cz,_tx,_ty,_tz,0,0,1));
Desired operation: Given the start positions, I'd expect the 3D camera to show me three triangles side by side, and I should be able to move around the world to look at them from different angles
In 'version 1' in the camera::draw, I get very close - the minimap is rendered in the sky, but is displayed sensibly - I think I know why that happens. As the player moves, the 'sky' tracks in and around the view correctly. If you pitch up, you can actually see the player's arrow following him around. Unfortunately the 'blocks' aren't rendered in the 3D realm at all - just as sprites in the sky. I've tried moving around to see if I've got the axes messed up, but they're just not there.
In 'version 2', I can see a single pure white triangle, but it stays solidly in the centre of the screen, changing shape slightly on player movement, and stretching oddly when the pitch changes. Changing the vertexes in block::create to change its width seems to have no effect, so I'm thinking I may not actually be looking at a block object at all.
Looking for any and all help, and please don't think anything's too obvious - I've spun this together from what I know of 2D cameras from my previous project and the tutorials, and the help. If it's easier, I can zip and upload the project to a server.