Reputation: 25
I use this code
MazeScene::MazeScene(const QVector<Light> &lights, mazeData m, int width, int height)
: m_lights(lights)
, m_walkingVelocity(0)
, m_strafingVelocity(0)
, m_turningSpeed(0)
, m_pitchSpeed(0)
, m_deltaYaw(0)
, m_deltaPitch(0)
, m_simulationTime(0)
, m_walkTime(0)
, m_width(width)
, m_height(height)
, m_player(0)
, m_accelerated(false)
{
m_camera.setPos(QPointF(1.5, 1.5));
m_camera.setYaw(0.1);
m_doorAnimation = new QTimeLine(1000, this);
m_doorAnimation->setUpdateInterval(20);
connect(m_doorAnimation, SIGNAL(valueChanged(qreal)), this, SLOT(moveDoors(qreal)));
// qDebug() << "MazeScene constructor";
m.display();
QMap<char, int> types;
types[' '] = -2;
types['-'] = -1;
types['#'] = 0;
QString line="\n";
for (int x = 0; x < height; ++x) {
for (int y = 0; y < width; ++y) {
if(m.getValue(x,y)==1) addWall(QPointF(x, y), QPointF(x+1, y), 0);
if(m.getValue(x,y)==1) addWall(QPointF(x+1, y+1), QPointF(x, y+1), 0);
if(m.getValue(x,y)==1) addWall(QPointF(x, y+1), QPointF(x, y), 0);
if(m.getValue(x,y)==1) addWall(QPointF(x+1, y), QPointF(x+1, y+1), 0);
if(m.getValue(x,y)==3) addWall(QPointF(x, y), QPointF(x+1, y), -1);
if(m.getValue(x,y)==3) addWall(QPointF(x+1, y+1), QPointF(x, y+1), -1);
if(m.getValue(x,y)==3) addWall(QPointF(x, y+1), QPointF(x, y), -1);
if(m.getValue(x,y)==3) addWall(QPointF(x+1, y), QPointF(x+1, y+1), -1);
if(m.getValue(x,y)==4) addWall(QPointF(x, y), QPointF(x+1, y), 1);
if(m.getValue(x,y)==4) addWall(QPointF(x+1, y+1), QPointF(x, y+1), 1);
if(m.getValue(x,y)==4) addWall(QPointF(x, y+1), QPointF(x, y), 1);
if(m.getValue(x,y)==4) addWall(QPointF(x+1, y), QPointF(x+1, y+1), 1);
if(m.getValue(x,y)==1) line=line+"#";
else line=line+".";
}
line= line + "\n";
}
//qDebug() << line;
QTimer *timer = new QTimer(this);
timer->setInterval(20);
timer->start();
connect(timer, SIGNAL(timeout()), this, SLOT(move()));
etimer.start();
// START
//m_time.start();
updateTransforms();
updateRenderer();
m_walkingItem = new WalkingItem(this);
//m_walkingItem->scale(0.008, 0.008);
m_walkingItem->setZValue(100000);
addItem(m_walkingItem);
}
I use this code in the constructor for walls
void MazeScene::addWall(const QPointF &a, const QPointF &b, int type)
{
WallItem *item = new WallItem(this, a, b, type);
#ifdef USE_PHONON
if (item->childItem() && item->type() == 7) {
m_playerPos = (a + b ) / 2;
m_player = static_cast<MediaPlayer *>(item->childItem()->widget());
}
#endif
#if 0
QGraphicsProxyWidget *proxy = item->childItem();
QWebView *view = proxy ? qobject_cast<QWebView *>(proxy->widget()) : 0;
if (view) {
connect(view, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished()));
proxy->setVisible(false);
}
#endif
item->setVisible(false);
addProjectedItem(item);
m_walls << item;
if (type == -1)
m_doors << item;
setSceneRect(-1, -1, 2, 2);
if (item->childItem()) {
QObject *widget = item->childItem()->widget()->children().value(0);
QPushButton *button = qobject_cast<QPushButton *>(widget);
if (button)
m_buttons << button;
}
}
To draw walls with OpenGL but left and right are inverted
On the 2D map with 0 and 1 I have to turn left and on the 3D OpenGL view I have to turn right.
I want to change OpenGL Code to turn left.
The src and bin of the project is available there :
https://sourceforge.net/projects/qmazegen/files/qMazeGen-QT6-SRC-BIN.zip/
The maze is working same walls and paths but maybe a transform to visit 3D view like the 2D map.
Upvotes: -3
Views: 26