Example #1
0
// virtual
void Transform::DrawGlobalLights(X3DDrawContext* pDC)
{
	D3DXMATRIX transform = GetTransform();
	pDC->m_renderContext->PushModelView(transform * pDC->m_renderContext->modelViewMatrix());

	DrawGlobalLightsChildren(pDC, getChildrenField());

	pDC->m_renderContext->PopMatrix();

#if 0
	pDC->m_pGraphics3D->PushMatrix();

// P' = T * C * R * SR * S * -SR * -C * P

		pDC->m_pGraphics3D->TranslateTransform(m_T->m_value);
		pDC->m_pGraphics3D->TranslateTransform(m_C->m_value);
		pDC->m_pGraphics3D->RotateTransform(gmDegrees(m_R->m_value.m_angle), m_R->m_value.m_axis);
		pDC->m_pGraphics3D->RotateTransform(gmDegrees(m_SR->m_value.m_angle), m_SR->m_value.m_axis);
		pDC->m_pGraphics3D->ScaleTransform(m_S->m_value);
		pDC->m_pGraphics3D->RotateTransform(gmDegrees(m_SR->m_value.m_angle), -m_SR->m_value.m_axis);
		pDC->m_pGraphics3D->TranslateTransform(-m_C->m_value);

	DrawGlobalLightsChildren(pDC, get_children());

	pDC->m_pGraphics3D->PopMatrix();
#endif
}
Example #2
0
D3DXMATRIX Transform::GetTransform()
{
	Vec3f T = getTranslation();
	Vec3f C = getCenter();
	Vec3f S = getScale();
	Rotation R = getRotation();
	Rotation SR = getScaleOrientation();

	gm::matrix4f m =
		gm::matrix4f::getTranslate(T) *
		gm::matrix4f::getTranslate(C) *
		gm::matrix4f::getRotate(gmDegrees(R.m_angle), R.m_axis) *
		gm::matrix4f::getRotate(gmDegrees(SR.m_angle), SR.m_axis) *
		gm::matrix4f::getScale(S) *
		gm::matrix4f::getRotate(gmDegrees(SR.m_angle), -SR.m_axis) *
		gm::matrix4f::getTranslate(-C);

	return *(D3DXMATRIX*)&m;
}
Example #3
0
void Transform::DrawOverlay(X3DDrawContext* pDC)
{
	Vec3f S = getScale();

	if (S[0] == 0 && S[1] == 0 && S[2] == 0)
		return;

	D3DXMATRIX transform = GetTransform();
	pDC->m_renderContext->PushModelView(transform * pDC->m_renderContext->modelViewMatrix());

	// TODO: not here
	if (m_selected)
	{
	//	pDC->m_renderContext->PushModelView(pDC->m_renderContext->modelViewMatrix() * MatrixTranslation(getLocation()));

		D3DXMATRIX m = pDC->m_renderContext->modelViewMatrix();
		DrawBoundingBox(pDC, CalculateBoundingBox(*(gm::matrix4f*)&m));

		DrawAxis(pDC);

	//	pDC->m_renderContext->PopMatrix();
	//	pDC->m_renderContext->GetRT()->m_d3d10->m_device->OMSetDepthStencilState(depthStencilState, stencilRef);
	}

	DrawOverlayChildren(pDC, getChildrenField());

	pDC->m_renderContext->PopMatrix();

#if 0
	/*
	SFVec3f*		C = static_cast<SFVec3f*>(m_C);
	SFRotation*	R = static_cast<SFRotation*>(m_R);
	SFVec3f*		S = static_cast<SFVec3f*>(m_S);
	SFVec3f*		SR = static_cast<SFVec3f*>(m_SR);
	SFVec3f*		T = static_cast<SFVec3f*>(m_T);
	MFNode*		children = static_cast<MFNode*>(m_children);
	*/

	pDC->m_pGraphics3D->glPushMatrix();

		pDC->m_pGraphics3D->glTranslate(m_T->m_value);
		pDC->m_pGraphics3D->glTranslate(m_C->m_value);
		pDC->m_pGraphics3D->glRotate(gmDegrees(m_R->m_value.m_angle), m_R->m_value.m_axis);
		pDC->m_pGraphics3D->glRotate(gmDegrees(m_SR->m_value.m_angle), m_SR->m_value.m_axis);
		pDC->m_pGraphics3D->glScale(m_S->m_value);
		pDC->m_pGraphics3D->glRotate(gmDegrees(m_SR->m_value.m_angle), -m_SR->m_value.m_axis);
		pDC->m_pGraphics3D->glTranslate(-m_C->m_value);

		// Draw axes
	{
		//DrawBoundBox();

		pDC->m_pGraphics3D->glPushAttrib(GL_ENABLE_BIT);

		float len = 4;

		pDC->m_pGraphics3D->glDisable(GL_LIGHTING);

		pDC->m_pGraphics3D->glBegin(GL_LINES);

		pDC->m_pGraphics3D->glColorf(1.0, 0, 0);	// red
		pDC->m_pGraphics3D->glVertexf(0, 0, 0);
		pDC->m_pGraphics3D->glVertexf(1*len, 0, 0);

		pDC->m_pGraphics3D->glColorf(0.0, 1.0, 0);	// blue
		pDC->m_pGraphics3D->glVertexf(0, 0, 0);
		pDC->m_pGraphics3D->glVertexf(0, 1*len, 0);

		pDC->m_pGraphics3D->glColorf(0, 0, 1.0);	// green
		pDC->m_pGraphics3D->glVertexf(0, 0, 0);
		pDC->m_pGraphics3D->glVertexf(0, 0, 1*len);

		pDC->m_pGraphics3D->glEnd();

		pDC->m_pGraphics3D->glColorf(1,1,1);	// white
	//	GLUquadricObj* q = gluNewQuadric();
		LDraw::gluSphere(pDC->m_pGraphics3D, 0.1, 8, 8);
	//	gluDeleteQuadric(q);

		pDC->m_pGraphics3D->glPopAttrib();
	}

	int nLight = pDC->m_nLight;

	int i;

	for (i = 0; i < m_children->m_items.GetSize(); i++)
	{
		if (m_children->m_items[i])
		{
			CLRenderImplImpl* render = dynamic_cast<CLRenderImplImpl*>(m_children->m_items[i]->GetNode());
			if (render)
			{
				render->PreDraw(pDC);
			}
		}
	}

	for (i = 0; i < m_children->m_items.GetSize(); i++)
	{
		if (m_children->m_items[i])
		{
			CLRenderImplImpl* render = dynamic_cast<CLRenderImplImpl*>(m_children->m_items[i]->GetNode());
			if (render)
			{
				render->DrawOverlay(pDC);
			}
		}
	}

	for (i = pDC->m_nLight; i >= nLight; i--)
	{
		pDC->m_pGraphics3D->glDisable(GL_LIGHT0+i);
	}
	pDC->m_nLight = nLight;

	pDC->m_pGraphics3D->glPopMatrix();
#endif
}
Example #4
0
// virtual
void Transform::Draw(X3DDrawContext* pDC)
{
	Vec3f S = getScale();

	if (S[0] == 0 && S[1] == 0 && S[2] == 0)
		return;

	D3DXMATRIX transform = GetTransform();

	pDC->m_renderContext->PushModelView(transform * pDC->m_renderContext->modelViewMatrix());

#if 0	// Had this
	pDC->m_pGraphics3D->PushMatrix();

// P' = T * C * R * SR * S * -SR * -C * P

		pDC->m_pGraphics3D->TranslateTransform(m_T->m_value);
		pDC->m_pGraphics3D->TranslateTransform(m_C->m_value);
		if (m_R->m_value.m_angle) pDC->m_pGraphics3D->RotateTransform(gmDegrees(m_R->m_value.m_angle), m_R->m_value.m_axis);
		if (m_SR->m_value.m_angle) pDC->m_pGraphics3D->RotateTransform(gmDegrees(m_SR->m_value.m_angle), m_SR->m_value.m_axis);
		pDC->m_pGraphics3D->ScaleTransform(m_S->m_value);
		if (m_SR->m_value.m_angle) pDC->m_pGraphics3D->RotateTransform(gmDegrees(m_SR->m_value.m_angle), -m_SR->m_value.m_axis);
		pDC->m_pGraphics3D->TranslateTransform(-m_C->m_value);
#endif
	// Draw axes
#if 0
	if (FALSE)
	{
		pDC->m_pGraphics3D->glPushAttrib(GL_ENABLE_BIT);

		float len = 4;

		pDC->m_pGraphics3D->glDisable(GL_LIGHTING);

		pDC->m_pGraphics3D->glBegin(GL_LINES);

		pDC->m_pGraphics3D->glColor3f(1.0, 0, 0);	// red
		pDC->m_pGraphics3D->glVertex3f(0, 0, 0);
		pDC->m_pGraphics3D->glVertex3f(1*len, 0, 0);

		pDC->m_pGraphics3D->glColor3f(0.0, 1.0, 0);	// blue
		pDC->m_pGraphics3D->glVertex3f(0, 0, 0);
		pDC->m_pGraphics3D->glVertex3f(0, 1*len, 0);

		glColor3f(0, 0, 1.0);	// green
		glVertex3f(0, 0, 0);
		glVertex3f(0, 0, 1*len);

		glEnd();

		glPopAttrib();
	}
#endif

	DrawChildren(pDC, getChildrenField());

	/*
	int nLight = pDC->m_nLight;
	int nNames = pDC->m_namedNodes.GetSize();

	int i;

	for (i = 0; i < m_children->m_items.GetSize(); i++)
	{
		if (m_children->m_items[i])
		{
			RenderImplImpl* render = dynamic_cast<RenderImplImpl*>(m_children->m_items[i]->GetNode());
			if (render)
			{
				render->PreDraw(pDC);
			}
		}
	}

	for (i = 0; i < m_children->m_items.GetSize(); i++)
	{
		if (m_children->m_items[i])
		{
			RenderImplImpl* render = dynamic_cast<RenderImplImpl*>(m_children->m_items[i]->GetNode());
			if (render)
			{
				render->Draw(pDC);
			}
		}
	}

	for (i = pDC->m_namedNodes.GetSize(); i >= nNames; i--)
	{
//		glPopName();
	}
	for (i = pDC->m_nLight; i >= nLight; i--)
	{
		pDC->m_pGraphics3D->glDisable(GL_LIGHT0+i);
	}
	pDC->m_nLight = nLight;
	*/

	pDC->m_renderContext->PopMatrix();
	//pDC->m_transformStack.pop();
#if 0
	pDC->m_pGraphics3D->PopMatrix();
#endif
}
Example #5
0
LRESULT CLX3DViewer::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
#if 0
	int nVirtKey = (int) wParam;    // virtual-key code 
	int lKeyData = lParam;          // key data 

	m_nKeyRepeat++;
	int repeatCount = m_nKeyRepeat;//lKeyData & 0xffff;

	LONG bCtrl = (GetAsyncKeyState(VK_CONTROL) & (1<<15));
	LONG bShift = (GetAsyncKeyState(VK_SHIFT) & (1<<15));

	double moveX = 0;
	double moveZ = 0;

	double rotateX = 0;
	double rotateY = 0;
	double rotateZ = 0;

	double rotate = 0.4 + 0.2*(repeatCount-1);
	if (rotate > 2) rotate = 2;

	BOOL bRunning = bShift;
	double speed = bRunning? 4: 2;

	switch (nVirtKey)
	{
	case VK_UP:
		{
			if (bCtrl)
			{
				rotateX = -rotate;
			}
			else
			{
				moveZ -= speed;
			}
		}
		break;

	case VK_DOWN:
		{
			if (bCtrl)
			{
				rotateX = rotate;
			}
			else
			{
				moveZ += speed;
			}
		}
		break;

	case VK_LEFT:
		{
			if (bCtrl)
			{
				moveX -= speed;
			}
			else
			{
				rotateY = rotate;
			}
		}
		break;

	case VK_RIGHT:
		{
			if (bCtrl)
			{
				moveX += speed;
			}
			else
			{
				rotateY = -rotate;
			}
		}
		break;
	}

	CLViewpoint* pViewpoint = static_cast<CLViewpoint*>(m_viewpointStack[0]);

	CLSFRotation* orientation = static_cast<CLSFRotation*>(pViewpoint->m_orientation);
	CLSFVec3f* position = static_cast<CLSFVec3f*>(pViewpoint->m_position);

	// Orientation
	if (rotateY != 0 || rotateX != 0 || rotateZ != 0)
	{
		/*
		float x = orientation->m_value.m_v[0];
		float y = orientation->m_value.m_v[1];
		float z = orientation->m_value.m_v[2];
		float angle = orientation->m_value.m_a;
		*/

		Quat4d q = orientation->m_value.AxisAngleToQuaternion();//x, y, z, angle);

		q.CombineQuaternion(/*x, y, z, angle,*/ gmRadians(rotateZ), gmRadians(rotateY), gmRadians(rotateX));

		orientation->m_value = q.QuaternionToAxisAngle();//x, y, z, angle);

		/*
		orientation->m_value.m_v[0] = x;
		orientation->m_value.m_v[1] = y;
		orientation->m_value.m_v[2] = z;
		orientation->m_value.m_a = angle;
		*/

		orientation->m_value.m_v.normalize();
	}

	// Position
	{
		gmMatrix4 repos = gmMatrix4::identity();

		repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v);
		repos *= gmMatrix4::translate(moveX, 0, moveZ);
		repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v).inverse();

		position->m_value = repos.transform(position->m_value);
	}

	FireViewChange();
#endif

	return 0;
}
Example #6
0
LRESULT CLX3DViewer::OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CPoint point;
	point.x = (short)LOWORD(lParam);
	point.y = (short)HIWORD(lParam);

	if (m_dragging == 1)
	{
		m_slider.OnMouseMove(point);
		UpdateWindow();

		double position = m_slider.GetPos();

		CComQIPtr<ILMediaSeeking> seeking = m_filterGraph;
		seeking->Seek(position);
	}

#if 0
	if (m_dragging)
	{
		CPoint offset = point - m_startpoint;

		if (m_dragging == 1)	// change XY position
		{
			CLViewpoint* pViewpoint = static_cast<CLViewpoint*>(m_viewpointStack[0]);

			CLSFRotation* orientation = static_cast<CLSFRotation*>(pViewpoint->m_orientation);
			CLSFVec3f* position = static_cast<CLSFVec3f*>(pViewpoint->m_position);

			double moveY = (double)-offset.y/20;
			double moveX = (double)offset.x/20;

			gmMatrix4 repos = gmMatrix4::identity();

			repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v);
			repos *= gmMatrix4::translate(moveX, moveY, 0);
			repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v).inverse();

			position->m_value = repos.transform(m_initialPosition);

			FireViewChange();
		}
		else if (m_dragging == 2) // change XZ position
		{
			CLViewpoint* pViewpoint = static_cast<CLViewpoint*>(m_viewpointStack[0]);

			CLSFRotation* orientation = static_cast<CLSFRotation*>(pViewpoint->m_orientation);
			CLSFVec3f* position = static_cast<CLSFVec3f*>(pViewpoint->m_position);

			double moveX = (double)offset.x/20;
			double moveZ = (double)offset.y/20;

			gmMatrix4 repos = gmMatrix4::identity();

			repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v);
			repos *= gmMatrix4::translate(moveX, 0, moveZ);
			repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v).inverse();

			position->m_value = repos.transform(m_initialPosition);

			FireViewChange();
		}
		else if (m_dragging == 3)
		{
			double r = 600;	// 360

			double rotateY = (double)offset.x*360/r;
			double rotateX = (double)offset.y*360/r;

			CLViewpoint* pViewpoint = static_cast<CLViewpoint*>(m_viewpointStack[0]);

			CLSFRotation* orientation = static_cast<CLSFRotation*>(pViewpoint->m_orientation);
			CLSFVec3f* position = static_cast<CLSFVec3f*>(pViewpoint->m_position);

			// Orientation
			if (rotateY != 0 || rotateX != 0)
			{
				/*
				float x = m_initialOrientation.m_v[0];
				float y = m_initialOrientation.m_v[1];
				float z = m_initialOrientation.m_v[2];
				float angle = m_initialOrientation.m_a;
				*/

				Quat4d q = m_initialOrientation.AxisAngleToQuaternion(/*x, y, z, angle*/);

				q.CombineQuaternion(/*x, y, z, angle,*/ 0, gmRadians(rotateY), gmRadians(rotateX));

				orientation->m_value = q.QuaternionToAxisAngle();//Quat4d(x, y, z, angle));

				/*
				orientation->m_value.m_v[0] = x;
				orientation->m_value.m_v[1] = y;
				orientation->m_value.m_v[2] = z;
				orientation->m_value.m_a = angle;
				*/

				orientation->m_value.m_v.normalize();
			}

			// Position
			{
				// Rotate position around centerOfRotation
				gmMatrix4 repos = gmMatrix4::identity();

				repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v);
				repos *= gmMatrix4::rotate(rotateY, gmVector3(0,1,0));
				repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v).inverse();

				position->m_value = repos.transform(m_initialPosition);
			}

			// Position
			{
				// Rotate position around centerOfRotation
				gmMatrix4 repos = gmMatrix4::identity();

				repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v);
				repos *= gmMatrix4::rotate(rotateX, gmVector3(1,0,0));
				repos *= gmMatrix4::rotate(rotateY, gmVector3(0,1,0));
				repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v).inverse();

				position->m_value = repos.transform(m_initialPosition);
			}

			FireViewChange();
		}
	}
	else
	{
		CRect client;
		GetClientRect(&client);
		int w = client.right;
		int h = client.bottom;
	//	wglMakeCurrent(hdc, m_hrc);

		double winx = point.x;
		double winy = client.bottom-point.y-1;

		GLint viewport[4] = { 0, 0, w, h };

		GLuint selectBuf[512];

		glSelectBuffer(512, selectBuf);
		glRenderMode(GL_SELECT);
		glInitNames();
		glPushName(0);

		{
			CLViewpoint* pViewpoint = NULL;

			if (m_viewpointStack.GetSize() > 0)
			{
				pViewpoint = static_cast<CLViewpoint*>(m_viewpointStack[0]);
			}
			else
			{
				// hmm...
			}

			//	glViewport(m_viewR[view].left, m_viewR[view].top, w, h);

			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			gluPickMatrix(winx, winy, 3, 3, viewport);
	//		glLoadMatrixd(projm);
		//
			double fov;
			if (pViewpoint)
			{
				CLSFFloat* fieldOfView = static_cast<CLSFFloat*>(pViewpoint->m_fieldOfView);
				fov = fieldOfView->m_value;
			}
			else
			{
				fov = M_PI/4;
			}

			gluPerspective(gmDegrees(fov), (GLfloat)w / (GLfloat)h, 1.0, 10000.0);

			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();
			//glLoadMatrixf((float*)modelm);

			CX3DDrawContext xdc;

#if 0
			// NavigationInfo
			{
				BOOL headlight;

				if (m_navigationinfoStack.GetSize() > 0)
				{
					CLNavigationInfo* pNavigationInfo = static_cast<CLNavigationInfo*>(m_navigationinfoStack[0]);

					headlight = static_cast<CLSFBool*>(pNavigationInfo->m_headlight)->m_v;
				}
				else
				{
					// Default values
					headlight = TRUE;
				}

				glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

				if (TRUE)//TRUE/*bAnyLights*/)
				{
				}

				if (headlight)
				{
					GLfloat light_direction[4] = { 0, 0, 1, 0};	// directional
					GLfloat color[4] = {1, 1, 1, 1};
					GLfloat ambient[4] = {0, 0, 0, 1};

					glEnable(GL_LIGHT0+xdc.m_nLight);
					glLightfv(GL_LIGHT0+xdc.m_nLight, GL_POSITION, light_direction);
					glLightfv(GL_LIGHT0+xdc.m_nLight, GL_AMBIENT, ambient);
					glLightfv(GL_LIGHT0+xdc.m_nLight, GL_DIFFUSE, color);
					glLightfv(GL_LIGHT0+xdc.m_nLight, GL_SPECULAR , color);

					xdc.m_nLight++;
				}
			}
#endif

			if (pViewpoint)
			{
				CLSFRotation* orientation = static_cast<CLSFRotation*>(pViewpoint->m_orientation);
				CLSFVec3f* position = static_cast<CLSFVec3f*>(pViewpoint->m_position);
				gmVector3t<float> norientation = orientation->m_value.m_v;
				norientation.normalize();

				glRotate(gmDegrees(orientation->m_value.m_a), -norientation);
				glTranslate(-position->m_value);
			}
			else
			{
				// TODO
				glTranslatef(0, 0, -180);
			}

			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

			if (m_scene)
			{
				CComQIPtr<CLRenderImplImpl> render = static_cast<CLSAIScene*>(m_scene)->m_root;
				if (render)
				{
					render->Draw(&xdc);
				}
			}

			glFlush();
		}

		GLint hits = glRenderMode(GL_RENDER);

		if (hits > 0)
		{
			MessageBeep(-1);
			GLuint* ptr = selectBuf;

			GLuint names = *ptr++;
			float z1 = *ptr++ / 0x7fffffff;
			float z2 = *ptr++ / 0x7fffffff;

			double winz = z2;

			double modelMatrix[16];
			double projMatrix[16];

			glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
			glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);

			double objx, objy, objz;
			gluUnProject(winx, winy, winz, modelMatrix, projMatrix, viewport, &objx, &objy, &objz);

			for (int n = 0; n < names; n++)
			{
			}
		}
	}
#endif

	return 0;
}