For some strange reason the way I calculate the normals on my cube spazzes the cube out. I do not know whether it’s the normal itself or I’m doing it wrong.
This is what the cube looks like when I comment out the method used: http://prntscr.com/fe0plv
Here’s what it looks like when I don’t comment it out: http://prntscr.com/fe0pv5
Here’s the Vertex Data (Min and Max are variables):
float vertexData[] = {
min.x_, min.y_, min.z_, 0.0f, 0.0f, 0.0f,
min.x_ + max.x_, min.y_, min.z_, 0.0f, 0.0f, 0.0f,
min.x_ + max.x_, min.y_ + max.y_, min.z_, 0.0f, 0.0f, 0.0f,
min.x_, min.y_ + max.y_, min.z_, 0.0f, 0.0f, 0.0f,
min.x_, min.y_, min.z_ + max.z_, 0.0f, 0.0f, 0.0f,
min.x_ + max.x_, min.y_, min.z_ + max.z_, 0.0f, 0.0f, 0.0f,
min.x_ + max.x_, min.y_ + max.y_, min.z_ + max.z_, 0.0f, 0.0f, 0.0f,
min.x_, min.y_ + max.y_, min.z_ + max.z_, 0.0f, 0.0f, 0.0f
};
Here’s the way I calculate normals (The way in the sample glitches out too so I tried a different way, still doesn’t work):
for (unsigned int i = 0; i < 48; i += 6) {
ur::Vector3 normal({ vertexData[i], vertexData[i + 1], vertexData[i + 2] });
normal.Normalize();
vertexData[(i + 3)] = normal.x_;
vertexData[(i + 3) + 1] = normal.y_;
vertexData[(i + 3) + 3] = normal.z_;
}
ur::SharedPtr<Model> model(new ur::Model(context_));
ur::SharedPtr<ur::VertexBuffer> vb(new ur::VertexBuffer(context_));
ur::SharedPtr<ur::IndexBuffer> ib(new ur::IndexBuffer(context_));
ur::SharedPtr<ur::Geometry> geom(new ur::Geometry(context_));
vb->SetShadowed(true);
ur::PODVector<ur::VertexElement> elements;
elements.Push(ur::VertexElement(ur::TYPE_VECTOR3, ur::SEM_POSITION));
elements.Push(ur::VertexElement(ur::TYPE_VECTOR3, ur::SEM_NORMAL));
The rest of the code is self-explanatory but I also apply the NoTextureVCol Technique.
There doesn’t seem to be any problem in the code that I’m aware of so I’m not sure what’s wrong.