will try some openGL on android
This commit is contained in:
48
main.cpp
48
main.cpp
@@ -1,9 +1,12 @@
|
|||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QGridLayout>
|
||||||
|
|
||||||
#include "sensors/SensorFactory.h"
|
#include "sensors/SensorFactory.h"
|
||||||
|
#include "map/MapView.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -25,27 +28,42 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
// test();
|
//// test();
|
||||||
LeListener listener;
|
// LeListener listener;
|
||||||
WiFiSensor& wifi = SensorFactory::getWiFi();
|
// WiFiSensor& wifi = SensorFactory::getWiFi();
|
||||||
wifi.addListener(&listener);
|
// wifi.addListener(&listener);
|
||||||
wifi.start();
|
// wifi.start();
|
||||||
|
|
||||||
// AccelerometerSensor& acc = SensorFactory::getAccelerometer();
|
//// AccelerometerSensor& acc = SensorFactory::getAccelerometer();
|
||||||
// acc.addListener(&listener);
|
//// acc.addListener(&listener);
|
||||||
// acc.start();
|
//// acc.start();
|
||||||
|
|
||||||
StepSensor& steps = SensorFactory::getSteps();
|
// StepSensor& steps = SensorFactory::getSteps();
|
||||||
steps.addListener(&listener);
|
// steps.addListener(&listener);
|
||||||
steps.start();;
|
// steps.start();;
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(10000));
|
// std::this_thread::sleep_for(std::chrono::seconds(10000));
|
||||||
|
|
||||||
// QGuiApplication app(argc, argv);
|
//QGuiApplication app(argc, argv);
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
QMainWindow* win = new QMainWindow();
|
||||||
|
|
||||||
|
QVBoxLayout* lay = new QVBoxLayout();
|
||||||
|
win->setLayout(lay);
|
||||||
|
|
||||||
|
MapView* map = new MapView(win);
|
||||||
|
lay->addWidget(map);
|
||||||
|
map->setMinimumHeight(200);
|
||||||
|
map->setMinimumWidth(200);
|
||||||
|
|
||||||
|
win->setMinimumWidth(400);
|
||||||
|
win->setMinimumHeight(400);
|
||||||
|
win->show();
|
||||||
|
|
||||||
// QQmlApplicationEngine engine;
|
// QQmlApplicationEngine engine;
|
||||||
// engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
// engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
||||||
|
|
||||||
// return app.exec();
|
return app.exec();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
82
map/MapView.cpp
Normal file
82
map/MapView.cpp
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
#include "MapView.h"
|
||||||
|
|
||||||
|
|
||||||
|
MapView::MapView(QWidget* parent) : QGLWidget(parent) {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
void MapView::initializeGL() {
|
||||||
|
|
||||||
|
qglClearColor(Qt::black);
|
||||||
|
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
glShadeModel(GL_SMOOTH);
|
||||||
|
glEnable(GL_LIGHTING);
|
||||||
|
glEnable(GL_LIGHT0);
|
||||||
|
|
||||||
|
static GLfloat lightPosition[4] = { 0, 0, 10, 1.0 };
|
||||||
|
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapView::paintGL() {
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
glLoadIdentity();
|
||||||
|
glTranslatef(0.0, 0.0, -10.0);
|
||||||
|
glRotatef(20 / 16.0, 1.0, 0.0, 0.0);
|
||||||
|
glRotatef(30 / 16.0, 0.0, 1.0, 0.0);
|
||||||
|
glRotatef(60 / 16.0, 0.0, 0.0, 1.0);
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapView::resizeGL(int width, int height) {
|
||||||
|
int side = qMin(width, height);
|
||||||
|
glViewport((width - side) / 2, (height - side) / 2, side, side);
|
||||||
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
#ifdef QT_OPENGL_ES_1
|
||||||
|
glOrthof(-2, +2, -2, +2, 1.0, 15.0);
|
||||||
|
#else
|
||||||
|
glOrtho(-2, +2, -2, +2, 1.0, 15.0);
|
||||||
|
#endif
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapView::draw()
|
||||||
|
{
|
||||||
|
qglColor(Qt::red);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glNormal3f(0,0,-1);
|
||||||
|
glVertex3f(-1,-1,0);
|
||||||
|
glVertex3f(-1,1,0);
|
||||||
|
glVertex3f(1,1,0);
|
||||||
|
glVertex3f(1,-1,0);
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
glBegin(GL_TRIANGLES);
|
||||||
|
glNormal3f(0,-1,0.707);
|
||||||
|
glVertex3f(-1,-1,0);
|
||||||
|
glVertex3f(1,-1,0);
|
||||||
|
glVertex3f(0,0,1.2);
|
||||||
|
glEnd();
|
||||||
|
glBegin(GL_TRIANGLES);
|
||||||
|
glNormal3f(1,0, 0.707);
|
||||||
|
glVertex3f(1,-1,0);
|
||||||
|
glVertex3f(1,1,0);
|
||||||
|
glVertex3f(0,0,1.2);
|
||||||
|
glEnd();
|
||||||
|
glBegin(GL_TRIANGLES);
|
||||||
|
glNormal3f(0,1,0.707);
|
||||||
|
glVertex3f(1,1,0);
|
||||||
|
glVertex3f(-1,1,0);
|
||||||
|
glVertex3f(0,0,1.2);
|
||||||
|
glEnd();
|
||||||
|
glBegin(GL_TRIANGLES);
|
||||||
|
glNormal3f(-1,0,0.707);
|
||||||
|
glVertex3f(-1,1,0);
|
||||||
|
glVertex3f(-1,-1,0);
|
||||||
|
glVertex3f(0,0,1.2);
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
26
map/MapView.h
Normal file
26
map/MapView.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef MAPVIEW_H
|
||||||
|
#define MAPVIEW_H
|
||||||
|
|
||||||
|
#include <QGLWidget>
|
||||||
|
|
||||||
|
class MapView : public QGLWidget {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
MapView(QWidget* parent = 0);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
void initializeGL();
|
||||||
|
|
||||||
|
void paintGL();
|
||||||
|
|
||||||
|
void resizeGL(int width, int height);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void draw();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MAPVIEW_H
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
|
||||||
QT += qml
|
QT += qml opengl
|
||||||
|
|
||||||
# android?
|
# android?
|
||||||
#QT += androidextras sensors
|
#QT += androidextras sensors
|
||||||
@@ -20,6 +20,7 @@ OTHER_FILES += \
|
|||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
|
map/MapView.cpp
|
||||||
|
|
||||||
RESOURCES += qml.qrc
|
RESOURCES += qml.qrc
|
||||||
|
|
||||||
@@ -48,7 +49,8 @@ HEADERS += \
|
|||||||
sensors/WiFiSensor.h \
|
sensors/WiFiSensor.h \
|
||||||
misc/Debug.h \
|
misc/Debug.h \
|
||||||
misc/fixc11.h \
|
misc/fixc11.h \
|
||||||
sensors/dummy/WiFiSensorDummy.h
|
sensors/dummy/WiFiSensorDummy.h \
|
||||||
|
map/MapView.h
|
||||||
|
|
||||||
DISTFILES += \
|
DISTFILES += \
|
||||||
android-sources/src/MyActivity.java
|
android-sources/src/MyActivity.java
|
||||||
|
|||||||
Reference in New Issue
Block a user