// RotateToMap returns a rotation map which rotates fromVec to have the // same direction as toVec. // fromVec and toVec should be unit vectors RotationMapR3 RotateToMap(const VectorR3& fromVec, const VectorR3& toVec) { VectorR3 crossVec = fromVec; crossVec *= toVec; double sintheta = crossVec.Norm(); double costheta = fromVec ^ toVec; if (sintheta <= 1.0e-40) { if (costheta > 0.0) { return (RotationMapR3( 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)); } else { GetOrtho(toVec, crossVec); // Get arbitrary orthonormal vector return (VrRotate(costheta, sintheta, crossVec)); } } else { crossVec /= sintheta; // Normalize the vector return (VrRotate(costheta, sintheta, crossVec)); } }
void SpriteBatch_GL3::Begin() { m_processingRender = true; m_currentIndex = 0; m_currentVert = 0; m_currentTextureID = 0; m_numFlushes = 0; //RenderTexture *renderTexture = m_pApplication->GetRenderTarget(); // //unsigned int viewWidth = ( renderTexture != nullptr ) ? renderTexture->GetWidth() : m_pApplication->GetWindowWidth(); //unsigned int viewHeight = ( renderTexture != nullptr ) ? renderTexture->GetHeight() : m_pApplication->GetWindowHeight(); unsigned int viewWidth = m_pApplication->GetViewWidth(); unsigned int viewHeight = m_pApplication->GetViewHeight(); //GetOrtho(m_projection, 0.0f, (float)viewWidth, (float)viewHeight, 0.0f, -1.0f, 100.0f); GetOrtho(m_projection, m_fCameraX, m_fCameraX + (float)viewWidth, m_fCameraY + (float)viewHeight, m_fCameraY, -1.0f, 100.0f); glUseProgram( m_shader ); glUniformMatrix4fv( glGetUniformLocation(m_shader, "u_projection"), 1, false, m_projection ); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); SetRenderColor(0xFFFFFFFF); }
void GetOrtho( const VectorR4& u, const VectorR4& v, const VectorR4& s, RotationMapR4& rotmat ) { rotmat.SetColumn1(u); rotmat.SetColumn2(v); rotmat.SetColumn3(s); GetOrtho( 3, rotmat ); }
void SpriteBatch_GL3::End() { if (m_processingRender == false) return; FlushBatch(); glUseProgram(0); m_processingRender = false; unsigned int viewWidth = m_pApplication->GetWindowWidth(); unsigned int viewHeight = m_pApplication->GetWindowHeight(); // resetup the projection and view //GetOrtho(m_projection, 0.0f, (float)viewWidth, (float)viewHeight, 0.0f, -1.0f, 100.0f); GetOrtho(m_projection, m_fCameraX, m_fCameraX + (float)viewWidth, m_fCameraY + (float)viewHeight, m_fCameraY, -1.0f, 100.0f); }
SpriteBatch_GL3::SpriteBatch_GL3(Application *pApp) : SpriteBatch( pApp ) { m_currentVert = 0; m_currentIndex = 0; m_processingRender = false; m_vao = -1; m_vbo = -1; m_ibo = -1; m_currentTextureID = 0; m_maxTextures = 5; for(int i=0; i<5; i++) m_activeTextures[i] = nullptr; // load the shader const char* aszInputs[] = { "a_position", "a_color", "a_texcoord" }; const char* aszOutputs[] = { "out_color" }; // load shader internally calls glCreateShader... GLuint vshader = LoadShader(gs_vertexShader, GL_VERTEX_SHADER); GLuint pshader = LoadShader(gs_fragmentShader, GL_FRAGMENT_SHADER); m_shader = CreateProgram( vshader, 0, 0, 0, pshader, 3, aszInputs, 1, aszOutputs); glDeleteShader( vshader ); glDeleteShader( pshader ); m_uniformTextureLoc = glGetUniformLocation(m_shader, "u_texture"); // pre calculate the indices... they will always be the same int index = 0; for(int i=0; i<3072;) { m_indices[i++] = (index + 0); m_indices[i++] = (index + 1); m_indices[i++] = (index + 2); m_indices[i++] = (index + 0); m_indices[i++] = (index + 2); m_indices[i++] = (index + 3); index += 4; } glClear(GL_COLOR_BUFFER_BIT); // create the vao, vio and vbo glGenVertexArrays(1, &m_vao); glBindVertexArray(m_vao); glGenBuffers(1, &m_vbo); glGenBuffers(1, &m_ibo); glBindBuffer(GL_ARRAY_BUFFER, m_vbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, 3072 * sizeof(unsigned short), (void *)(&m_indices[0]), GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, 2048 * sizeof(SBVertex), m_vertices, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(SBVertex), (char *)0); glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(SBVertex), (char *)12); glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(SBVertex), (char *)28); glBindVertexArray(0); m_fCameraX = 0.0f; m_fCameraY = 0.0f; GetOrtho(m_projection, m_fCameraX, m_fCameraX + (float)pApp->GetViewWidth(), m_fCameraY + (float)pApp->GetViewHeight(), m_fCameraY, 0.0f, 100.0f); }
void GetOrtho( const VectorR4& u, RotationMapR4& rotmat ) { rotmat.SetColumn1(u); GetOrtho( 1, rotmat ); }