• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

3D [Solved] Z in 3d projection isnt working?

Z

zendraw

Guest
so i have this code in a cam instance

d3d_set_projection_ext(x, y, z, x, y, z+1, 0, 0, 1, 90, view_wview/view_hview, 1, 16000);

and i change its x/y/z but the projection doesnt change? i have another 3d project and theres no diffrence whatsoever and it x/y/z positions work on that one... any ideas whats may be wrong?

PS:working with GMS1
 

lolslayer

Member
There is no z variable built-in with gamemaker like x and y, did you initialize your z variable somewhere before calling this?

PS use reply on me, I won't get a notification if you just post something else on this thread without directly replying to me
 
Z

zendraw

Guest
There is no z variable built-in with gamemaker like x and y, did you initialize your z variable somewhere before calling this?

PS use reply on me, I won't get a notification if you just post something else on this thread without directly replying to me
ofcorse, it will give me an error if i didnt. also i change that z variable to test it but it doesnt work, it doesnt work even with x and y.
 

Binsk

Member
Change your up values. You have the direction of the camera pointed along the same axis as your camera up vector.

GameMaker attempts to make this perpendicular if it is not, but when the two equal the cross product equals 0 which will screw up your camera. Since I don't know what angle you want your camera (and the up vector changes this) you'll have to figure it out. My guess is you want it along the positive or negative y axis.
 
Z

zendraw

Guest
@Binsk @lolslayer
- the projection is set only once, first it was in the draw event of the camera object then i put it in the controller object which also draws every instance in its draw event, but the projection didint work in the cam object also.

- im not sure what you are sayng. currently the camera without using the projection function is set exactly how i want it, with using the projection function with these settings it achives the same view angle i want. it simply doesnt move for some reason and also i m not noticing any difference when changing the angle setting for the lens or what its called.

its really bizzare to me, i dont see a reason for it to not work, there isnt much d3d functions going on anyway.
 
Last edited:

Binsk

Member
@Binsk @lolslayer
- the projection is set only once, first it was in the draw event of the camera object then i put it in the controller object which also draws every instance in its draw event, but the projection didint work in the cam object also.

- im not sure what you are sayng. currently the camera without using the projection function is set exactly how i want it, with using the projection function with these settings it achives the same view angle i want. it simply doesnt move for some reason and also i m not noticing any difference when changing the angle setting for the lens or what its called.

its really bizzare to me, i dont see a reason for it to not work, there isnt much d3d functions going on anyway.
d3d_set_projection_ext

Read the documentation. You have specified your up-vector as per the arguments. Try changing it from the z-axis (0, 0, 1) to the y-axis (0, -1, 0) if your camera is going to be pointing along the z-axis like in your first post. If that doesn't help, then perhaps we need to see a different part of your code. Give us the full code portions where you call this function.
 
Z

zendraw

Guest
d3d_set_projection_ext

Read the documentation. You have specified your up-vector as per the arguments. Try changing it from the z-axis (0, 0, 1) to the y-axis (0, -1, 0) if your camera is going to be pointing along the z-axis like in your first post. If that doesn't help, then perhaps we need to see a different part of your code. Give us the full code portions where you call this function.
i will try what you say, altho i dont see why wuld it matter anyway, in my other project the camera projection moves on x,y and z no problem.
i will also check if some other code accidentaly interfires.
 

lolslayer

Member
I see what you did wrong with this code

You can't look directly up or down if you have your up axis on the z axis, so change the code to this and it should work:
d3d_set_projection_ext(x, y, z, x+0.001, y+0.001, z+1, 0, 0, 1, 90, view_wview/view_hview, 1, 16000);
 
M

Multimagyar

Guest
I see what you did wrong with this code

You can't look directly up or down if you have your up axis on the z axis, so change the code to this and it should work:
d3d_set_projection_ext(x, y, z, x+0.001, y+0.001, z+1, 0, 0, 1, 90, view_wview/view_hview, 1, 16000);
or you know you could just re-calcuate the up vector pretty easily. Number like +0.001 can make inaccuracies. if it's a static top down look you could just also change the up vectory to 1,0,0; 0,1,0; -1,0,0 or 0,-1,0.
 
Z

zendraw

Guest
wait now, the problem is that the projection doesnt respond atall to x/y/z positions, the instance that has the projection code moves, the camera doesnt. i dont even see the 'angle' variable to be doing anything, and if i disable the projection function with // theres actually no change whatsoever for the camera.
 

Binsk

Member
Have you actually TRIED what three of us now have suggested? Try. It. Tell us what happens.
 

Binsk

Member
Alright, then can you give us the whole code block for that draw code? Where else are you drawing? THAT code?

You sure are making it difficult to help you.
 
Z

zendraw

Guest
so i have a controller object that does all the drawing, the other instances are not even visible, and theyr code is just moving code and such.
here is the code for the controller object
Code:
CREATE
draw_texture_flush();

d3d_start();

d3d_set_lighting(false);
//d3d_light_enable(1, true);
//d3d_light_enable(2, true);
//d3d_set_fog(true, c_black, 6144, 8192);
d3d_set_culling(true);
d3d_set_hidden(true);

draw_set_colour(c_white);
display_set_gui_size(view_wview,view_hview);

for (var i=0; i<2; i++)
{
    mdl[i]=d3d_model_create();
}

d3d_model_load(mdl[0], "tests.txt");
d3d_model_load(mdl[1], "testmet.txt");

radar=0;
lens=45;

z=0;

alarm[0]=room_speed;
Code:
STEP
//this is just for testing for the projection
x+=32;
z+=32;
Code:
Draw Event:

execute code:

///self


d3d_draw_floor(-8000, -8000, 16000, 16000, 16000, 16000, tx_space, 1, 1);



for all o_fighter: execute code:

///o_fighter

//d3d_draw_block(x-56, y-16, z-32, x+56, y+16, z+96, tex, 1, 1);

d3d_transform_set_identity();

//d3d_model_draw(other.mdl[mdl], other.x, other.y, 0, other.tx_radar);

d3d_transform_add_rotation_z(hlean);
d3d_transform_add_rotation_x(vlean);

d3d_transform_add_translation(x, y, z);

d3d_model_draw(other.mdl[mdl], 0, 0, z, tex);

d3d_transform_set_identity();

for all par_alien: execute code:

///par_enemy

//d3d_draw_ellipsoid(x-32, y-32, z-32, x+32, y+32, z+32, tex, 1, 1, 16);

d3d_transform_set_identity();

//d3d_model_draw(other.mdl[mdl], x, y, 0, tex);
if (other.radar)
{
    d3d_model_draw(other.mdl[mdl], x, y, 0, other.tx_radar);
}

d3d_transform_add_translation(x, y, z);

d3d_model_draw(other.mdl[mdl], 0, 0, z, tex);

d3d_transform_set_identity();



for all o_star: execute code:

///o_star

//d3d_draw_ellipsoid(x-32, y-32, z-32, x+32, y+32, z+32, tex, 1, 1, 16);

d3d_transform_set_identity();
//d3d_transform_add_rotation_z(dir);
d3d_transform_add_translation(x,y,z);

d3d_model_draw(other.mdl[mdl], 0, 0, z, tex);

d3d_transform_set_identity();

for all o_dmg: execute code:

/// o_dmg

//d3d_draw_block(x-4, y-4, z, x+4, y+4, z+256, tex, 1, 1);


d3d_transform_set_identity();
d3d_transform_set_scaling(.25, .25, 10);
d3d_transform_add_rotation_z(hlean);
d3d_transform_add_rotation_x(vlean);
d3d_transform_add_translation(x, y, z);

d3d_model_draw(other.mdl[mdl], 0, 0, z, tex);

d3d_transform_set_identity();



execute code:

///self-projection

d3d_set_projection_ext(x, y, z, x, y, z+1, 0, 0, 1, lens, 1, 1, 16000);

//d3d_set_projection_ortho(x, y, view_wview, view_hview, 0);



Draw GUI Event:

for all o_fighter: execute code:

/// o_fighter


draw_text(view_wview*.5, 16,
'skore:'+string(skore)
);

execute code:

/// fighter powers

var rw2=(view_wview*.5)-108;

for (var i=0; i<4; i++)
{
    if (i && i<3) {j=8} else {j=0};
    draw_sprite(s_pwr_slot, 0, rw2+(i*72), view_hview-48+j);
    draw_sprite(s_pwr_laser+i, 0, rw2+(i*72), view_hview-48+j);
}



execute code:

/// cotnroll

draw_set_halign(fa_left);
draw_set_valign(fa_top);

draw_set_colour(c_silver);
draw_text(0, 0,
'fps:'+string(floor(fps_real))+
'#ins:'+string(instance_count)
);
 
Z

zendraw

Guest
before, if i ptu them after, theres blackness, i havent tryedchanging the angles at that point.
 
Z

zendraw

Guest
yeah the problem was i was putting it after i draw the stuff. now it works normally, thanks for the replies, i also had to change the up variables.
 
Top