![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Example of using "Canvas" form "Graphics" library to display 3D graphics.
Dependencies: BSP_DISCO_F746NG Graphics mbed
Models/Pyramid.cpp@3:aca7fe2d44b3, 2016-11-11 (annotated)
- Committer:
- karpent
- Date:
- Fri Nov 11 17:06:53 2016 +0000
- Revision:
- 3:aca7fe2d44b3
New 3d models added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
karpent | 3:aca7fe2d44b3 | 1 | // |
karpent | 3:aca7fe2d44b3 | 2 | // Pyramid.cpp - example of usage graphics commands to create 3D graphics. |
karpent | 3:aca7fe2d44b3 | 3 | // |
karpent | 3:aca7fe2d44b3 | 4 | // This example is based on code written by |
karpent | 3:aca7fe2d44b3 | 5 | // Fabio de Albuquerque Dela Antonio (fabio914 at gmail.com) |
karpent | 3:aca7fe2d44b3 | 6 | // See : https://github.com/fabio914/arduinogl/blob/master/examples |
karpent | 3:aca7fe2d44b3 | 7 | // |
karpent | 3:aca7fe2d44b3 | 8 | |
karpent | 3:aca7fe2d44b3 | 9 | #include "Pyramid.h" |
karpent | 3:aca7fe2d44b3 | 10 | |
karpent | 3:aca7fe2d44b3 | 11 | // Constructor |
karpent | 3:aca7fe2d44b3 | 12 | Pyramid::Pyramid(Display * display) : Model() |
karpent | 3:aca7fe2d44b3 | 13 | { |
karpent | 3:aca7fe2d44b3 | 14 | glUseCanvas(display); |
karpent | 3:aca7fe2d44b3 | 15 | } |
karpent | 3:aca7fe2d44b3 | 16 | |
karpent | 3:aca7fe2d44b3 | 17 | /** |
karpent | 3:aca7fe2d44b3 | 18 | * @brief Model setup. |
karpent | 3:aca7fe2d44b3 | 19 | * @retval None |
karpent | 3:aca7fe2d44b3 | 20 | */ |
karpent | 3:aca7fe2d44b3 | 21 | void Pyramid::Setup() |
karpent | 3:aca7fe2d44b3 | 22 | { |
karpent | 3:aca7fe2d44b3 | 23 | SetFixedScaleMode(2.5); |
karpent | 3:aca7fe2d44b3 | 24 | |
karpent | 3:aca7fe2d44b3 | 25 | glPointSize(4); |
karpent | 3:aca7fe2d44b3 | 26 | |
karpent | 3:aca7fe2d44b3 | 27 | glMatrixMode(GL_PROJECTION); |
karpent | 3:aca7fe2d44b3 | 28 | glLoadIdentity(); |
karpent | 3:aca7fe2d44b3 | 29 | |
karpent | 3:aca7fe2d44b3 | 30 | gluPerspective(30.0, 1.7647f, 0.1f, 9999.f); |
karpent | 3:aca7fe2d44b3 | 31 | |
karpent | 3:aca7fe2d44b3 | 32 | glMatrixMode(GL_MODELVIEW); |
karpent | 3:aca7fe2d44b3 | 33 | } |
karpent | 3:aca7fe2d44b3 | 34 | |
karpent | 3:aca7fe2d44b3 | 35 | /** |
karpent | 3:aca7fe2d44b3 | 36 | * @brief Renders a model for given view angle and scale. |
karpent | 3:aca7fe2d44b3 | 37 | * @param None |
karpent | 3:aca7fe2d44b3 | 38 | * @retval None |
karpent | 3:aca7fe2d44b3 | 39 | */ |
karpent | 3:aca7fe2d44b3 | 40 | void Pyramid::Render() |
karpent | 3:aca7fe2d44b3 | 41 | { |
karpent | 3:aca7fe2d44b3 | 42 | float scale = GetScaleValue(); |
karpent | 3:aca7fe2d44b3 | 43 | |
karpent | 3:aca7fe2d44b3 | 44 | glLoadIdentity(); |
karpent | 3:aca7fe2d44b3 | 45 | gluLookAt(10, 8, -10, 0, 0, 0, 0, 1, 0); |
karpent | 3:aca7fe2d44b3 | 46 | |
karpent | 3:aca7fe2d44b3 | 47 | glRotatef(GetAngleValue(), 0.f, 1.f, 0.f); |
karpent | 3:aca7fe2d44b3 | 48 | glScalef(scale, scale, scale); |
karpent | 3:aca7fe2d44b3 | 49 | |
karpent | 3:aca7fe2d44b3 | 50 | DrawModel(); |
karpent | 3:aca7fe2d44b3 | 51 | } |
karpent | 3:aca7fe2d44b3 | 52 | |
karpent | 3:aca7fe2d44b3 | 53 | |
karpent | 3:aca7fe2d44b3 | 54 | |
karpent | 3:aca7fe2d44b3 | 55 | void Pyramid::DrawModel() |
karpent | 3:aca7fe2d44b3 | 56 | { |
karpent | 3:aca7fe2d44b3 | 57 | |
karpent | 3:aca7fe2d44b3 | 58 | /* 3 triangles instead of 4 */ |
karpent | 3:aca7fe2d44b3 | 59 | glBegin(GL_TRIANGLE_STRIP); |
karpent | 3:aca7fe2d44b3 | 60 | glVertex3f(-1, -1, -1); |
karpent | 3:aca7fe2d44b3 | 61 | glVertex3f(1, -1, -1); |
karpent | 3:aca7fe2d44b3 | 62 | glVertex3f(0, 1, 0); |
karpent | 3:aca7fe2d44b3 | 63 | glVertex3f(1, -1, 1); |
karpent | 3:aca7fe2d44b3 | 64 | glVertex3f(-1, -1, 1); |
karpent | 3:aca7fe2d44b3 | 65 | glEnd(); |
karpent | 3:aca7fe2d44b3 | 66 | |
karpent | 3:aca7fe2d44b3 | 67 | glBegin(GL_POLYGON); |
karpent | 3:aca7fe2d44b3 | 68 | glVertex3f(-1, -1, 1); |
karpent | 3:aca7fe2d44b3 | 69 | glVertex3f(1, -1, 1); |
karpent | 3:aca7fe2d44b3 | 70 | glVertex3f(1, -1, -1); |
karpent | 3:aca7fe2d44b3 | 71 | glVertex3f(-1, -1, -1); |
karpent | 3:aca7fe2d44b3 | 72 | glEnd(); |
karpent | 3:aca7fe2d44b3 | 73 | } |