Kirjautuminen

Haku

Tehtävät

Kilpailu

Ohjelmoi tekoäly!
Arvostele pelit
15.8. klo 12 mennessä!

Keskustelu: Koodit näytille: C++: OpenGL valoluokka (dll)

Sivu 1 / 1

shadez [04.06.2003 17:25:28]

#

OpenGl valoluokka, käytä miten tykkäät, jos haluut että ei oo dll niin poista __declspec(dllexport).

LVector on vektori jne.

// LLight.h

class __declspec(dllexport) LLight
{
public:
	LLight();
	~LLight() {};

	void Setup(int number);
	void Disable();
	void SetPosition(LVector pos, LVector dir);
	void Render();
	void SetColour(LColor diffuse, LColor ambient);
	void SetRays(int num, float angle, float siz);

	LVector GetPosition() { return position; }
	LVector GetDirection() { return direction; }

private:
	bool VisibleRays;
	int NumRays, GlobalOrder;
	float FalloffAngle;
	float Size;
	int numb;

	LColor dif, amb;
	LVector position, direction;
};
#include "L_Light.h"


LLight::LLight()
{
	VisibleRays=false;
	NumRays=0;
	GlobalOrder=0;
}

void LLight::Setup(int number)
{
	unsigned int val=GL_LIGHT0+number;
	numb=number;

	float Ambient[4]={amb.r,amb.g,amb.b,amb.a};
	float Diffuse[4]={dif.r,dif.g,dif.b,dif.a};
	float Position[4]={position.x, position.y, position.z, 1};

	glLightfv(val, GL_AMBIENT, Ambient);
	glLightfv(val, GL_DIFFUSE, Diffuse);
	glLightfv(val, GL_SPECULAR, Diffuse);
	glLightfv(val, GL_POSITION, Position);
	direction.Normalize();

	glEnable(val);
}

void LLight::SetColour(LColor diffuse, LColor ambient)
{
	dif=diffuse;
	amb=LColor(ambient.r,ambient.g,ambient.b,1);
}

void LLight::SetPosition(LVector pos, LVector dir)
{
	position=pos;
	direction=dir;
}

void LLight::SetRays(int num, float angle, float siz)
{
	VisibleRays=true;
	NumRays=num;
	FalloffAngle=angle;
	Size=siz;
}

void LLight::Render()
{
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);

    glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE);

	for(int i=0;i<NumRays;i++)
	{
		float fractality=(float)(((rand()%100)/(float)100)-0.5f)*FalloffAngle;
		float fractality2=(float)(((rand()%100)/(float)100)-0.5f)*FalloffAngle;
		float fractality3=(float)(((rand()%100)/(float)100)-0.5f)*FalloffAngle;
		glBegin(GL_LINES);

		 glColor4f(dif.r,dif.g,dif.b,0.5f);glVertex3f(position.x,position.y,position.z);
		 glColor4f(0,0,0,0.0f);glVertex3f(position.x+direction.x*Size+fractality,position.y+direction.y*Size+fractality2,
			 position.z+direction.z*Size+fractality3);

		glEnd();
	}
	glEnable(GL_DEPTH_TEST);
	glDisable(GL_BLEND);
	glEnable(GL_LIGHTING);
}

void LLight::Disable()
{
	unsigned int val=GL_LIGHT0+numb;
	glDisable(val);
}

Vastaus

Aihe on jo aika vanha, joten et voi enää vastata siihen.

Tietoa sivustosta