Example #1
0
/// Computes lighting for the entire scene
void computeLighting()
{
    for (auto &ridge : mountains)
    {
        for (int i=0; i < ridge.meshVertices.size(); i = i+3)
        {
            // Compute for our (single) light
            Vec3Df vertexpos = Vec3Df(ridge.meshVertices[i],
                                      ridge.meshVertices[i+1],
                                      ridge.meshVertices[i+2]);
            Vec3Df normal = Vec3Df(ridge.meshNormals[i],
                                   ridge.meshNormals[i+1],
                                   ridge.meshNormals[i+2]);
            Vec3Df lighting = computeLighting(vertexpos, normal, DIFFUSE_LIGHTING);
            
            // Pass computed values to Ridge
            ridge.meshColors[i] = lighting[0];
            ridge.meshColors[i+1] = lighting[1];
            ridge.meshColors[i+2] = lighting[2];
        }
    }
	
	if (toggleBoss) {
		std::vector<Vertex> vertices = boss.getMesh().vertices;
		std::vector<Vec3Df> meshColors = std::vector<Vec3Df>(vertices.size());

		auto rotMat = matrixMultiplication(
			rotateMatrixY(boss.angleHeadY*M_PI / 180),
			rotateMatrixX(boss.angleHeadZ*M_PI / 180)
			);

		for (int i = 0; i < vertices.size(); i++)
		{
			// Compute for our (single) light
			Vertex vertex = vertices[i];
			Vec3Df vec = vertex.p;
			vec = calculateMatrix(rotMat, vec);
			vec = vec + boss.translation;
			vec = vec * boss.scale;
			vec = vec + boss.position;

			Vec3Df nor = vertex.n;
			nor = calculateMatrix(rotMat, nor);
			nor = nor + boss.translation;
			nor = nor * boss.scale;
			nor = nor + boss.position;

			Vec3Df lighting = computeLighting(vec, nor, PHONG_LIGHTNING);

			meshColors[i] = lighting;
		}
		boss.getMesh().meshColor = meshColors;
	}
}
Example #2
0
void roomEditorControls(void)
{
	//TEMP CONTROLS
	// if(keysHeld() & KEY_R)editorScale+=inttof32(2);
	// if(keysHeld() & KEY_L)editorScale-=inttof32(2);
	if(keysHeld() & KEY_R)moveCameraImmediate(&editorCamera, vect(0,0,inttof32(1)/32));
	if(keysHeld() & KEY_L)moveCameraImmediate(&editorCamera, vect(0,0,-inttof32(1)/32));
	
	if(keysHeld() & KEY_UP)moveCameraImmediate(&editorCamera, vect(0,inttof32(1)/32,0));
	else if(keysHeld() & KEY_DOWN)moveCameraImmediate(&editorCamera, vect(0,-inttof32(1)/32,0));
	if(keysHeld() & KEY_RIGHT)moveCameraImmediate(&editorCamera, vect(inttof32(1)/32,0,0));
	else if(keysHeld() & KEY_LEFT)moveCameraImmediate(&editorCamera, vect(-inttof32(1)/32,0,0));
	
	if(keysHeld() & KEY_Y)rotateMatrixY(editorCamera.transformationMatrix, 256, true);
	if(keysHeld() & KEY_A)rotateMatrixY(editorCamera.transformationMatrix, -256, true);
	if(keysHeld() & KEY_B)rotateMatrixX(editorCamera.transformationMatrix, 256, false);
	if(keysHeld() & KEY_X)rotateMatrixX(editorCamera.transformationMatrix, -256, false);
	
	// if(keysHeld() & KEY_START){writeMapEditor(&editorRoom, "fat:/test.map");}
	if(keysDown() & KEY_SELECT){switchScreens();}

	// if((keysHeld() & KEY_R) && (keysHeld() & KEY_L))changeState(&editorState);
}
Example #3
0
void applyCameraState(camera_struct* c, cameraState_struct* cs)
{
	if(!c || !cs)return;

	c->position=cs->position;
	c->viewPosition=cs->position;

	initTransformationMatrix(c);
	rotateMatrixX(c->transformationMatrix, cs->angle.x, false);
	rotateMatrixY(c->transformationMatrix, cs->angle.y, false);
	rotateMatrixZ(c->transformationMatrix, cs->angle.z, false);

	// NOGBA("p : %d %d %d",cs->position.x,cs->position.y,cs->position.z);
	// NOGBA("a : %d %d %d",cs->angle.x,cs->angle.y,cs->angle.z);
}
Example #4
0
void initRoomEdition(void)
{
	initLights();
	initBlocks();
	initEntities();
	initInterface();
	initEditorRoom(&editorRoom);
	initContextButtons();
	initSelection(NULL);
	initCamera(&editorCamera);
	// initProjectionMatrixOrtho(&editorCamera, inttof32(-128), inttof32(127),inttof32(-96), inttof32(95), inttof32(-1000), inttof32(1000));
	initProjectionMatrix(&editorCamera, 70*90, inttof32(4)/3, inttof32(1)/10, inttof32(1000)); //TEMP?
	editorCamera.position=vect(0,0,0);
	editorTranslation=vect(0,0,inttof32(-1));
	editorScale=inttof32(1);
	lineOfTouchOrigin=vect(0,0,0);
	lineOfTouchVector=vect(0,0,0);
	currentScreen=false;

	//initial camera setup
	rotateMatrixY(editorCamera.transformationMatrix, 2048+384, true);
	rotateMatrixX(editorCamera.transformationMatrix, 1024+128, false);
	editorScale=inttof32(8*20);

	//controls stuff
	touchRead(&currentTouch);
	oldTouch=currentTouch;

	//cosmetics
	glSetOutlineColor(0,RGB15(0,0,0));
	glSetOutlineColor(1,RGB15(29,15,3));

	glMaterialf(GL_AMBIENT, RGB15(8,8,8));
	glMaterialf(GL_DIFFUSE, RGB15(24,24,24));
	glMaterialf(GL_SPECULAR, RGB15(0,0,0));
	glMaterialf(GL_EMISSION, RGB15(0,0,0));

	glSetToonTableRange(0, 2, RGB15(8,8,8));
	glSetToonTableRange(3, 31, RGB15(24,24,24));

	glLight(0, RGB15(31,31,31), cosLerp(4096)>>3, 0, sinLerp(4096)>>3);
}
Example #5
0
void warpPlayer(portal_s* p, player_s* pl)
{
	if(!p || !pl)return;
	camera_s* c = &pl->camera;

	camera_s new_camera = *c;

	if(gravityGunObject)gravityGunObject = NULL; // TEMP : TODO better solution

	float tmp1[4*4], tmp2[4*4];
	transposeMatrix44(p->target->matrix, tmp1);
	new_camera.position = vaddf(p->target->position, warpPortalVector(p, vsubf(c->position, p->position)));
	multMatrix44((float*)new_camera.orientation, p->matrix, tmp2);
	rotateMatrixY(tmp1, M_PI, true);
	multMatrix44(tmp2, tmp1, (float*)new_camera.orientation);

	memcpy(new_camera.modelview, new_camera.orientation, sizeof(mtx44));
	translateMatrix((float*)new_camera.modelview, -new_camera.position.x, -new_camera.position.y, -new_camera.position.z);

	pl->object.position = new_camera.position;
	pl->object.speed = warpPortalVector(p, pl->object.speed);
	*c = new_camera;
}
Example #6
0
File: main.c Project: minexew/ctrgl
static void set3DView()
{
    static const float nearZ = 0.01f, farZ = 100.0f;
    mtx44 projection, modelView;

    // standard perspective projection
    initProjectionMatrix((float*) projection, 80.0f*M_PI/180.0f, 240.0f/400.0f, nearZ, farZ);
    rotateMatrixZ((float*) projection, M_PI/2, false);   //because framebuffer is sideways...
    glPerspectiveProjectionMatrixfCTR((float*) projection,
            nearZ,  // must match the value passed to initProjectionMatrix

            -5.0f,  // depth of the plane that will converge at screen depth in stereo,
                    // e.g. everything further will be behind the screen, everything closer will pop out

            0.2f    // determine experimentally; allows you to mix multiple views in one coherent stereo
            );

    // poor man's camera control
    loadIdentity44((float*) modelView);
    translateMatrix((float*) modelView, position.x, position.y, position.z);
    rotateMatrixX((float*) modelView, angle.x, false);
    rotateMatrixY((float*) modelView, angle.y, false);
    glModelviewMatrixfCTR((float*) modelView);
}
Example #7
0
void roomEditorCursor(selection_struct* sel)
{
	if(!sel)sel=&editorSelection;
	if((keysDown() & KEY_TOUCH) && !(sel->entity && !sel->entity->placed))
	{
		u8 type;
		void* ptr=getBlockEntityTouch(&type);
		if(sel->entity && sel->selectingTarget)
		{
			if(type)
			{
				sel->selectingTarget=false;
				sel->entity->target=(entity_struct*)ptr;
				cleanUpContextButtons();
			}
		}else{
			if(type)
			{
				//entity
				entity_struct* e=(entity_struct*)ptr;

				undoSelection(sel);
				sel->active=true;
				sel->selecting=false;
				sel->selectingTarget=false;
				sel->entity=e;
			}else{
				//blockface
				blockFace_struct* bf=(blockFace_struct*)ptr;

				if(bf)
				{
					if(sel->active && isFaceInSelection(bf, sel))
					{
						sel->currentFace=bf;
						sel->currentPosition=vect(bf->x,bf->y,bf->z);
						sel->selecting=false;
						sel->selectingTarget=false;
					}else{
						undoSelection(sel);
						sel->firstFace=sel->secondFace=bf;
						sel->active=true;
						sel->selecting=true;
						sel->selectingTarget=false;
					}
					sel->entity=NULL;
				}else{
					undoSelection(sel);
				}
			}			
		}
	}else if(keysHeld() & KEY_TOUCH)
	{
		if(sel->active && !(sel->entity && sel->selectingTarget))
		{
			if(sel->entity)
			{
				blockFace_struct* bf=getBlockFaceTouch(NULL);
				if(bf)
				{
					sel->error=!moveEntityToBlockFace(sel->entity, bf);
				}
			}else{
				if(sel->selecting)
				{
					blockFace_struct* bf=getBlockFaceTouch(NULL);
					if(bf)sel->secondFace=bf;
				}else{
					blockFace_struct* bf=sel->currentFace;
					bool fill=true;
					vect3D p=getDragPosition(bf, lineOfTouchOrigin, lineOfTouchVector, lineOfTouchVector);
					p=vect((p.x+(ROOMARRAYSIZEX*BLOCKSIZEX+BLOCKSIZEX)/2)/BLOCKSIZEX,(p.y+(ROOMARRAYSIZEY*BLOCKSIZEY+BLOCKSIZEY)/2)/BLOCKSIZEY,(p.z+(ROOMARRAYSIZEZ*BLOCKSIZEZ+BLOCKSIZEZ)/2)/BLOCKSIZEZ);
					
					switch(bf->direction)
					{
						case 0:  p.y=bf->y; p.z=bf->z; fill=p.x>sel->currentPosition.x; break;
						case 1:  p.y=bf->y; p.z=bf->z; fill=p.x<sel->currentPosition.x; break;
						case 2:  p.x=bf->x; p.z=bf->z; fill=p.y>sel->currentPosition.y; break;
						case 3:  p.x=bf->x; p.z=bf->z; fill=p.y<sel->currentPosition.y; break;
						case 4:  p.x=bf->x; p.y=bf->y; fill=p.z>sel->currentPosition.z; break;
						default: p.x=bf->x; p.y=bf->y; fill=p.z<sel->currentPosition.z; break;
					}

					if(p.x!=sel->currentPosition.x || p.y!=sel->currentPosition.y || p.z!=sel->currentPosition.z)
					{
						blockFace_struct oldFirstFace=*sel->firstFace;
						blockFace_struct oldSecondFace=*sel->secondFace;
						blockFace_struct oldCurrentFace=*sel->currentFace;

						vect3D v=vectDifference(p, sel->currentPosition);
						vect3D o=(bf->direction%2)?(sel->origin):(adjustVectForNormal(bf->direction, sel->origin)); vect3D s=v;
						fixOriginSize(&o, &s); s=adjustVectForNormal((bf->direction%2)?(bf->direction):(oppositeDirection[bf->direction]), addVect(s,sel->size));
						vect3D oe=adjustVectForNormal(bf->direction, sel->origin); vect3D se=sel->size;

						moveEntitiesRange(oe, se, v);
						if(fill)fillBlockArrayRange(editorRoom.blockArray, &editorRoom.blockFaceList, o, s);
						else emptyBlockArrayRange(editorRoom.blockArray, &editorRoom.blockFaceList, o, s);
						getEntityBlockFacesRange(editorRoom.blockFaceList, addVect(oe,v), se, true);

						adjustSelection(&editorRoom, sel, oldFirstFace, oldSecondFace, oldCurrentFace, v);
						sel->currentPosition=p;
					}
				}
			}
		}else{
			if(abs(oldTouch.px-currentTouch.px)>2)rotateMatrixY(editorCamera.transformationMatrix, -TOUCHSPEEDX*(oldTouch.px-currentTouch.px), true);
			if(abs(oldTouch.py-currentTouch.py)>2)rotateMatrixX(editorCamera.transformationMatrix, -TOUCHSPEEDY*(oldTouch.py-currentTouch.py), false);
		}
	}else if(keysUp() & KEY_TOUCH)
	{
		if(sel->active)
		{
			if(sel->entity && sel->entity->type)
			{
				if(!sel->selectingTarget)setupContextButtons(sel->entity->type->contextButtonsArray, sel->entity->type->numButtons);
				else setupContextButtons(targetSelectionButtonArray, 2);
			}else if(sel->planar && sel->firstFace && (sel->firstFace->direction==2 || sel->firstFace->direction==3))setupContextButtons(groundSelectionButtonArray, 4);
			else if(sel->planar)setupContextButtons(planarSelectionButtonArray, 2);
			else setupContextButtons(nonplanarSelectionButtonArray, 4);
		}
	}
}