Exemple #1
0
Matrix4 Matrix4::operator=(Matrix4 mat4)
{
	float* tmp = mat4.getData();
	for(int i = 0; i < 16; i++)
		mData[i] = tmp[i];
	return *this;
}
Exemple #2
0
void RenderEngine::renderAll() {
	ShaderTextureRenderOpMap::iterator opIter;
	for(opIter = _renderOps.begin(); opIter != _renderOps.end(); ++opIter) {
		_programs[opIter->first].use();

		Matrix4 projection;
		projection.setOrtho(-(int)_settings.getWindowWidth() / 2.0f, _settings.getWindowWidth() / 2.0f,
			-(int)_settings.getWindowHeight() / 2.0f, _settings.getWindowHeight() / 2.0f, 0.0f, 100.0f);
		glUniformMatrix4fv(_uniforms[opIter->first].projection, 1, GL_TRUE, projection.getData());

		Matrix4 camera;
		glUniformMatrix4fv(_uniforms[opIter->first].modelview, 1, GL_TRUE, camera.getData());

		TextureRenderOpMap::iterator texIter;
		for(texIter = opIter->second.begin(); texIter != opIter->second.end(); ++texIter) {
			if(texIter->first) {
				float texsize[2] = {texIter->first->getWidth() * 1.0f, texIter->first->getHeight() * 1.0f};
				glUniform2fv(_uniforms[opIter->first].texsize, 1, texsize);

				glActiveTexture(GL_TEXTURE0);
				glBindTexture(GL_TEXTURE_2D, texIter->first->getID());
				glUniform1i(_uniforms[opIter->first].texture, 0);
			}

			std::vector<RenderOperation*>& op = texIter->second;
			for(unsigned int i = 0; i < op.size(); ++i) {
				if(op[i]->getUpdateElements() && op[i]->getUpdateVertices()) {
					op[i]->update();
				} else if(op[i]->getUpdateElements()) {
					op[i]->updateElements();
				} else if(op[i]->getUpdateVertices()) {
					op[i]->updateVertices();
				} 

				glBindVertexArray(op[i]->getVAO());
				glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, op[i]->getIBO());
				glDrawElements(GL_TRIANGLES, op[i]->getElementCount(), GL_UNSIGNED_INT, reinterpret_cast<void*>(0));
			}
		}
	}
}
Exemple #3
0
Matrix4 Matrix4::operator*(const Matrix4& mat4) const
{
	Matrix4 tmp;
	const float* matData = mat4.getData();
	float tmpData[16];
	tmpData[0]  = (mData[0] * matData[0])  + (mData[4] * matData[1])  + (mData[8]  * matData[2])  + (mData[12] * matData[3]);
	tmpData[1]  = (mData[1] * matData[0])  + (mData[5] * matData[1])  + (mData[9]  * matData[2])  + (mData[13] * matData[3]);
	tmpData[2]  = (mData[2] * matData[0])  + (mData[6] * matData[1])  + (mData[10] * matData[2])  + (mData[14] * matData[3]);
	tmpData[3]  = (mData[3] * matData[0])  + (mData[7] * matData[1])  + (mData[11] * matData[2])  + (mData[15] * matData[3]);
	tmpData[4]  = (mData[0] * matData[4])  + (mData[4] * matData[5])  + (mData[8]  * matData[6])  + (mData[12] * matData[7]);
	tmpData[5]  = (mData[1] * matData[4])  + (mData[5] * matData[5])  + (mData[9]  * matData[6])  + (mData[13] * matData[7]);
	tmpData[6]  = (mData[2] * matData[4])  + (mData[6] * matData[5])  + (mData[10] * matData[6])  + (mData[14] * matData[7]);
	tmpData[7]  = (mData[3] * matData[4])  + (mData[7] * matData[5])  + (mData[11] * matData[6])  + (mData[15] * matData[7]);
	tmpData[8]  = (mData[0] * matData[8])  + (mData[4] * matData[9])  + (mData[8]  * matData[10]) + (mData[12] * matData[11]);
	tmpData[9]  = (mData[1] * matData[8])  + (mData[5] * matData[9])  + (mData[9]  * matData[10]) + (mData[13] * matData[11]);
	tmpData[10] = (mData[2] * matData[8])  + (mData[6] * matData[9])  + (mData[10] * matData[10]) + (mData[14] * matData[11]);
	tmpData[11] = (mData[3] * matData[8])  + (mData[7] * matData[9])  + (mData[11] * matData[10]) + (mData[15] * matData[11]);
	tmpData[12] = (mData[0] * matData[12]) + (mData[4] * matData[13]) + (mData[8]  * matData[14]) + (mData[12] * matData[15]);
	tmpData[13] = (mData[1] * matData[12]) + (mData[5] * matData[13]) + (mData[9]  * matData[14]) + (mData[13] * matData[15]);
	tmpData[14] = (mData[2] * matData[12]) + (mData[6] * matData[13]) + (mData[10] * matData[14]) + (mData[14] * matData[15]);
	tmpData[15] = (mData[3] * matData[12]) + (mData[7] * matData[13]) + (mData[11] * matData[14]) + (mData[15] * matData[15]);
	tmp.setData(tmpData);
	return tmp;
}