Advertisement
Guest User

cpp file

a guest
Aug 23rd, 2016
121
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.88 KB | None
  1. /*
  2.   ==============================================================================
  3.  
  4.   This is an automatically generated GUI class created by the Introjucer!
  5.  
  6.   Be careful when adding custom code to these files, as only the code within
  7.   the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
  8.   and re-saved.
  9.  
  10.   Created with Introjucer version: 3.1.1
  11.  
  12.   ------------------------------------------------------------------------------
  13.  
  14.   The Introjucer is part of the JUCE library - "Jules' Utility Class Extensions"
  15.   Copyright 2004-13 by Raw Material Software Ltd.
  16.  
  17.   ==============================================================================
  18. */
  19.  
  20. //[Headers] You can add your own extra header files here...
  21. //[/Headers]
  22.  
  23. #include "HeadAnimation.h"
  24.  
  25.  
  26. //[MiscUserDefs] You can add your own user definitions and misc code here...
  27. //[/MiscUserDefs]
  28.  
  29. //==============================================================================
  30. HeadAnimation::HeadAnimation () : doBackgroundDrawing(false),
  31. scale(0.5f), rotationSpeed(0.0f), rotation(0.0f),
  32. textureToUse(nullptr), lastTexture(nullptr)
  33. {
  34.  
  35.     //[UserPreSize]
  36.     //[/UserPreSize]
  37.  
  38.     setSize (600, 400);
  39.  
  40.  
  41.     //[Constructor] You can add your own custom stuff here..
  42.  
  43.     const TopLevelWindow* tlw = TopLevelWindow::getTopLevelWindow(0);
  44.     //tlw->setRenderingEngine(0);
  45.  
  46.     //setOpaque(true);
  47.     //addAndMakeVisible(controlsOverlay = new DemoControlsOverlay(*this));
  48.  
  49.     openGLContext.setRenderer(this);
  50.     openGLContext.attachTo(*this);
  51.     openGLContext.setContinuousRepainting(true);
  52.  
  53.     //openGLContext.setRenderer(this);
  54.  
  55.  
  56.     textures.add(new BuiltInTexture("Portmeirion", BinaryData::portmeirion_jpg, BinaryData::portmeirion_jpgSize));
  57.     DemoTexture* t = textures[0];
  58.     setTexture(t);
  59.  
  60.     scale = 1;
  61.  
  62.     String vertex =
  63.         "attribute vec4 position;\n"
  64.         "attribute vec4 sourceColour;\n"
  65.         "attribute vec2 textureCoordIn;\n"
  66.         "\n"
  67.         "varying vec4 destinationColour;\n"
  68.         "varying vec2 textureCoordOut;\n"
  69.         "\n"
  70.         "void main()\n"
  71.         "{\n"
  72.         "    destinationColour = sourceColour;\n"
  73.         "    textureCoordOut = textureCoordIn;\n"
  74.         "    gl_Position = position;\n"
  75.         "}\n";
  76.  
  77.     String fragment =
  78. #if JUCE_OPENGL_ES
  79.         "varying lowp vec4 destinationColour;\n"
  80.         "varying lowp vec2 textureCoordOut;\n"
  81. #else
  82.         "varying vec4 destinationColour;\n"
  83.         "varying vec2 textureCoordOut;\n"
  84. #endif
  85.         "\n"
  86.         "uniform sampler2D demoTexture;\n"
  87.         "void main()\n"
  88.         "{\n"
  89.         "   gl_FragColor = destinationColour; \n"
  90.         "   gl_FragColor = texture2D (demoTexture, textureCoordOut);"
  91.         "}\n";
  92.  
  93.  
  94.     //String vertext = "attribute vec4 position;attribute vec4 normal;attribute vec4 sourceColour;attribute vec2 texureCoordIn;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform vec4 lightPosition;varying vec4 destinationColour;varying vec2 textureCoordOut;varying float lightIntensity;void main(){    destinationColour = sourceColour;    textureCoordOut = texureCoordIn;    vec4 light = viewMatrix * lightPosition;    lightIntensity = dot (light, normal);    gl_Position = projectionMatrix * viewMatrix * position;}";
  95.     //String fragment = "varying vec4 destinationColour;varying vec2 textureCoordOut;varying float lightIntensity;uniform sampler2D demoTexture;void main(){   float l = max (0.3, lightIntensity * 0.3);   vec4 colour = vec4 (l, l, l, 1.0);    gl_FragColor = colour * texture2D (demoTexture, textureCoordOut);}";
  96.  
  97.     setShaderProgram(vertex, fragment);
  98.  
  99.     doBackgroundDrawing = false;
  100.  
  101.     //controlsOverlay->initialise();
  102.  
  103.  
  104.     //[/Constructor]
  105. }
  106.  
  107. HeadAnimation::~HeadAnimation()
  108. {
  109.     //[Destructor_pre]. You can add your own custom destruction code here..
  110.     //[/Destructor_pre]
  111.  
  112.  
  113.  
  114.     //[Destructor]. You can add your own custom destruction code here..
  115.     //[/Destructor]
  116. }
  117.  
  118. //==============================================================================
  119. void HeadAnimation::paint (Graphics& g)
  120. {
  121.     //[UserPrePaint] Add your own custom painting code here..
  122.     //[/UserPrePaint]
  123.  
  124.     //g.fillAll (Colour (0xffaaaaaa));
  125.  
  126.     //[UserPaint] Add your own custom painting code here..
  127.     //[/UserPaint]
  128. }
  129.  
  130. void HeadAnimation::resized()
  131. {
  132.     //[UserPreResize] Add your own custom resize code here..
  133.     //[/UserPreResize]
  134.  
  135.     //[UserResized] Add your own custom resize handling here..
  136.     //[/UserResized]
  137. }
  138.  
  139.  
  140.  
  141. //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
  142.  
  143.  
  144.  
  145.  
  146. struct DynamicTexture : public DemoTexture
  147. {
  148.     DynamicTexture() { name = "Dynamically-generated texture"; }
  149.  
  150.     Image image;
  151.     BouncingNumber x, y;
  152.  
  153.     bool applyTo(OpenGLTexture& texture) override
  154.     {
  155.         const int size = 128;
  156.  
  157.         if (!image.isValid())
  158.             image = Image(Image::ARGB, size, size, true);
  159.  
  160.         {
  161.             Graphics g(image);
  162.             g.fillAll(Colours::lightcyan);
  163.  
  164.             g.setColour(Colours::darkred);
  165.             g.drawRect(0, 0, size, size, 2);
  166.  
  167.             g.setColour(Colours::green);
  168.             g.fillEllipse(x.getValue() * size * 0.9f, y.getValue() * size * 0.9f, size * 0.1f, size * 0.1f);
  169.  
  170.             g.setColour(Colours::black);
  171.             g.setFont(40);
  172.             g.drawFittedText(String(Time::getCurrentTime().getMilliseconds()), image.getBounds(), Justification::centred, 1);
  173.         }
  174.  
  175.         texture.loadImage(image);
  176.         return true;
  177.     }
  178. };
  179.  
  180.  
  181.  
  182. struct TextureFromFile : public DemoTexture
  183. {
  184.     TextureFromFile(const File& file)
  185.     {
  186.         name = file.getFileName();
  187.         image = resizeImageToPowerOfTwo(ImageFileFormat::loadFrom(file));
  188.     }
  189.  
  190.     Image image;
  191.  
  192.     bool applyTo(OpenGLTexture& texture) override
  193.     {
  194.         texture.loadImage(image);
  195.         return false;
  196.     }
  197. };
  198.  
  199. struct Vertex
  200. {
  201.     float position[3];
  202.     float normal[3];
  203.     float colour[4];
  204.     float texCoord[2];
  205. };
  206.  
  207. struct Attributes
  208. {
  209.     Attributes(OpenGLContext& openGLContext, OpenGLShaderProgram& shader)
  210.     {
  211.         position = createAttribute(openGLContext, shader, "position");
  212.         normal = createAttribute(openGLContext, shader, "normal");
  213.         sourceColour = createAttribute(openGLContext, shader, "sourceColour");
  214.         texureCoordIn = createAttribute(openGLContext, shader, "texureCoordIn");
  215.     }
  216.  
  217.     void enable(OpenGLContext& openGLContext)
  218.     {
  219.         if (position != nullptr)
  220.         {
  221.             openGLContext.extensions.glVertexAttribPointer(position->attributeID, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
  222.             openGLContext.extensions.glEnableVertexAttribArray(position->attributeID);
  223.         }
  224.  
  225.         if (normal != nullptr)
  226.         {
  227.             openGLContext.extensions.glVertexAttribPointer(normal->attributeID, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(float) * 3));
  228.             openGLContext.extensions.glEnableVertexAttribArray(normal->attributeID);
  229.         }
  230.  
  231.         if (sourceColour != nullptr)
  232.         {
  233.             openGLContext.extensions.glVertexAttribPointer(sourceColour->attributeID, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(float) * 6));
  234.             openGLContext.extensions.glEnableVertexAttribArray(sourceColour->attributeID);
  235.         }
  236.  
  237.         if (texureCoordIn != nullptr)
  238.         {
  239.             openGLContext.extensions.glVertexAttribPointer(texureCoordIn->attributeID, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(float) * 10));
  240.             openGLContext.extensions.glEnableVertexAttribArray(texureCoordIn->attributeID);
  241.         }
  242.     }
  243.  
  244.     void disable(OpenGLContext& openGLContext)
  245.     {
  246.         if (position != nullptr)       openGLContext.extensions.glDisableVertexAttribArray(position->attributeID);
  247.         if (normal != nullptr)         openGLContext.extensions.glDisableVertexAttribArray(normal->attributeID);
  248.         if (sourceColour != nullptr)   openGLContext.extensions.glDisableVertexAttribArray(sourceColour->attributeID);
  249.         if (texureCoordIn != nullptr)  openGLContext.extensions.glDisableVertexAttribArray(texureCoordIn->attributeID);
  250.     }
  251.  
  252.     ScopedPointer<OpenGLShaderProgram::Attribute> position, normal, sourceColour, texureCoordIn;
  253.  
  254. private:
  255.     static OpenGLShaderProgram::Attribute* createAttribute(OpenGLContext& openGLContext,
  256.         OpenGLShaderProgram& shader,
  257.         const char* attributeName)
  258.     {
  259.         if (openGLContext.extensions.glGetAttribLocation(shader.getProgramID(), attributeName) < 0)
  260.             return nullptr;
  261.  
  262.         return new OpenGLShaderProgram::Attribute(shader, attributeName);
  263.     }
  264. };
  265.  
  266. struct Uniforms
  267. {
  268.     Uniforms(OpenGLContext& openGLContext, OpenGLShaderProgram& shader)
  269.     {
  270.         projectionMatrix = createUniform(openGLContext, shader, "projectionMatrix");
  271.         viewMatrix = createUniform(openGLContext, shader, "viewMatrix");
  272.         texture = createUniform(openGLContext, shader, "demoTexture");
  273.         lightPosition = createUniform(openGLContext, shader, "lightPosition");
  274.         bouncingNumber = createUniform(openGLContext, shader, "bouncingNumber");
  275.     }
  276.  
  277.     ScopedPointer<OpenGLShaderProgram::Uniform> projectionMatrix, viewMatrix, texture, lightPosition, bouncingNumber;
  278.  
  279. private:
  280.     static OpenGLShaderProgram::Uniform* createUniform(OpenGLContext& openGLContext,
  281.         OpenGLShaderProgram& shader,
  282.         const char* uniformName)
  283.     {
  284.         if (openGLContext.extensions.glGetUniformLocation(shader.getProgramID(), uniformName) < 0)
  285.             return nullptr;
  286.  
  287.         return new OpenGLShaderProgram::Uniform(shader, uniformName);
  288.     }
  289. };
  290.  
  291. struct Shape
  292. {
  293.     Shape(OpenGLContext& openGLContext)
  294.     {
  295.         if (shapeFile.load(BinaryData::teapot_obj).wasOk())
  296.             for (int i = 0; i < shapeFile.shapes.size(); ++i)
  297.                 vertexBuffers.add(new VertexBuffer(openGLContext, *shapeFile.shapes.getUnchecked(i)));
  298.  
  299.     }
  300.  
  301.     void draw(OpenGLContext& openGLContext, Attributes& attributes)
  302.     {
  303.         for (int i = 0; i < vertexBuffers.size(); ++i)
  304.         {
  305.             VertexBuffer& vertexBuffer = *vertexBuffers.getUnchecked(i);
  306.             vertexBuffer.bind();
  307.  
  308.             attributes.enable(openGLContext);
  309.             glDrawElements(GL_TRIANGLES, vertexBuffer.numIndices, GL_UNSIGNED_INT, 0);
  310.             attributes.disable(openGLContext);
  311.         }
  312.     }
  313.  
  314. private:
  315.     struct VertexBuffer
  316.     {
  317.         VertexBuffer(OpenGLContext& context, WavefrontObjFile::Shape& shape) : openGLContext(context)
  318.         {
  319.             numIndices = shape.mesh.indices.size();
  320.  
  321.             openGLContext.extensions.glGenBuffers(1, &vertexBuffer);
  322.             openGLContext.extensions.glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
  323.  
  324.             Array<Vertex> vertices;
  325.             createVertexListFromMesh(shape.mesh, vertices, Colours::green);
  326.  
  327.             openGLContext.extensions.glBufferData(GL_ARRAY_BUFFER, vertices.size() * (int) sizeof(Vertex),
  328.                 vertices.getRawDataPointer(), GL_STATIC_DRAW);
  329.  
  330.             openGLContext.extensions.glGenBuffers(1, &indexBuffer);
  331.             openGLContext.extensions.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
  332.             openGLContext.extensions.glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices * (int) sizeof(juce::uint32),
  333.                 shape.mesh.indices.getRawDataPointer(), GL_STATIC_DRAW);
  334.         }
  335.  
  336.         ~VertexBuffer()
  337.         {
  338.             openGLContext.extensions.glDeleteBuffers(1, &vertexBuffer);
  339.             openGLContext.extensions.glDeleteBuffers(1, &indexBuffer);
  340.         }
  341.  
  342.         void bind()
  343.         {
  344.             openGLContext.extensions.glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
  345.             openGLContext.extensions.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
  346.         }
  347.  
  348.         GLuint vertexBuffer, indexBuffer;
  349.         int numIndices;
  350.         OpenGLContext& openGLContext;
  351.  
  352.         JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VertexBuffer)
  353.     };
  354.  
  355.     WavefrontObjFile shapeFile;
  356.     OwnedArray<VertexBuffer> vertexBuffers;
  357.  
  358.     static void createVertexListFromMesh(const WavefrontObjFile::Mesh& mesh, Array<Vertex>& list, Colour colour)
  359.     {
  360.         const float scale = 0.2f;
  361.         WavefrontObjFile::TextureCoord defaultTexCoord = { 0.5f, 0.5f };
  362.         WavefrontObjFile::Vertex defaultNormal = { 0.5f, 0.5f, 0.5f };
  363.  
  364.         for (int i = 0; i < mesh.vertices.size(); ++i)
  365.         {
  366.             const WavefrontObjFile::Vertex& v = mesh.vertices.getReference(i);
  367.  
  368.             const WavefrontObjFile::Vertex& n
  369.                 = i < mesh.normals.size() ? mesh.normals.getReference(i) : defaultNormal;
  370.  
  371.             const WavefrontObjFile::TextureCoord& tc
  372.                 = i < mesh.textureCoords.size() ? mesh.textureCoords.getReference(i) : defaultTexCoord;
  373.  
  374.             Vertex vert =
  375.             {
  376.                 { scale * v.x, scale * v.y, scale * v.z, },
  377.                 { scale * n.x, scale * n.y, scale * n.z, },
  378.                 { colour.getFloatRed(), colour.getFloatGreen(), colour.getFloatBlue(), colour.getFloatAlpha() },
  379.                 { tc.x, tc.y }
  380.             };
  381.  
  382.             list.add(vert);
  383.         }
  384.     }
  385. };
  386.  
  387. //void HeadAnimation::selectTexture(int itemID)
  388. //{
  389. //  if (itemID == 1000)
  390. //  {
  391. //      static File lastLocation = File::getSpecialLocation(File::userPicturesDirectory);
  392. //
  393. //      FileChooser fc("Choose an image to open...", lastLocation, "*.jpg;*.jpeg;*.png;*.gif");
  394. //
  395. //      if (fc.browseForFileToOpen())
  396. //      {
  397. //          lastLocation = fc.getResult();
  398. //
  399. //          textures.add(new TextureFromFile(fc.getResult()));
  400. //          updateTexturesList();
  401. //
  402. //          textureBox.setSelectedId(textures.size());
  403. //      }
  404. //  }
  405. //  else
  406. //  {
  407. //      if (DemoTexture* t = textures[itemID - 1])
  408. //          demo.setTexture(t);
  409. //  }
  410. //}
  411.  
  412. void HeadAnimation::setShaderProgram(const String& vertexShader, const String& fragmentShader)
  413. {
  414.     newVertexShader = vertexShader;
  415.     newFragmentShader = fragmentShader;
  416. }
  417.  
  418. void HeadAnimation::setTexture(DemoTexture* t)
  419. {
  420.     lastTexture = textureToUse = t;
  421. }
  422.  
  423. void HeadAnimation::drawBackground2DStuff(float desktopScale)
  424. {
  425.     // Create an OpenGLGraphicsContext that will draw into this GL window..
  426.     ScopedPointer<LowLevelGraphicsContext> glRenderer(createOpenGLGraphicsContext(openGLContext,
  427.         roundToInt(desktopScale * getWidth()),
  428.         roundToInt(desktopScale * getHeight())));
  429.  
  430.     if (glRenderer != nullptr)
  431.     {
  432.         Graphics g(*glRenderer);
  433.         g.addTransform(AffineTransform::scale(desktopScale));
  434.  
  435.         for (int i = 0; i < numElementsInArray(stars); ++i)
  436.         {
  437.             float size = 0.25f;
  438.  
  439.             // This stuff just creates a spinning star shape and fills it..
  440.             Path p;
  441.             p.addStar(Point<float>(getWidth() * stars[i].x.getValue(),
  442.                 getHeight() * stars[i].y.getValue()), 7,
  443.                 getHeight() * size * 0.5f,
  444.                 getHeight() * size,
  445.                 stars[i].angle.getValue());
  446.  
  447.             float hue = stars[i].hue.getValue();
  448.  
  449.             g.setGradientFill(ColourGradient(Colours::green.withRotatedHue(hue).withAlpha(0.8f),
  450.                 0, 0,
  451.                 Colours::red.withRotatedHue(hue).withAlpha(0.5f),
  452.                 0, (float)getHeight(), false));
  453.             g.fillPath(p);
  454.         }
  455.     }
  456. }
  457.  
  458. void HeadAnimation::updateShader()
  459. {
  460.     if (newVertexShader.isNotEmpty() || newFragmentShader.isNotEmpty())
  461.     {
  462.         ScopedPointer<OpenGLShaderProgram> newShader(new OpenGLShaderProgram(openGLContext));
  463.         String statusText;
  464.  
  465.         if (newShader->addVertexShader(OpenGLHelpers::translateVertexShaderToV3(newVertexShader))
  466.             && newShader->addFragmentShader(OpenGLHelpers::translateFragmentShaderToV3(newFragmentShader))
  467.             && newShader->link())
  468.         {
  469.             shape = nullptr;
  470.             attributes = nullptr;
  471.             uniforms = nullptr;
  472.  
  473.             shader = newShader;
  474.             shader->use();
  475.  
  476.  
  477.             shape = new Shape(openGLContext);
  478.             attributes = new Attributes(openGLContext, *shader);
  479.             uniforms = new Uniforms(openGLContext, *shader);
  480.  
  481.             statusText = "GLSL: v" + String(OpenGLShaderProgram::getLanguageVersion(), 2);
  482.         }
  483.         else
  484.         {
  485.             statusText = newShader->getLastError();
  486.         }
  487.  
  488.         //controlsOverlay->statusLabel.setText(statusText, dontSendNotification);
  489.  
  490.  
  491.         newVertexShader = String::empty;
  492.         newFragmentShader = String::empty;
  493.     }
  494. }
  495.  
  496. void HeadAnimation::renderOpenGL()
  497. {
  498.     jassert(OpenGLHelpers::isContextActive());
  499.  
  500.     const float desktopScale = (float)openGLContext.getRenderingScale();
  501.     OpenGLHelpers::clear(Colours::lightblue);
  502.  
  503.     if (textureToUse != nullptr)
  504.     {
  505.         if (!textureToUse->applyTo(texture))
  506.         {
  507.             textureToUse = nullptr;
  508.         }
  509.     }
  510.  
  511.     // First draw our background graphics to demonstrate the OpenGLGraphicsContext class
  512.     if (doBackgroundDrawing)
  513.         drawBackground2DStuff(desktopScale);
  514.  
  515.     updateShader();   // Check whether we need to compile a new shader
  516.  
  517.     if (shader == nullptr)
  518.         return;
  519.  
  520.     // Having used the juce 2D renderer, it will have messed-up a whole load of GL state, so
  521.     // we need to initialise some important settings before doing our normal GL 3D drawing..
  522.     glEnable(GL_DEPTH_TEST);
  523.     glDepthFunc(GL_LESS);
  524.     glEnable(GL_BLEND);
  525.     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  526.     openGLContext.extensions.glActiveTexture(GL_TEXTURE0);
  527.     glEnable(GL_TEXTURE_2D);
  528.  
  529.     glViewport(0, 0, roundToInt(desktopScale * getWidth()), roundToInt(desktopScale * getHeight()));
  530.  
  531.     texture.bind();
  532.  
  533.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  534.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  535.  
  536.     shader->use();
  537.  
  538.     if (uniforms->projectionMatrix != nullptr)
  539.         uniforms->projectionMatrix->setMatrix4(getProjectionMatrix().mat, 1, false);
  540.  
  541.     if (uniforms->viewMatrix != nullptr)
  542.         uniforms->viewMatrix->setMatrix4(getViewMatrix().mat, 1, false);
  543.  
  544.     if (uniforms->texture != nullptr)
  545.         uniforms->texture->set((GLint)0);
  546.  
  547.     if (uniforms->lightPosition != nullptr)
  548.         uniforms->lightPosition->set(-15.0f, 10.0f, 15.0f, 0.0f);
  549.  
  550.     if (uniforms->bouncingNumber != nullptr)
  551.         uniforms->bouncingNumber->set(bouncingNumber.getValue());
  552.  
  553.     shape->draw(openGLContext, *attributes);
  554.  
  555.     // Reset the element buffers so child Components draw correctly
  556.     openGLContext.extensions.glBindBuffer(GL_ARRAY_BUFFER, 0);
  557.     openGLContext.extensions.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  558.  
  559.  
  560.     rotation += (float)rotationSpeed;
  561. }
  562.  
  563. void HeadAnimation::newOpenGLContextCreated()
  564. {
  565.     // nothing to do in this case - we'll initialise our shaders + textures
  566.     // on demand, during the render callback.
  567.     freeAllContextObjects();
  568.  
  569.     //if (controlsOverlay != nullptr)   controlsOverlay->updateShader();
  570. }
  571.  
  572. void HeadAnimation::openGLContextClosing()
  573. {
  574.     // When the context is about to close, you must use this callback to delete
  575.     // any GPU resources while the context is still current.
  576.     freeAllContextObjects();
  577.  
  578.     //if (lastTexture != nullptr)   setTexture(lastTexture);
  579. }
  580.  
  581. void HeadAnimation::freeAllContextObjects()
  582. {
  583.     shape = nullptr;
  584.     shader = nullptr;
  585.     attributes = nullptr;
  586.     uniforms = nullptr;
  587.     texture.release();
  588. }
  589.  
  590. Matrix3D<float> HeadAnimation::getProjectionMatrix() const
  591. {
  592.     float w = 1.0f / (scale + 0.1f);
  593.     float h = w * getLocalBounds().toFloat().getAspectRatio(false);
  594.     return Matrix3D<float>::fromFrustum(-w, w, -h, h, 4.0f, 30.0f);
  595. }
  596.  
  597. Matrix3D<float> HeadAnimation::getViewMatrix() const
  598. {
  599.     Matrix3D<float> viewMatrix = draggableOrientation.getRotationMatrix()
  600.         * Vector3D<float>(0.0f, 1.0f, -10.0f);
  601.  
  602.     Matrix3D<float> rotationMatrix = viewMatrix.rotated(Vector3D<float>(rotation, rotation, -0.3f));
  603.  
  604.     return rotationMatrix * viewMatrix;
  605. }
  606.  
  607. //[/MiscUserCode]
  608.  
  609.  
  610. //==============================================================================
  611. #if 0
  612. /*  -- Introjucer information section --
  613.  
  614.     This is where the Introjucer stores the metadata that describe this GUI layout, so
  615.     make changes in here at your peril!
  616.  
  617. BEGIN_JUCER_METADATA
  618.  
  619. <JUCER_COMPONENT documentType="Component" className="HeadAnimation" componentName=""
  620.                  parentClasses="public CPIComponent, private OpenGLRenderer" constructorParams=""
  621.                  variableInitialisers="" snapPixels="8" snapActive="1" snapShown="1"
  622.                  overlayOpacity="0.330" fixedSize="0" initialWidth="600" initialHeight="400">
  623.   <BACKGROUND backgroundColour="ffaaaaaa"/>
  624. </JUCER_COMPONENT>
  625.  
  626. END_JUCER_METADATA
  627. */
  628. #endif
  629.  
  630.  
  631. //[EndFile] You can add extra defines here...
  632. //[/EndFile]
Advertisement
RAW Paste Data Copied
Advertisement