1

我的代码适用于我纯粹的过剩实现,但我正试图让它在 qt 中工作。

我有一个用于金属丝网系统的质点向量

std::vector<masspoint> m_particles; 

问题是在我的 qt 版本中,我写的东西都没有真正坚持,我留下了一个零数组。基本上我很困惑为什么 glut 版本具有正确的值,但 qt 并没有给出它基本上是相同的代码。qt代码有什么问题?

是的,我在使用 qDebug 时只看到零。当我在 qt 版本中调用我的绘图函数时,所有组件中的所有顶点都变为 0,因此什么也看不到。

int myboog = 1;
int county = 0;
// Constructors
Cloth::Cloth(float width, float height, int particles_in_width, int particles_in_height):
m_width(particles_in_width),
m_height(particles_in_height),
m_dimensionWidth(width),
m_dimensionHeight(height),
m_distanceX(width/(float)particles_in_width),
m_distanceY(height/(float)particles_in_height)
{

    //Set the particle array to the given size
    //Height by width

    //mparticles is the name of our vector
    m_particles.resize(m_width*m_height);
    qDebug() << m_particles.size();

    // Create the point masses to simulate the cloth
    for (int x = 0; x < m_width; ++x)
    {
        for (int y=0; y < m_height; ++y)
        {
            // Place the pointmass of the cloth, lift the edges to give the wind more effect as the cloth falls
            Vector3f position = Vector3f(m_dimensionWidth * (x / (float)m_width),
                                         ((x==0)||(x==m_width-1)||(y==0)||(y==m_height-1)) ? m_distanceY/2.0f:0,
                                         m_dimensionHeight * (y / (float)m_height));

            // The gravity effect is applied to new pmasspoints
            m_particles[y * m_width + x] = masspoint(position,Vector3f(0,-0.06,0));

        }

    }

    int num = (int)m_particles.size();
    for (int i=0; i<num; ++i)
    {
        masspoint* p = &m_particles[i];
        if(myboog)
        {
            qDebug() << "test " <<  *p->getPosition().getXLocation() << county;
            county++;
        }
    }
    myboog = 0;

    // Calculate the normals for the first time so the initial draw is correctly lit
    calculateClothNormals();
}

CLoth 的构造函数中涉及的质量点代码

#ifndef MASSPOINT_H
#define MASSPOINT_H
#include <QGLWidget>
#include "vector3f.h"
class masspoint
{


private:
Vector3f m_position;                // Current Location of the pointmass
Vector3f m_velocity;                // Direction and speed the pointmass is traveling in

Vector3f m_acceleration;            // Speed at which the pointmass is accelerating (used for gravity)
Vector3f m_forceAccumulated;        // Force that has been accumulated since the last update
Vector3f m_normal;                  // Normal of this pointmass, used to light the cloth when drawing



float m_damping;                    // Amount of velocity lost per update
bool m_stationary;                  // Whether this pointmass is currently capible of movement

public:

masspoint& operator= (const masspoint& particle);


//Some constructors
masspoint();
masspoint(const masspoint& particle);
masspoint(Vector3f position, Vector3f acceleration);


//Like eulur integration
void integrate(float duration);



// Accessor functions

//Get the position of the point mass
inline Vector3f getPosition() const {return m_position;}

CLoth 的构造函数中涉及的向量内容

#ifndef VECTOR3F_H
#define VECTOR3F_H

#include <math.h>

// Vector library to be used
class Vector3f
{
private:
    float m_x, m_y, m_z;
public:
     const float* getXLocation() const { return &m_x; }
4

0 回答 0