// Blending shader
// PI constant
#define M_PI 3.1415926535897932384626433832795
// Used by lighting fragment shader
varying vec3 N;
varying vec3 v;
// Bending angle (-30 to 30 degrees)
uniform float bendAngle;
// Creates matrix representing rotation around X axis
mat4 makeXRotMat(float myAngle)
{
// STUDENTS CODE //
// X Y Z W
mat4 retMat = mat4( 1.0, 0.0, 0.0, 0.0,
0.0, cos(myAngle), -sin(myAngle), 0.0,
0.0, sin(myAngle), cos(myAngle), 0.0,
0.0, 0.0, 0.0, 1.0 );
// TODO: create matrix representing rotation around X axis
// Hint: use circle equation in parametric form
// X column should remain constant - YZ unit vectors represent desired change of base vectors
// STUDENTS CODE END //
return retMat;
}
// Vertex shader entry point
void main()
{
// Copy vertex
vec4 tmpV = gl_Vertex;
// STUDENTS CODE //
// TODO: Create blended cone animation using vertices with Z > 1.0
// Step one: create rotation matrices: one should represent rotation and the other should be identity matrix
// We will blend vertex rotation between them
mat4 matOne = makeXRotMat(bendAngle);
// Step two: calculate blending coefficient - we start bending if given vertex tmpV has Z coordinate greater than 1.0
// Cone has height of 4.0 units (Z axis), so coefficient should be calculated for Z in range from 1.0 to 4.0
// and result should be between 0.0 and 1.0
// Hint: use function clamp(val_to_clamp, min, max);
// float coeff = ...
float coeff = clamp((tmpV.z - 1)/3, 0, 1);
// Step three: alter only vertices with Z coordinate greater than 1.0
// Hint: You can access tmpV like a structure - tmpV.x, tmpV.y, tmpV.z
// Hint: tmpV must be translated to the origin in Z axis before transformation, since center of rotation will be in the origin
// Hint: matrices can be blended using regular multiplication operations - blendedMat = coeffN1 * matN1 + coeffN2 * matN2 + ...
// Hint: sum of coeffN1 + coeffN2 + ... must be equal to 1.0
// Hint: after altering tmpV with blendMat (tmpV = tmpV * blendMat; or tmpV *= blendMat), remember to translate tmpV back in Z axis!
if(tmpV.z > 1.0) {
tmpV.z -= 1.0;
tmpV *= (coeff*matOne + (1f-coeff)*mat4(1f));
tmpV.z += 1.0;
}
// STUDENTS CODE END //
// tmpV now contains final position in model space..
// Transforming The Vertex
v = vec3(gl_ModelViewMatrix * tmpV);
N = normalize(gl_NormalMatrix * gl_Normal);
gl_Position = gl_ModelViewProjectionMatrix * tmpV;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}