Beispiel #1
0
void draw(const float r, const float g, const float b)
{
#ifndef BT_NO_PROFILE
	CProfileManager::Reset();
#endif //BT_NO_PROFILE

	BT_PROFILE("draw()");
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glViewport ( 0, 0, m_glutScreenWidth, m_glutScreenHeight );
	btScalar aspect = m_glutScreenWidth / (btScalar)m_glutScreenHeight;

	m_fluidWorld->stepSimulation(btScalar(1.0/60.0) ,1,  btScalar(1.0/60.0));
	m_fluidWorld->setFluidSolver(m_fluidSolverCPU);
//	if(m_fluidWorld) m_fluidWorld->debugDrawWorld();		//Optional but useful: debug drawing to detect problems

	updateCamera();
	esMatrixLoadIdentity(&projMat);
	esMatrixLoadIdentity(&viewMat);
	esFrustum(&projMat, -aspect, aspect,  -1.0f, 1.0f, 1.0f, 1000.0f);
	esMatrixLookAt(&viewMat,
					0.0f, 100.0f, 20.0f,
					0.0f, 0.0f, 0.0f,
					0.0f, 1.0f, 0.0f);

	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);
	glDisable(GL_BLEND);
//	plane->draw(plane_motion_x, -10, plane_motion_z, basicShader,&projMat,&viewMat);

	renderShootBox(plane_motion_x, -10, plane_motion_z, basicShader,&projMat,&viewMat);
	renderFluids(r, g, b);
	glUseProgram(0);
}
Beispiel #2
0
void        Init(GLContext    *_context)
{
	_context->userObject = new   UserData();
	UserData      *_user = (UserData *)_context->userObject;
	_user->object = GLProgram::createWithFile("shader/sun/sun.vsh", "shader/sun/sun.fsh");
	_user->mvpLoc = _user->object->getUniformLocation("u_mvpMatrix");
	_user->mvLoc = _user->object->getUniformLocation("u_mvMatrix");
	_user->baseMapLoc = _user->object->getUniformLocation("u_baseMap");
	_user->lightColorLoc = _user->object->getUniformLocation("u_lightColor");

	TGAImage       _earthMap("tga/Earth512x256.tga");
	_user->earthMapId = _earthMap.genTextureMap();

	TGAImage       _moonMap("tga/Moon256x128.tga");
	_user->moonMapId = _moonMap.genTextureMap();

	_user->earthAngle = 0.0f;
	_user->moonAngle = 0.0f;

	_user->mSphere = GLSphere::createWithSlice(256, 0.6f);
	//
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
//	glEnable(GL_BLEND);
	//	return    true;
	esMatrixLookAt(&_user->viewMatrix, &GLVector3(0.0f,0.0f,0.0f),&GLVector3(0.0f,0.0f,-5.0f),&GLVector3(0.0f,1.0f,0.0f));
}
//固定不变的矩阵
void        SetFixedMatrix(GLContext *_context)
{
	UserData    *_user = (UserData*)_context->userObject;
	Size   _size = _context->getWinSize();
	esPerspective(&_user->projMatrix, 50.0f, _size.width / _size.height, 1.0f, 100.0f);
	//	esOrtho(&_user->projMatrix, -4.0f, 4.0f, -4.0f, 4.0f, 0.0f, 8.0f);
	//光源的视野
	//	esMatrixLookAt(&_user->viewMatrix, &GLVector3(4.0f, 2.5f, -4.0f), &GLVector3(0.0f, 0.0f, -4.0f), &GLVector3(0.0f, 1.0f, 0.0f));
	esMatrixLookAt(&_user->viewMatrix, &GLVector3(2.3f, 2.5f, -4.0f), &GLVector3(2.0f, 0.0f, -4.0f), &GLVector3(0.0f, 1.0f, 0.0f));
	//光线的方向
	ESMatrix3      trunkMatrix;
	esMatrixTrunk(&trunkMatrix, &_user->viewMatrix);
	_user->lightVector = esMatrixMultiplyVector3(&GLVector3(2.3f - 2.0f, 2.5f - 0.0f, -4.0f + 4.0f), &trunkMatrix);// normalize(&GLVector3(2.3f - 2.0f, 2.5f - 0.0f, -4.0f + 4.0f));
	_user->lightVector = normalize(&_user->lightVector);
	ESMatrix    identity;
	///////////////////地面//////////////////
	//旋转
	esRotate(&_user->lightGroundMatrix, -90.0f, 1.0f, 0.0f, 0.0f);
	//平移
	esTranslate(&_user->lightGroundMatrix, 0.0f, -1.0f, -4.0f);
	//视图矩阵
	esMatrixMultiply(&_user->lightGroundMatrix, &_user->lightGroundMatrix, &_user->viewMatrix);
	//获取法线矩阵
	esMatrixTrunk(&_user->normalGroundMatrix, &_user->lightGroundMatrix);
	GLVector3    rotatevector = esMatrixMultiplyVector3(&GLVector3(0.0f, 0.0f, 1.0f), &_user->normalGroundMatrix);
	esMatrixMultiply(&_user->lightGroundMatrix, &_user->lightGroundMatrix, &_user->projMatrix);
////////////////////
	//旋转
	esRotate(&_user->eyeGroundMatrix, -90.0f, 1.0f, 0.0f, 0.0f);
	//平移
	esTranslate(&_user->eyeGroundMatrix, 0.0f, -1.0f, -4.0f);
	//视图矩阵
	esMatrixLookAt(&_user->eyeViewMatrix, &GLVector3(0.0f, 1.0f, 0.0f), &GLVector3(0.0f, 0.0f, -8.0f), &GLVector3(0.0f, 1.0f, 0.0f));
	esMatrixMultiply(&_user->eyeGroundMatrix, &_user->eyeGroundMatrix, &_user->eyeViewMatrix);
	//MVP矩阵
	esMatrixMultiply(&_user->eyeGroundMatrix, &_user->eyeGroundMatrix, &_user->projMatrix);
}
Beispiel #4
0
void updateCamera(){

//	BT_PROFILE("updateCamera");
//	btScalar rele = m_ele * btScalar(0.01745329251994329547);// rads per deg
//	btScalar razi = m_azi * btScalar(0.01745329251994329547);// rads per deg
//
//
//	btQuaternion rot(m_cameraUp,razi);
//
//
//	btVector3 eyePos(0,0,0);
//	eyePos[m_forwardAxis] = -m_cameraDistance;
//
//	LOGI("eyepos1 is %f,%f,%f",eyePos.getX(),eyePos.getY(),eyePos.getZ());
//	btVector3 forward(eyePos[0],eyePos[1],eyePos[2]);
//	if (forward.length2() < SIMD_EPSILON)
//		not executed
//	{
//		forward.setValue(1.f,0.f,0.f);
//	}
//	btVector3 right = m_cameraUp.cross(forward);
//	btQuaternion roll(right,-rele);
//
//	eyePos = btMatrix3x3(rot) * btMatrix3x3(roll) * eyePos;
//
//	m_cameraPosition[0] = eyePos.getX();
//	m_cameraPosition[1] = eyePos.getY();
//	m_cameraPosition[2] = eyePos.getZ();
//
////	LOGI("eyepos2 is %f,%f,%f",eyePos.getX(),eyePos.getY(),eyePos.getZ());
//	m_cameraPosition += m_cameraTargetPosition;
//
//	if (m_glutScreenWidth == 0 && m_glutScreenHeight == 0)
//		return;
//
	btScalar aspect;
	btVector3 extents;

	aspect = m_glutScreenWidth / (btScalar)m_glutScreenHeight;
	extents.setValue(aspect * 1.0f, 1.0f,0);


	if (m_ortho)
	{
//		not executed
		extents *= m_cameraDistance;
		btVector3 lower = m_cameraTargetPosition - extents;
		btVector3 upper = m_cameraTargetPosition + extents;
//		gluOrtho2D(lower.x, upper.x, lower.y, upper.y);
		esOrtho(&projMat,lower.getX(), upper.getX(), lower.getY(), upper.getY(),-1000,1000);
//		glOrthof(lower.getX(), upper.getX(), lower.getY(), upper.getY(),-1000,1000);
		LOGI("ORTHO");
	} else
	{
//		esFrustum(&projMat, -aspect * 1.0f, aspect * 1.0f, 1.0f, -1.0f, 1.0f,  200.0f);
//		esMatrixLookAt(&viewMat,
//				m_cameraPosition[0], m_cameraPosition[1], m_cameraPosition[2],
//				m_cameraTargetPosition[0], m_cameraTargetPosition[1], m_cameraTargetPosition[2],
//				m_cameraUp.getX(),m_cameraUp.getY(),m_cameraUp.getZ());
		esFrustum(&projMat, -aspect, aspect,  -1.0f, 1.0f, 1.0f, 1000.0f);
		esMatrixLookAt(&viewMat,
						0.0f, 100.0f, 20.0f,
						0.0f, 0.0f, 0.0f,
						0.0f, 1.0f, 0.0f);
	}

}