Top Banner

Click here to load reader

Animator Help Session

Mar 18, 2016

ReportDownload

Documents

iden

Animator Help Session. Surface of Revolution. You will write OpenGL code to draw a surface by rotating a curve. Each vertex must have an appropriate: Texture coordinate pair Vertex normal Position Replace code for drawRevolution() in modelerdraw.cpp - PowerPoint PPT Presentation

  • Animator Help Session

  • Surface of RevolutionYou will write OpenGL code to draw a surface by rotating a curve.Each vertex must have an appropriate:Texture coordinate pairVertex normalPositionReplace code for drawRevolution() in modelerdraw.cppThe divisions variable determines number of slicesLoad new curve with File->Load Revolution Curve File

  • How to startDrawing a curveUsing the curve editor toolStart by left click with ctrl key onSave dense point samples into .apts fileLoad point samples in modeler

  • Curve file formatA curve file is basically a .txt file with a list of x,y coordinates for control points.aptsDensely sampled points on a curve.cfg: curve configuration fileRow 1: sample densityRow 2: curve interpolation method

  • Slicing it into Triangle StripsDivide the surface into bands by longitudeCompute vertex positions and normalsUsing sin(), cos() in c++ codeSee lecture notes for normal computationConnect the dots with OpenGL triangles

  • Connecting dots in a modern wayUse glDrawElements with GL_TRIANGLES (required!)The order of vertices mattersRight-hand rule

  • Connecting dotsIts okay to use glBegin(), glEnd() for testing shapes, but dont use them in the final submitted codeDont use GL_QUAD_STRIP or GL_TRIANGLE_STRIP in the final submission, either. In the submitted code, you need to build a triangle mesh and send it to OpenGLUsing glDrawElements with GL_TRIANGLES

  • An ExampleThis is an overly simplified example of drawing a plane using glDrawElements. The plane consists of two connecting triangles and the normal vectors of all vertices are pointing up.// preparing the data for the vertices positionsGLfloat vertices[12] = { 0,0,0, 0,0,-1, 1,0,0, 1,0,-1 };// normal directionsGLfloat normals[12] = {0,1,0, 0,1,0, 0,1,0, 0,1,0};// texture coordinateGLfloat texture_uv[8] = {0,0, 0,1, 1,0, 1,1};// vertex indices to form triangles, the order of the vertices follows the right hand ruleGLuint indices[6] = { 1,0,2, 1,2,3 }int indices_length = 6;glEnableClientState(GL_VERTEX_ARRAY);glEnableClientState(GL_NORMAL_ARRAY);glEnableClientState(GL_TEXTURE_COORD_ARRAY);glVertexPointer(3, GL_FLOAT, 0, vertices);glNormalPointer(GL_FLOAT,0,normals);glTexCoordPointer(2,GL_FLOAT,0,texture_uv);glDrawElements(GL_TRIANGLES, indices_length,GL_UNSIGNED_INT, indices);glDisableClientState(GL_TEXTURE_COORD_ARRAY);glDisableClientState(GL_NORMAL_ARRAY);glDisableClientState(GL_VERTEX_ARRAY);

  • Texture MappingSee lecture slides for texture mappingBasic idea: use longitude and arc length (curve distance) as texture coordinatesEach vertex must have an appropriate:Vertex normalPositionTexture Coordinate Pairu,v [0,1]

  • Part 2: Hierarchical ModelingYou must make a character with:2 levels of branchingSomething drawn at each levelMeaningful controlsOtherwise, you will be overwhelmed when you animate it!You will need to:Extend the Model classOverride the draw() methodAdd properties that Modeler users can controlGive an instance of your class to ModelerUserInterface in the main() function

  • Building a Scene of your ownIn sample.cpp, the Scene class extends Modeldraw() method draws the green floor, sphere, and cylinder, etc.Add and replace drawing commands of your own

    You can use these draw commands as OpenGL referencesModelerdraw.cppdrawBoxdrawCylinderdrawRevolution

  • Add a radio button for your sceneAdd a new radio button for your scene at the end of the list

  • Add Properties to Control ItKinds of properties (in properties.h):BooleanProperty = checkboxRangeProperty = sliderRGBProperty = colorChoiceProperty = radio buttonsNeed to add it to:Class definitionConstructorProperty listSee sample.cpp for example

  • OpenGL Is A State MachineglEnable()/glDisable() changes stateOnce you change something, it stays that way until you change it to something newOpenGLs state includes:Current colorTransformation matricesDrawing modes Light sources

  • OpenGLs Transformation MatrixJust two of them: projection and modelview. Well modify modelview.Matrix applied to all vertices and normalsThese functions multiply transformations: glRotated(), glTranslated(), glScaled()Applies transformations in REVERSE order from the order in which they are called.Transformations are cumulative. Since theyre all squashed into one matrix, you cant undo a transformation.

  • Transformations: Going BackHow do we get back to an earlier transformation matrix?We can remember itOpenGL maintains a stack of matrices.To store the current matrix, call glPushMatrix().To restore the last matrix you stored, call glPopMatrix().

  • Hierarchical Modeling in OpenGLDraw the bodyUse glPushMatrix() to remember the current matrix.Imagine that a matrix corresponds to a set of coordinate axes:By changing your matrix, you can move, rotate, and scale the axes OpenGL uses.

  • Hierarchical Modeling in OpenGLApply a transform:glRotated()glTranslated()glScaled()Here, we apply glTranslated(1.5,2,0)All points translated 1.5 units left and 2 units upIts as if we moved our coordinate axes!

  • Hierarchical Modeling in OpenGLDraw an ear.This ear thinks it was drawn at the origin.Transformations let us transform objects without changing their geometry!We didnt have to edit that ears drawing commands to transform it

  • Hierarchical Modeling in OpenGLCall glPopMatrix() to return to the bodys coordinate axes.To draw the other ear, call glPushMatrix() again

  • Hierarchical Modeling in OpenGLApply another transformWhere will the ear be drawn now?

  • Hierarchical Modeling in OpenGLDraw the other ear

  • Hierarchical Modeling in OpenGLThen, call glPopMatrix() to return to the bodys axesTechnically, you dont need to if that second ear is the last thing you draw.But what if you wanted to add something else to the body?

  • Rule: A Pop For Every PushMake sure theres a glPopMatrix() for every glPushMatrix()!You can divide your draw() function into a series of nested methods, each with a push at the beginning and a pop at the end.

  • Levels of BranchingYour scene must have two levels of branching like in this diagram.Circles are objectsArrows are transformationsCall glPushMatrix() for green, so you can draw orange after drawing redDo the same for orangeYou must draw something at each level.

  • Multiple-Joint SliderNeeds to control multiple aspects of your model.Example: Rotate multiple joints at onceDont get too complicated!Wait for Animator in four weeks!

  • Part 3. Blinn-Phong ShaderWe provide a directional light shader in OpenGL Shading Language (GLSL)You must extend it to support point lights.Files to edit:shader.frag your fragment shadershader.vert your vertex shader

  • Useful GLSL Variablesgl_LightSource[i].position.xyz the position of light source i.gl_FrontLightProduct[i] object that stores the product of a lights properties with the current surfaces material properties:Example: gl_FrontLightProduct[i].diffuse == gl_FrontMaterial.diffuse * gl_LightSource[i].diffuse

  • Part 4. Your Custom ShaderAnything you want!Can earn extra credit!Ask TAs for estimated extra credit value of an option.See the OpenGL orange book in the lab for details + code.Can still use sample solution to test (depending on complexity)

    WarningsDont modify any files except your model file and the required modificationsOr, your model might not work in Animator (project 4)

  • Part 4. Your Custom Shader

  • Curve ImplementationWhat are all those vectors?In any specific curveEvaluator classptvCtrlPts: a collection of control points that you specify in the curve editorptvEvaluatedCurvePts: a collection of evaluated curve points that you return from the function calculated using the curve types formulasfAniLength: maximum time that a curve is definedbWrap: a flag indicating whether or not the curve should be wrapped

  • Curve ImplementationWhere should I put things?Create curve evaluator classes for each that inherit from CurveEvaluatorBezierB-splineCatmull-RomIn GraphWidget classChange the skeleton to call your new constructors in the GraphWidget class.

  • Particle SystemRequirementsParticle System classShould have pointers to all particles and a marching variable (time) for simulationIf you have two separate simulations (say, cloth sim and particles that respond to viscous drag) you may want to make that distinction here (as well as in your force and particle implementationSolver In the skeleton, this actually exists within the Particle System classParticles

  • Particle SystemRequirementsTwo distinct forcesDistinct may mean forces whose values are calculated with different equations (gravity and drag are distinct because gravity eq is of form f=ma, where drag is defined in terms of a drag coefficient and velocity)Alternatively (and better): distinct may mean that one force is a unary force and another is a n-ary force or spacially driven forceConnect to Hierarchical model

  • Particle SystemWhat should I implement?Canonical components ConstructorDestructoretcSimulation functionsdrawParticles()startSimulation()computeForcesAndUpdateParticles()stopSimulation()

  • Particle SystemWhat should I implement?Particle struct or classyou may have several of these if you have multiple types of simulationsIf this is the case, take advantage of inheritanceForce classAn elegant implementation would include a generic Force class and a variety of distinct forces that inherit from it

  • Particle SystemEmbedding in your hierarchyNeed to find World Coordinates of Particles- Model View Matrix- Inverse Camera Transformation- Generate world coordinate for particles by undoing camera transformations to the point yo