void CCGShaderSystem::SetConstantBuffers()
	{
		cgSetMatrixParameterfr( m_CGMtxWorldParam, m_mtxWorld.mm );
		cgSetMatrixParameterfr( m_CGMtxViewParam, m_mtxView.mm );
		cgSetMatrixParameterfr( m_CGMtxProjParam, m_mtxProj.mm );
		cgSetMatrixParameterfr( m_CGMtxViewProjParam, m_mtxViewProj.mm );
		cgSetMatrixParameterfr( m_CGMtxWVPParam, m_mtxWVP.mm );
	}
 //
 // SetFloatMat4
 //
 void CCgUniform::SetFloatMat4( 
                               const Mat4& m, EMatrixOrder Order 
                               )
 {
     if (Order == MO_COLUMN_MAJOR)
         cgSetMatrixParameterfc( m_Parameter, &m[ 0 ][ 0 ] );
     else
         cgSetMatrixParameterfr( m_Parameter, &m[ 0 ][ 0 ] );
 }
示例#3
0
bool GLCgShader::SetMatrixConstant(const str_type::string& name, const math::Matrix4x4 &matrix)
{
	CGparameter param = SeekParameter(name, m_params);
	if (!param)
		return ShowInvalidParameterWarning(m_shaderName, name);

	cgSetMatrixParameterfr(param, (float*)&matrix);
	if (CheckForError("Shader::SetMatrixConstant setting parameter", m_shaderName))
		return false;
	return true;
}
void ShaderProjectiveTextureInterface::PerFrameInit() {
	// bind the texture
	GLuint texture_id = mesh->projTexture->texture->Bind();

	//set parameters
	cgGLSetStateMatrixParameter(vertexModelViewProj, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);

	float zNear = 1.0f;
	float zFar = 1000.0f;

	M44 biasMatrix, lightViewMatrix, projectionMatrix;
	BuildBiasMatrix(biasMatrix);
	BuildLightViewMatrix(mesh->projTexture->ppc, lightViewMatrix);
	BuildProjectionMatrix(mesh->projTexture->ppc, zNear, zFar, projectionMatrix);

	lightViewMatrix = biasMatrix * projectionMatrix * lightViewMatrix;
	cgSetMatrixParameterfr(vertexTextureMatrix, (float*)lightViewMatrix.rows);
	cgGLSetTextureParameter(fragmentProjectiveMap, texture_id);
}
示例#5
0
static void display(void)
{
  /* World-space positions for light and eye. */
  const float eyePosition[4] = { camera[0], camera[1], camera[2], 1 };
  const float lightPosition[4] = { 0,100,0, 1 };

  float translateMatrix[16], rotateMatrix[16],
        modelMatrix[16], invModelMatrix[16], viewMatrix[16],
        modelViewMatrix[16], modelViewProjMatrix[16];
  float objSpaceEyePosition[4], objSpaceLightPosition[4];

  buildLookAtMatrix(eyePosition[0], eyePosition[1], eyePosition[2],
                    0, 0, 0,
                    0, 1, 0,
                    viewMatrix);

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  cgGLBindProgram(myCgVertexProgram);
  checkForCgError("binding vertex program");

  cgGLEnableProfile(myCgVertexProfile);
  checkForCgError("enabling vertex profile");

  cgGLBindProgram(myCgFragmentProgram);
  checkForCgError("binding fragment program");

  cgGLEnableProfile(myCgFragmentProfile);
  checkForCgError("enabling fragment profile");
  

  /*** Render able ***/

   
  setTableMaterial();

  /* modelView = rotateMatrix * translateMatrix */
  makeRotateMatrix(0, 1, 1, 1, rotateMatrix);
  makeTranslateMatrix(0, 0 , 0, translateMatrix);
  multMatrix(modelMatrix, translateMatrix, rotateMatrix);

  /* invModelMatrix = inverse(modelMatrix) */
  invertMatrix(invModelMatrix, modelMatrix);

  /* Transform world-space eye and light positions to sphere's object-space. */
  transform(objSpaceEyePosition, invModelMatrix, eyePosition);
  cgSetParameter3fv(myCgFragmentParam_eyePosition, objSpaceEyePosition);
  transform(objSpaceLightPosition, invModelMatrix, lightPosition);
  cgSetParameter3fv(myCgFragmentParam_lightPosition, objSpaceLightPosition);

  /* modelViewMatrix = viewMatrix * modelMatrix */
  multMatrix(modelViewMatrix, viewMatrix, modelMatrix);

  /* modelViewProj = projectionMatrix * modelViewMatrix */
  multMatrix(modelViewProjMatrix, myProjectionMatrix, modelViewMatrix);

  /* Set matrix parameter with row-major matrix. */
  cgSetMatrixParameterfr(myCgVertexParam_modelViewProj, modelViewProjMatrix);
  drawtable();
  
  collision();

  /*** Render White Ball ***/
  setBallMaterial(w.r, w.g, w.b);
  
  if (w.xspeed>0) { w.xspeed=w.xspeed-friction; if (w.xspeed<=0){ w.xspeed=0;}else w.x=w.x+(w.xspeed);}
  else if(w.xspeed<0){ w.xspeed=w.xspeed+friction; if (w.xspeed>=0) {w.xspeed=0;}else w.x=w.x+(w.xspeed);}
	else  { w.xspeed = 0; 
			}
	if (w.zspeed>0) {w.zspeed=w.zspeed-friction; if (w.zspeed<=0) {w.zspeed=0;}else w.z=w.z+(w.zspeed);}
	else if (w.zspeed<0){ w.zspeed=w.zspeed+friction; if (w.zspeed>=0) {w.zspeed=0;}else w.z=w.z+(w.zspeed);}
	else { w.zspeed=0;
	}
  if (w.xspeed==0 && w.zspeed==0)
 {b.flag=1;
 w.flag=1;
 r.flag=1;
glutPostRedisplay(); 
 }
 
  board();
  
  /* modelView = viewMatrix * translateMatrix */
  makeTranslateMatrix(w.x, w.y, w.z, translateMatrix);
  makeRotateMatrix(90, 1, 0, 0, rotateMatrix);
  multMatrix(modelMatrix, translateMatrix, rotateMatrix);

  /* invModelMatrix = inverse(modelMatrix) */
  invertMatrix(invModelMatrix, modelMatrix);

  /* Transform world-space eye and light positions to sphere's object-space. */
  transform(objSpaceEyePosition, invModelMatrix, eyePosition);
  cgSetParameter3fv(myCgFragmentParam_eyePosition, objSpaceEyePosition);
  transform(objSpaceLightPosition, invModelMatrix, lightPosition);
  cgSetParameter3fv(myCgFragmentParam_lightPosition, objSpaceLightPosition);

  /* modelViewMatrix = viewMatrix * modelMatrix */
  multMatrix(modelViewMatrix, viewMatrix, modelMatrix);

  /* modelViewProj = projectionMatrix * modelViewMatrix */
  multMatrix(modelViewProjMatrix, myProjectionMatrix, modelViewMatrix);

  /* Set matrix parameter with row-major matrix. */
  cgSetMatrixParameterfr(myCgVertexParam_modelViewProj, modelViewProjMatrix);

  glutWireSphere(4, 30, 30);

  /*** Render Red Ball ***/
  setBallMaterial(r.r,r.g,r.b);

  collision();
  //checkzerospeed();
  if (r.xspeed>0){r.xspeed=r.xspeed-friction; if (r.xspeed<=0) { r.xspeed=0;}else r.x=r.x+(r.xspeed);}
  else if(r.xspeed<0){r.xspeed=r.xspeed+friction; if (r.xspeed>=0) {r.xspeed=0;}else r.x=r.x+(r.xspeed);}
	else  { r.xspeed = 0;
			}
	if (r.zspeed>0){r.zspeed=r.zspeed-friction; if (r.zspeed<=0){ r.zspeed=0;}else r.z=r.z+(r.zspeed);}
	else if (r.zspeed<0){r.zspeed=r.zspeed+friction; if (r.zspeed>=0) { r.zspeed=0;}else r.z=r.z+(r.zspeed);}
	else r.zspeed=0;

	if (r.xspeed==0 && r.zspeed==0)
 {b.flag=1;
 w.flag=1;
 r.flag=1;
glutPostRedisplay(); 
 }
  redboard();
  /* modelView = viewMatrix * translateMatrix */
  makeTranslateMatrix(r.x, r.y, r.z, translateMatrix);
  makeRotateMatrix(90, 1, 0, 0, rotateMatrix);
  multMatrix(modelMatrix, translateMatrix, rotateMatrix);

  /* invModelMatrix = inverse(modelMatrix) */
  invertMatrix(invModelMatrix, modelMatrix);

  /* Transform world-space eye and light positions to sphere's object-space. */
  transform(objSpaceEyePosition, invModelMatrix, eyePosition);
  cgSetParameter3fv(myCgFragmentParam_eyePosition, objSpaceEyePosition);
  transform(objSpaceLightPosition, invModelMatrix, lightPosition);
  cgSetParameter3fv(myCgFragmentParam_lightPosition, objSpaceLightPosition);

  /* modelViewMatrix = viewMatrix * modelMatrix */
  multMatrix(modelViewMatrix, viewMatrix, modelMatrix);

  /* modelViewProj = projectionMatrix * modelViewMatrix */
  multMatrix(modelViewProjMatrix, myProjectionMatrix, modelViewMatrix);

  /* Set matrix parameter with row-major matrix. */
  cgSetMatrixParameterfr(myCgVertexParam_modelViewProj, modelViewProjMatrix);

  glutSolidSphere(4, 30, 30); 

 /*** Render Black Ball ***/
  setBallMaterial(b.r,b.g,b.b);

  collision();
 
  if (b.xspeed>0){b.xspeed=b.xspeed-friction; if (b.xspeed<=0) {b.xspeed=0;}else  b.x=b.x+(b.xspeed);}
  else if(b.xspeed<0){b.xspeed=b.xspeed+friction; if (b.xspeed>=0) { b.xspeed=0;}else  b.x=b.x+(b.xspeed);}
	else  { b.xspeed = 0;
			}
	if (b.zspeed>0){b.zspeed=b.zspeed-friction; if (b.zspeed<=0){ b.zspeed=0;}else b.z=b.z+(b.zspeed);}
	else if (b.zspeed<0){b.zspeed=b.zspeed+friction; if (b.zspeed>=0) { b.zspeed=0;}else b.z=b.z+(b.zspeed);}
	else b.zspeed=0;

 if (b.xspeed==0 && b.zspeed==0)
 {b.flag=1;
 w.flag=1;
 r.flag=1;
glutPostRedisplay(); 
 }
  blackboard();
 
  /* modelView = viewMatrix * translateMatrix */
  makeTranslateMatrix(b.x, b.y, b.z, translateMatrix);
  makeRotateMatrix(90, 1, 0, 0, rotateMatrix);
  multMatrix(modelMatrix, translateMatrix, rotateMatrix);

  /* invModelMatrix = inverse(modelMatrix) */
  invertMatrix(invModelMatrix, modelMatrix);

  /* Transform world-space eye and light positions to sphere's object-space. */
  transform(objSpaceEyePosition, invModelMatrix, eyePosition);
  cgSetParameter3fv(myCgFragmentParam_eyePosition, objSpaceEyePosition);
  transform(objSpaceLightPosition, invModelMatrix, lightPosition);
  cgSetParameter3fv(myCgFragmentParam_lightPosition, objSpaceLightPosition);

  /* modelViewMatrix = viewMatrix * modelMatrix */
  multMatrix(modelViewMatrix, viewMatrix, modelMatrix);

  /* modelViewProj = projectionMatrix * modelViewMatrix */
  multMatrix(modelViewProjMatrix, myProjectionMatrix, modelViewMatrix);

  /* Set matrix parameter with row-major matrix. */
  cgSetMatrixParameterfr(myCgVertexParam_modelViewProj, modelViewProjMatrix);

  glutSolidSphere(4, 30, 30);

    /*** Render Stick***/
  if (enablestick)
  
  { //printf("stick enabled");
  setStickMaterial();
  /* modelView = viewMatrix * translateMatrix */
  makeTranslateMatrix(w.x,0,w.z, translateMatrix);
  makeRotateMatrix(stickangle, 0, 1, 0, rotateMatrix);
  multMatrix(modelMatrix, translateMatrix, rotateMatrix);

  /* invModelMatrix = inverse(modelMatrix) */
  invertMatrix(invModelMatrix, modelMatrix);

  /* Transform world-space eye and light positions to sphere's object-space. */
  transform(objSpaceEyePosition, invModelMatrix, eyePosition);
  cgSetParameter3fv(myCgFragmentParam_eyePosition, objSpaceEyePosition);
  transform(objSpaceLightPosition, invModelMatrix, lightPosition);
  cgSetParameter3fv(myCgFragmentParam_lightPosition, objSpaceLightPosition);

  /* modelViewMatrix = viewMatrix * modelMatrix */
  multMatrix(modelViewMatrix, viewMatrix, modelMatrix);

  /* modelViewProj = projectionMatrix * modelViewMatrix */
  multMatrix(modelViewProjMatrix, myProjectionMatrix, modelViewMatrix);

  /* Set matrix parameter with row-major matrix. */
  cgSetMatrixParameterfr(myCgVertexParam_modelViewProj, modelViewProjMatrix);
drawstick();
  
/*  glBegin(GL_LINES);
  glVertex3f(0,0,0);
  glVertex3f(0,20,84);
  glEnd();
 */
  }

  glutSwapBuffers();
}
示例#6
0
void CCgUniform4x4f::update(const void* data, const SMaterial& material) const
{
	f32* Data = (f32*)data;
	cgSetMatrixParameterfr(Parameter, Data);
}