tag:blogger.com,1999:blog-7720114227451545666.post4908057052930732487..comments2023-06-12T03:26:53.884-07:00Comments on DwarvesH Development: LL3DLGLD – 11 – I see you, jakesillyminerDwarvesH Developmenthttp://www.blogger.com/profile/15924524153610772335noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-7720114227451545666.post-4166459330313540672011-10-07T09:33:16.200-07:002011-10-07T09:33:16.200-07:00I take that back. Looking from positive Z to zero ...I take that back. Looking from positive Z to zero in a left-handed Cartesian coordinate systems reverses the rest of the coordinate axis and I can no longer use the same rules one uses in "normal" math.DwarvesH Developmenthttps://www.blogger.com/profile/15924524153610772335noreply@blogger.comtag:blogger.com,1999:blog-7720114227451545666.post-78848729805726493372011-10-07T08:51:57.575-07:002011-10-07T08:51:57.575-07:00Wow, I am going to need some time to process that ...Wow, I am going to need some time to process that information.<br /><br />I'll experiment a little: because of the left-handed Cartesian coordinate systems Z increases as we go deeper into the screen but I can still put the camera at a positive Z coordinate and make it look to zero. <br /><br />I hope this won't have any ill effects, other than a few faces changing direction. Is there any good reason not to do this?DwarvesH Developmenthttps://www.blogger.com/profile/15924524153610772335noreply@blogger.comtag:blogger.com,1999:blog-7720114227451545666.post-50503706126811943022011-10-07T06:18:03.983-07:002011-10-07T06:18:03.983-07:00Sound advice from David about creating your own ca...Sound advice from David about creating your own camera. A lot of effects & techniques requires (or become easier) when you know the camera matrix. <br /><br />Examples of effects:<br />- casting a ray from the camera in its view direction. Useful alternative to colorpicking.<br /><br />- drawing 3D objects infront of the camera (regardless of look dir). Just use the cameras matrix and add a translation. Useful for fps weapons, hands or the players head orientation.<br /><br />- frustum culling<br /><br />For a 3x3 viewmatrix, the view-vector is the last row. <br /><br />side_x, side_y, side_z,<br />up_x, up_y, up_z,<br />fwd_x, fwd_y, fwd_z // <- the forward vector<br /><br />One way of making this matrix is by creating the forward vector by creating the orientation part by multiplying two matrices, one for rotation around the x-axis (vertical) and the other in the y-axis (horizontal) like this:<br /><br />mat3 orientation = make_rot_matrix_x( horizontal_angle ) * make_rot_matrix_y( vertical_angle );<br /><br />Ok, now you want to translate in the direction you're looking if pressing forward/backward (keys W/S), or sidestep relative to the forward vector (keys A/D). This can be done by creating a move_dir vector like so: <br /><br />dirvec = vec3(left_key-right_key, 0.0, back_key-forwards_key); <br /><br />The dirvec is relative to your coordinate system, so it needs to be transformed by the orientation matrix, so <br /><br />move_delta = orientation * dirvec;<br /><br />The move_delta can now be added to your cameras translation. <br /><br />camera.position += move_delta;<br /><br />You probably want a final homogenous 4x4 instead of an 3x3 orientation + a vec position.<br /><br />... Another way of creating a view matrix using a horizontal and vertical angle is the ang2mat (basically does what I explained above, but creates the orientation matrix directly) function I found one of Ken Silvermans evaldraw scripts:<br />ang2mat(hang,vang,mat[9])<br />{<br /> mat[0]=cos(hang);<br /> mat[1]=0;<br /> mat[2]=-sin(hang);<br /><br /> mat[6]=cos(vang)*sin(hang); <br /> mat[7]=sin(vang);<br /> mat[8]=cos(vang)*cos(hang);<br /><br /> mat[3] = mat[7]*mat[2] - mat[8]*mat[1];<br /> mat[4] = mat[8]*mat[0] - mat[6]*mat[2];<br /> mat[5] = mat[6]*mat[1] - mat[7]*mat[0];<br />}<br />First it creates a side vector stored at indices (0,1,2). Then a forwards-vector in (6,7,8). Finally it creates the upvector in (3,4,5) by taking the cross product up = cross(side, fwd). <br /><br />Expressed using a vector lib:<br />vec3 side( cos(hang), 0.0, -sin(hang) );<br />vec3 fwd( cos(vang)*sin(hang), sin(vang), cos(vang)*cos(hang) );<br />vec3 up = cross(side,fwd);<br />mat3 orientation( side, up, fwd );<br /><br />To move in the new look direction you can do as I previously explained transforming your desired move direction (dirvec).<br />move_delta = orientation * dirvec;<br /><br />Another way to move the camera would be to translate some multiple of the side, up or forwards vector. For instance <br /><br />camera.position += side * (left_key-right_key);<br />camera.position += fwd * (back_key-forwards_key);<br /><br />It could be better to add these to vectors togheter like<br />vec3 move_delta = side * (left_key-right_key) + fwd * (back_key-forwards_key);<br /><br />and then normalize it so you don't move faster when holding W/S and A/D as you mention.torbjørnnoreply@blogger.comtag:blogger.com,1999:blog-7720114227451545666.post-51085389139027900992011-10-07T05:23:49.800-07:002011-10-07T05:23:49.800-07:00why would you have Z run into negative? why not ha...why would you have Z run into negative? why not have the bottom most level playable count as 0 and increase as you work up to the surface/sky?<br /><br />this will be confusing for 3d modellers as you're basically drawing the world upside down and back to front to the standard of most modern 3d modelling software :/<br /><br />is this a technicality of the engine?BrewStewhttps://www.blogger.com/profile/15801505803938335004noreply@blogger.comtag:blogger.com,1999:blog-7720114227451545666.post-23549063499938271852011-10-07T03:02:05.980-07:002011-10-07T03:02:05.980-07:00OpenGL and DirectX (whichever Irrlicht is talking ...OpenGL and DirectX (whichever Irrlicht is talking to) both use a coordinate system that looks like the following:<br /><br />http://msdn.microsoft.com/en-us/library/windows/desktop/bb204853(v=vs.85).aspx<br /><br />OpenGL is right handed, which is alluded to in the article.<br /><br />A quick fix is to change your coordinates into the right form for the engine by multiplying them by a matrix something like:<br /><br />1 0 0<br />0 0 ±1<br />0 ±1 0<br /><br />until you get the right thing. Once this is done, the default camera would then do exactly what you want in terms of mouselook, but you would need to restrict vertical movement.<br /><br />In the long run, it is still a good idea to write the camera object from scratch, though. =)Davidhttps://www.blogger.com/profile/01237451898682810300noreply@blogger.com