Skip to content

Instantly share code, notes, and snippets.

@pingpoli
pingpoli / ViewFrustum.cpp
Last active June 17, 2020 20:32
calculate the perspective projection view frustum in opengl
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 );
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() );
<?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 );
}
<?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() )
{
<?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";
<?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 )
#version 330 core
uniform float threshold;
uniform float strength;
uniform sampler2D colorTexture;
in vec2 uv;
out vec4 fragColor;
void main()
{
vec4 color = texture2D( colorTexture , uv );
// convert rgb to grayscale/brightness
#version 330 core
uniform sampler2D colorTexture;
uniform float resolution;
uniform float radius;
uniform vec2 direction;
in vec2 uv;
out vec4 fragColor;
void main()
{
float blur = radius/resolution;
#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;
}
#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 );