parent
edeec37d01
commit
b6af60f08c
|
@ -30,6 +30,9 @@ Camera rotate/zoom implemented, [here](http://www.songho.ca/opengl/gl_transform.
|
||||||
Added x,z axis, looks better than last screenshot.
|
Added x,z axis, looks better than last screenshot.
|
||||||
I have to use the GLU library, the previous implementation of drawSphere and drawCylinder looks not good, and take too much time to debug.
|
I have to use the GLU library, the previous implementation of drawSphere and drawCylinder looks not good, and take too much time to debug.
|
||||||
<img src="screenshot/dust3d_node_edge_with_glu.png">
|
<img src="screenshot/dust3d_node_edge_with_glu.png">
|
||||||
|
*B-Mesh data struct*
|
||||||
|
I created the test nodes's geometry information from Blender. Here is the render result of `data/bmesh_test_1.h`
|
||||||
|
<img src="screenshot/dust3d_bmesh_nodes.png">
|
||||||
- [ ] Export Wavefront .obj
|
- [ ] Export Wavefront .obj
|
||||||
- [ ] Render B-Mesh result
|
- [ ] Render B-Mesh result
|
||||||
- [ ] Design UI for monster parts configuration
|
- [ ] Design UI for monster parts configuration
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1,12 @@
|
||||||
|
const float bmeshTest1Nodes[][4] = {
|
||||||
|
{0, -2.07575, 1.53902, 0.04122}, {1, 2.40837, 2.34882, 0.48585},
|
||||||
|
{2, -0.91403, 0.77069, 0.62299}, {3, 2.25224, 0.74973, 0.85115},
|
||||||
|
{4, 0, 0, 0},
|
||||||
|
{5, 0.00920, -0.66115, -2.04601},
|
||||||
|
{6, 0.01726, -0.88224, -2.87471}
|
||||||
|
};
|
||||||
|
|
||||||
|
const int bmeshTest1Edges[][2] = {
|
||||||
|
{0, 2}, {2, 4}, {4, 3}, {3, 1},
|
||||||
|
{4, 5}, {5, 6}
|
||||||
|
};
|
Binary file not shown.
After Width: | Height: | Size: 153 KiB |
14
src/draw.cpp
14
src/draw.cpp
|
@ -3,11 +3,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#ifdef __APPLE__
|
#include <stdarg.h>
|
||||||
#include <OpenGL/glu.h>
|
|
||||||
#else
|
|
||||||
#include <GL/glu.h>
|
|
||||||
#endif
|
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
|
|
||||||
static GLUquadricObj *quadricId = 0;
|
static GLUquadricObj *quadricId = 0;
|
||||||
|
@ -92,3 +88,11 @@ int drawGrid(float size, float step) {
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int drawPrintf(int x, int y, const char *fmt, ...) {
|
||||||
|
va_list args;
|
||||||
|
char text[1024];
|
||||||
|
va_start(args, fmt);
|
||||||
|
vsnprintf(text, sizeof(text), fmt, args);
|
||||||
|
return drawText(x, y, text);
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
#ifndef DRAW_SPHERE_H
|
#ifndef DRAW_SPHERE_H
|
||||||
#define DRAW_SPHERE_H
|
#define DRAW_SPHERE_H
|
||||||
#include "vector3d.h"
|
#include "vector3d.h"
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <OpenGL/glu.h>
|
||||||
|
#else
|
||||||
|
#include <GL/glu.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -21,6 +26,8 @@ void drawTriangle(triangle *poly);
|
||||||
int drawCylinder(vec3 *topOrigin, vec3 *bottomOrigin, float radius, int slices,
|
int drawCylinder(vec3 *topOrigin, vec3 *bottomOrigin, float radius, int slices,
|
||||||
int stacks);
|
int stacks);
|
||||||
int drawGrid(float size, float step);
|
int drawGrid(float size, float step);
|
||||||
|
int drawText(int x, int y, char *text);
|
||||||
|
int drawPrintf(int x, int y, const char *fmt, ...);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include "bmesh.h"
|
#include "bmesh.h"
|
||||||
#include "matrix.h"
|
#include "matrix.h"
|
||||||
|
|
||||||
|
static QGLWidget *_this = 0;
|
||||||
|
|
||||||
static int drawBmeshNode(bmesh *bm, bmeshNode *node) {
|
static int drawBmeshNode(bmesh *bm, bmeshNode *node) {
|
||||||
float color1[3] = {1, 0, 0};
|
float color1[3] = {1, 0, 0};
|
||||||
glColor3fv(color1);
|
glColor3fv(color1);
|
||||||
|
@ -15,7 +17,7 @@ static int drawBmeshNode(bmesh *bm, bmeshNode *node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int drawBmeshEdge(bmesh *bm, bmeshEdge *edge) {
|
static int drawBmeshEdge(bmesh *bm, bmeshEdge *edge) {
|
||||||
float color2[3] = {0, 0, 1};
|
float color2[3] = {1, 1, 0};
|
||||||
glColor3fv(color2);
|
glColor3fv(color2);
|
||||||
bmeshNode *firstNode = bmeshGetNode(bm, edge->firstNode);
|
bmeshNode *firstNode = bmeshGetNode(bm, edge->firstNode);
|
||||||
bmeshNode *secondNode = bmeshGetNode(bm, edge->secondNode);
|
bmeshNode *secondNode = bmeshGetNode(bm, edge->secondNode);
|
||||||
|
@ -23,6 +25,11 @@ static int drawBmeshEdge(bmesh *bm, bmeshEdge *edge) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int drawText(int x, int y, char *text) {
|
||||||
|
_this->renderText(x, y, QString(text));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Render::Render(QWidget *parent)
|
Render::Render(QWidget *parent)
|
||||||
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent) {
|
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent) {
|
||||||
QTimer *timer = new QTimer(this);
|
QTimer *timer = new QTimer(this);
|
||||||
|
@ -31,8 +38,8 @@ Render::Render(QWidget *parent)
|
||||||
|
|
||||||
mouseX = 0;
|
mouseX = 0;
|
||||||
mouseY = 0;
|
mouseY = 0;
|
||||||
cameraAngleX = 45;
|
cameraAngleX = 20;
|
||||||
cameraAngleY = -45;
|
cameraAngleY = -225;
|
||||||
cameraDistance = 3;
|
cameraDistance = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +50,14 @@ void Render::initializeGL() {
|
||||||
glShadeModel(GL_SMOOTH);
|
glShadeModel(GL_SMOOTH);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glEnable(GL_LIGHTING);
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
qglClearColor(QWidget::palette().color(QWidget::backgroundRole()));
|
qglClearColor(QWidget::palette().color(QWidget::backgroundRole()));
|
||||||
|
glClearStencil(0);
|
||||||
glClearDepth(1.0f);
|
glClearDepth(1.0f);
|
||||||
|
|
||||||
GLfloat ambientLight[] = {0.0f, 0.0f, 0.0f, 1.0f};
|
GLfloat ambientLight[] = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
|
@ -61,26 +74,22 @@ void Render::initializeGL() {
|
||||||
|
|
||||||
float shininess = 64.0f;
|
float shininess = 64.0f;
|
||||||
float specularColor[] = {1.0, 1.0f, 1.0f, 1.0f};
|
float specularColor[] = {1.0, 1.0f, 1.0f, 1.0f};
|
||||||
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess); // range 0 ~ 128
|
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specularColor);
|
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specularColor);
|
||||||
|
|
||||||
glClearStencil(0);
|
|
||||||
glClearDepth(1.0f);
|
|
||||||
glDepthFunc(GL_LEQUAL);
|
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
glEnable(GL_LIGHTING);
|
|
||||||
glEnable(GL_CULL_FACE);
|
|
||||||
|
|
||||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
||||||
glEnable(GL_COLOR_MATERIAL);
|
glEnable(GL_COLOR_MATERIAL);
|
||||||
|
|
||||||
drawInit();
|
drawInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "../data/bmesh_test_1.h"
|
||||||
|
|
||||||
void Render::paintGL() {
|
void Render::paintGL() {
|
||||||
static bmesh *bm = 0;
|
static bmesh *bm = 0;
|
||||||
|
|
||||||
|
_this = this;
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
@ -89,6 +98,10 @@ void Render::paintGL() {
|
||||||
glRotatef(cameraAngleX, 1, 0, 0);
|
glRotatef(cameraAngleX, 1, 0, 0);
|
||||||
glRotatef(cameraAngleY, 0, 1, 0);
|
glRotatef(cameraAngleY, 0, 1, 0);
|
||||||
|
|
||||||
|
glColor3f(0, 0, 0);
|
||||||
|
drawPrintf(0, 10, "cameraAngleX:%f cameraAngleY:%f", cameraAngleX,
|
||||||
|
cameraAngleY);
|
||||||
|
|
||||||
drawGrid(10, 1);
|
drawGrid(10, 1);
|
||||||
|
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
|
@ -96,27 +109,25 @@ void Render::paintGL() {
|
||||||
if (0 == bm) {
|
if (0 == bm) {
|
||||||
bmeshNode node;
|
bmeshNode node;
|
||||||
bmeshEdge edge;
|
bmeshEdge edge;
|
||||||
|
int i;
|
||||||
bm = bmeshCreate();
|
bm = bmeshCreate();
|
||||||
|
|
||||||
|
for (i = 0; i < sizeof(bmeshTest1Nodes) / sizeof(bmeshTest1Nodes[0]); ++i) {
|
||||||
memset(&node, 0, sizeof(node));
|
memset(&node, 0, sizeof(node));
|
||||||
node.position.x = 0;
|
node.position.x = bmeshTest1Nodes[i][1];
|
||||||
node.position.y = 0;
|
node.position.y = bmeshTest1Nodes[i][2];
|
||||||
node.position.z = 3;
|
node.position.z = bmeshTest1Nodes[i][3];
|
||||||
node.radius = 0.5;
|
node.radius = 0.35;
|
||||||
bmeshAddNode(bm, &node);
|
|
||||||
|
|
||||||
memset(&node, 0, sizeof(node));
|
|
||||||
node.position.x = 1;
|
|
||||||
node.position.y = 0;
|
|
||||||
node.position.z = 2;
|
|
||||||
node.radius = 0.5;
|
|
||||||
bmeshAddNode(bm, &node);
|
bmeshAddNode(bm, &node);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < sizeof(bmeshTest1Edges) / sizeof(bmeshTest1Edges[0]); ++i) {
|
||||||
memset(&edge, 0, sizeof(edge));
|
memset(&edge, 0, sizeof(edge));
|
||||||
edge.firstNode = 1;
|
edge.firstNode = bmeshTest1Edges[i][0];
|
||||||
edge.secondNode = 0;
|
edge.secondNode = bmeshTest1Edges[i][1];
|
||||||
bmeshAddEdge(bm, &edge);
|
bmeshAddEdge(bm, &edge);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
|
@ -138,7 +149,7 @@ void Render::resizeGL(int w, int h) {
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glFrustum(-2, 2, -1.5, 1.5, 1, 100);
|
gluPerspective(60.0f, w/(h/2.0f), 1, 100);
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
Loading…
Reference in New Issue