⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toolmarker.cpp

📁 hair solusion, c&#226 cs ádasda
💻 CPP
字号:
#include "ToolMarker.h"

#include <stdio.h>
#include <math.h>

ToolMarker::ToolMarker()
{
	pDecal = NULL;

	pixelx = 0;
	pixely = 0;

	xpos = 0.0;
	ypos = 0.0;

	realmousex = 0.0;
	realmousey = 0.0;

	mousevectorx = 1.0;
	mousevectory = 1.0;

	fRedDif[0] = 1.0;
	fRedDif[1] = 0.0;
	fRedDif[2] = 0.0;
	fRedDif[3] = 1.0;
}

ToolMarker::~ToolMarker()
{
}

void ToolMarker::CreateDisplayList()
{
	if ( ! DisplayID )
	{
		GLfloat fPyrVerts[5][4] =
		{
			{ 0.0, 0.0, 0.0 },
			{ -TOOL_MARKER_WIDTH, -TOOL_MARKER_WIDTH, TOOL_MARKER_HEIGHT },
			{ -TOOL_MARKER_WIDTH,  TOOL_MARKER_WIDTH, TOOL_MARKER_HEIGHT },
			{  TOOL_MARKER_WIDTH,  TOOL_MARKER_WIDTH, TOOL_MARKER_HEIGHT },
			{  TOOL_MARKER_WIDTH, -TOOL_MARKER_WIDTH, TOOL_MARKER_HEIGHT },
		};

		GLfloat fBoxAmb[]  = {0.0, 0.0, 0.0, 1.0};
		GLfloat fBoxSpec[] = {1.0, 1.0, 1.0, 1.0};

		// Only create the display list once

		DisplayID = glGenLists(1);

		glNewList(DisplayID, GL_COMPILE);

		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,  fRedDif);
		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,  fBoxAmb);

		glCallList(DisplayID);

			glPushMatrix();

//				glScalef( pDecal->fSinglePixelSize, pDecal->fSinglePixelSize, 0.01 );
				glScalef( 0.1, 0.1, 0.01 );

				glTranslatef( 0.0, 0.0, 0.5 );

				glutSolidCube(1.0);

			glPopMatrix();

		glEndList();
	}
}

void ToolMarker::Draw()
{
	GLfloat angle = 0.0;
	angle = GetMouseAngle();

	glPushMatrix();

		glTranslatef( xpos, ypos, 0.0 );
//		glTranslatef( -0.2, -0.2, 0.0 );

		glCallList(DisplayID);

		glPushMatrix();
			glRotatef(-angle, 0.0, 0.0, 1.0);

			glBegin(GL_TRIANGLES);
				glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,  fRedDif);

				glVertex3f(-POINTER_WIDTH, 0.0,            POINTER_HEIGHT);
				glVertex3f( POINTER_WIDTH, 0.0,            POINTER_HEIGHT);
				glVertex3f(0.0,            POINTER_LENGTH, POINTER_HEIGHT);
			glEnd();

		glPopMatrix();

	glPopMatrix();
}

float ToolMarker::PixelToPhysicalPos(GLuint pixel)
{
	if (pDecal)
		return ( (float) pixel + 0.5f ) * pDecal->fSinglePixelSize;
	else
		return 0.0;
}

GLuint ToolMarker::PhysicalToPixelPos(GLdouble pos)
{
	if (pDecal)
		return (GLuint) floor(pos / pDecal->fSinglePixelSize);
	else
		return 0;
}

void ToolMarker::SetPixelPos(GLuint x, GLuint y)
{
	pixelx = x;
	pixely = y;

	if (pDecal)
	{
		xpos = PixelToPhysicalPos(x);
		ypos = PixelToPhysicalPos(y);
	}
}

void ToolMarker::SetWorldPos(GLdouble x, GLdouble y)
{
	GLuint worldpixelx = 0;
	GLuint worldpixely = 0;

	if (pDecal)
	{
		worldpixelx = PhysicalToPixelPos(x);
		worldpixely = PhysicalToPixelPos(y);
	}

	mousevectorx = x - realmousex;
	mousevectory = y - realmousey;

	realmousex = x;
	realmousey = y;

//	printf("mouse vector = (%10.5f, %10.5f)\n", mousevectorx, mousevectory);

//	SetPixelPos(worldpixelx, worldpixely);

	xpos = x;
	ypos = y;
}

void ToolMarker::SetTextureInfo(Decal *pInput)
{
	pDecal = pInput;
}

GLfloat ToolMarker::GetMouseAngle()
{
	return GetVectorAngle(mousevectorx, mousevectory);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -