This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void ViewFrustum::calculate( const float fov , const float aspectratio , const float n , const float f ) | |
| { | |
| float nearPlane = -n; | |
| float farPlane = -f; | |
| float y1 = nearPlane * tanf(torad(fov)/2.0f); | |
| float y2 = farPlane * tanf(torad(fov)/2.0f); | |
| // calculate the horizontal fov from the vertical one | |
| float fov_horizontal = 2.0f * atanf( tanf(torad(fov)/2.0f) * aspectratio ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void render() | |
| { | |
| // update camera based on mouse position, WASD, etc. | |
| // calculate the view frustum | |
| viewFrustum.calculate( 60.0f , (float)window->getWidth()/(float)window->getHeight() , 0.1f , 100.0f ); | |
| // convert the view frustum to world space | |
| viewFrustum.convertToWorldSpace( camera->getInverseViewMatrix() ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function ppnEncrypt( $data , $key ) | |
| { | |
| $method = 'aes-256-gcm'; | |
| $key = base64_decode( $key ); | |
| $iv = openssl_random_pseudo_bytes( openssl_cipher_iv_length( $method ) ); | |
| $tag = ""; // openssl_encrypt will fill this | |
| $result = openssl_encrypt( $data , $method , $key , OPENSSL_RAW_DATA , $iv , $tag , "" , 16 ); | |
| return base64_encode( $iv.$tag.$result ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $sql = "INSERT INTO table ( a , b , c ) VALUES ( ? , ? , ? )"; | |
| // prepared statement without the wrapper function | |
| if ( $stmt = $mysql->prepare( $sql ) ) | |
| { | |
| if ( $stmt->bind_param( "iis" , 1 , 2 , "string" ) ) | |
| { | |
| if ( $stmt->execute() ) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function foobar( $arg , $arg2 ) | |
| { | |
| echo __FUNCTION__, " got $arg and $arg2\n"; | |
| } | |
| class foo | |
| { | |
| function bar( $arg , $arg2 ) | |
| { | |
| echo __METHOD__, " got $arg and $arg2\n"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function lmysql_execute( $mysql , $sql , $types , ...$params ) | |
| { | |
| if ( !( $stmt = $mysql->prepare( $sql ) ) ) | |
| { | |
| error_log( "LMYSQL > prepare , errno: ".$mysql->errno.", error: ".$mysql->error ); | |
| return false; | |
| } | |
| if ( strlen( $types ) > 0 ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #version 330 core | |
| in vec2 uv; | |
| uniform sampler2D sampler; | |
| uniform float desaturationFactor; | |
| out vec4 fragColor; | |
| void main() | |
| { | |
| vec3 color = texture2D( sampler , uv ).rgb; | |
| vec3 gray = vec3( dot( color , vec3( 0.2126 , 0.7152 , 0.0722 ) ) ); | |
| fragColor = vec4( mix( color , gray , desaturationFactor ) , 1.0 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #version 330 core | |
| layout ( location = 0 ) in vec2 vertex_position; | |
| layout ( location = 2 ) in vec2 vertex_uv; | |
| uniform mat4 M_mvp; | |
| out vec2 uv; | |
| void main() | |
| { | |
| gl_Position = M_mvp * vec4( vertex_position , 0.0 , 1.0 ); | |
| uv = vertex_uv; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const std::string SimpleParticleShader::VS = "#version 330 core\n" | |
| "layout ( location = 0 ) in vec3 vertex_position;" | |
| "layout ( location = 4 ) in vec4 position;" | |
| "uniform mat4 M_v;" | |
| "uniform mat4 M_p;" | |
| "uniform float particleSize;" | |
| "out float lifetime;" | |
| "void main()" | |
| "{" | |
| " vec4 position_viewspace = M_v * vec4( position.xyz , 1 );" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SimpleEmitter::SimpleEmitter() | |
| { | |
| // create 100 particles | |
| this->particles.resize( 100 ); | |
| for ( uint i = 0 ; i < this->particles.size() ; ++i ) | |
| { | |
| // give every particle a random position | |
| this->particles[i].position = lstd_random_between( vec3( -1.0f ) , vec3( 1.0f ) ); | |
| this->particles[i].lifetime = lstd_random_between( 1.0f , 2.0f ); | |
| } |
OlderNewer