Graphics::Graphics(const RECT& rect) : stage(rect) {
	linePainter = new LinePainter(rect);

	AssertEx(rect.bottom - rect.top == rect.right - rect.left, "only square stage is supported");

	camera = new Camera(moveSpeed, rotateSpeed, rect.bottom - rect.top);

	LightAttribute lightAttr;
	lightAttr.diffuse = Color(255, 255, 255);
	lightAttr.direction = Vector3::right;
	lightAttr.lightOn = true;
	lightAttr.lightType = LightTypeDirection;
	lightAttr.position.Set(200, 0, 0);
	camera->AddLight(Light(lightAttr));

	lightAttr.ambient = Color(90, 90, 90);
	lightAttr.lightType = LightTypeAmbient;
	lightAttr.lightOn = true;
	camera->AddLight(Light(lightAttr));

	zBuffer = new ZBuffer(stage.right - stage.left, stage.bottom - stage.top);

	VertexContainer vertices;
	IndexedTriangleContainer triangles;
	CreatePlane(vertices, triangles, Texture("bmp/metal.bmp"), 2, 3);
	street = new Object();
	//street->Initialize(vertices, triangles, 5.f, 12.f, Vector3(), Vector3());
	AddObject(street);

	xmin = stage.left + 1;
	xmax = stage.right - 2;
	ymin = stage.top + 1;
	ymax = stage.bottom - 2;
}
Example #2
0
/** Can a player see something?
 * \param player the looker.
 * \param thing object to be seen.
 * \param can_see_loc 1 if player can see the location, 0 if location is dark.
 * \retval 1 player can see thing.
 * \retval 0 player can not see thing.
 */
int
can_see(dbref player, dbref thing, int can_see_loc)
{
  if (!can_interact(thing, player, INTERACT_SEE, NULL))
    return 0;

  /*
   * 1) your own body isn't listed in a 'look' 2) exits aren't listed in a
   * 'look' 3) unconnected (sleeping) players aren't listed in a 'look'
   */
  if (player == thing || IsExit(thing) ||
      (IsPlayer(thing) && !Connected(thing)))
    return 0;

  /* if thing is in a room set LIGHT, it can be seen */
  else if (IS(Location(thing), TYPE_ROOM, "LIGHT"))
    return 1;

  /* if the room is non-dark, you can see objects which are light or non-dark */
  else if (can_see_loc)
    return (Light(thing) || !DarkLegal(thing));

  /* otherwise room is dark and you can only see lit things */
  else
    return (Light(thing));
}
Example #3
0
/* SCENE DESCRIPTION:
 *    -> Cube test.
 */
void sceneFive()
{
    /* First, allocates enough space for all the structures.*/
    noObjects = 2;
    noLights = 2;

    objects = new Object *[noObjects];
    lights = new Light[noLights];

    /* Spheres initialization. */
    Cube *cube = new Cube(200.0,300, 500.0, 200,200,200, 1.0, 0.0, 0.0);
    (*cube).setReflection(0.0);
    (*cube).setShininess(50);
    (*cube).setSpecular(1, 1, 1);
    (*cube).setRefraction(0.0);

    objects[0] = cube;

    /* Back wall.*/
    vector normalOne = {1, 0, 0};
    Plane *plane = new Plane(0,0,0, normalOne, 0.1,0.1,0.8);
    (*plane).setReflection(0.0);
    (*plane).setShininess(50);
    (*plane).setSpecular(0.1, 0.1, 0.1);
    (*plane).setRefraction(0);

    objects[1] = plane;

    /* Lights initialization. */
    //lights[0] = Light(300,10000,6000, 1.0, 1, 1, 1);
    lights[0] = Light(300,400,-1000, 1.0, 1, 1, 1);
    lights[1] = Light(1000,400,500, 1.0, 1, 1, 1);
}
Example #4
0
/* SCENE DESCRIPTION:
 *    -> There is one ground plane and two spheres, one blue and another red.
 */
void sceneThree()
{
    /* First, allocates enough space for all the structures.*/
    noObjects = 4;
    noLights = 2;

    objects = new Object *[noObjects];
    lights = new Light[noLights];

    /* Spheres initialization. */
    Sphere *sphere = new Sphere(500.0,500, 800.0, 280.0, 0.0, 0.0, 0.0);
    (*sphere).setReflection(0.9);
    (*sphere).setShininess(50);
    (*sphere).setSpecular(1, 1, 1);
    (*sphere).setRefraction(0.0);

    objects[0] = sphere;

    sphere = new Sphere(50.0,520.0, 600.0, 200.0, 0.0, 0.0, 1.0);
    (*sphere).setReflection(0.0);
    (*sphere).setShininess(50);
    (*sphere).setSpecular(1, 1, 1);
    (*sphere).setRefraction(0.0);

    /*sphere = new Sphere(450.0,300.0, 100.0, 50.0, 0.1, 0.1, 0.1);
    (*sphere).setReflection(0.0);
    (*sphere).setShininess(10);
    (*sphere).setSpecular(0.2, 0.2, 0.2);
    (*sphere).setDiffuse(0.2, 0.2, 0.2);
    (*sphere).setRefraction(0.5);*/

    objects[1] = sphere;

    /* Planes initialization. */

    /* Ground. */
    vector normalZero = {0, 1, 0};
    Plane *plane = new Plane(0,0,0, normalZero, 0.0,0.0,0.7);
    (*plane).setReflection(0.0);
    (*plane).setShininess(20);
    (*plane).setSpecular(0.6, 0.4, 0.2);
    (*plane).setRefraction(0);

    objects[2] = plane;

    /* Right wall. */
    vector normalOne = {-1, 0, 0};
    plane = new Plane(1600,0,0, normalOne, 0.0,0.0,0.0);
    (*plane).setReflection(0.9);
    (*plane).setShininess(50);
    (*plane).setSpecular(1, 1, 1);
    (*plane).setRefraction(0);

    objects[3] = plane;

    /* Lights initialization. */
    lights[0] = Light(300,10000,6000, 1.0, 1, 1, 1);
    lights[1] = Light(300,400,-6000, 1.0, 1, 1, 1);
}
Example #5
0
/* Show the 'Obvious Exits' list for a room. Used in 'look' and 'examine'.
 * \param player The player looking
 * \param loc room whose exits we're showing
 * \param exit_name "Obvious Exits" string
 * \param pe_info the pe_info to use for evaluating EXITFORMAT and interact locks
 */
static void
look_exits(dbref player, dbref loc, const char *exit_name, NEW_PE_INFO *pe_info)
{
  dbref thing;
  char *tbuf1, *tbuf2, *nbuf;
  char *s1, *s2;
  char *p;
  int exit_count, this_exit, total_count;
  int texits;
  ufun_attrib ufun;
  PUEBLOBUFF;

  /* make sure location is a room */
  if (!IsRoom(loc))
    return;

  tbuf1 = (char *) mush_malloc(BUFFER_LEN, "string");
  tbuf2 = (char *) mush_malloc(BUFFER_LEN, "string");
  nbuf = (char *) mush_malloc(BUFFER_LEN, "string");
  if (!tbuf1 || !tbuf2 || !nbuf)
    mush_panic("Unable to allocate memory in look_exits");
  s1 = tbuf1;
  s2 = tbuf2;
  texits = exit_count = total_count = 0;
  this_exit = 1;

  if (fetch_ufun_attrib
      ("EXITFORMAT", loc, &ufun, UFUN_IGNORE_PERMS | UFUN_REQUIRE_ATTR)) {
    char *arg, *buff, *bp;
    PE_REGS *pe_regs = pe_regs_create(PE_REGS_ARG, "look_exits");

    arg = (char *) mush_malloc(BUFFER_LEN, "string");
    buff = (char *) mush_malloc(BUFFER_LEN, "string");
    if (!arg || !buff)
      mush_panic("Unable to allocate memory in look_exits");

    bp = arg;
    DOLIST(thing, Exits(loc)) {
      if (((Light(loc) || Light(thing)) || !(Dark(loc) || Dark(thing)))
          && can_interact(thing, player, INTERACT_SEE, pe_info)) {
        if (bp != arg)
          safe_chr(' ', arg, &bp);
        safe_dbref(thing, arg, &bp);
      }
    }
    *bp = '\0';
    pe_regs_setenv_nocopy(pe_regs, 0, arg);

    call_ufun(&ufun, buff, player, player, pe_info, pe_regs);

    pe_regs_free(pe_regs);
    notify_by(loc, player, buff);
    mush_free(tbuf1, "string");
    mush_free(tbuf2, "string");
    mush_free(nbuf, "string");
    mush_free(arg, "string");
    mush_free(buff, "string");
    return;
  }
/*!****************************************************************************
 @Function		main
 @Return		int			result code to OS
 @Description	Main function of the program
******************************************************************************/
int main()
{
    initEGL();
    Init();
    //create_texture();

	for(;;)
	{
		glClear(GL_COLOR_BUFFER_BIT);
		/*
			Clears the color buffer.
			glClear() can also be used to clear the depth or stencil buffer
			(GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT)
		*/
		glClearColor(0.0, 0.5, 0.5, 1.0);
		glClear(GL_DEPTH_BUFFER_BIT);
		if (!TestEGLError("glClear"))
		{
			goto cleanup;
		}


		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glColorMask(false, true, true, true);
		Light(0); 
		Render(0); 
		glClear( GL_DEPTH_BUFFER_BIT) ;
		glColorMask(true, false, false, true);
		Light(1); 
		Render(1); 
		glColorMask( true, true, true, true);

		XRotate+=0.5; 
		/*
			Swap Buffers.
			Brings to the native display the current render surface.
		*/
		eglSwapBuffers(eglDisplay, eglSurface);
		if (!TestEGLError("eglSwapBuffers"))
		{
			goto cleanup;
		}
	}

	/*
		Step 8 - Terminate OpenGL ES and destroy the window (if present).
		eglTerminate takes care of destroying any context or surface created
	*/
cleanup:
	// Delete the VBO as it is no longer needed
	glDeleteBuffers(1, &ui32Vbo);
	eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) ;
	eglTerminate(eglDisplay);

	return 0;
}
Example #7
0
/* SCENE DESCRIPTION:
 *    -> Sea theme.
 */
void sceneFour()
{
    fadingCoeficient = 100000;
    fullLightLimit = 1000000;

    /* First, allocates enough space for all the structures.*/
    noObjects = 4;
    noLights = 2;

    objects = new Object *[noObjects];
    lights = new Light[noLights];

    /* Spheres initialization. */
    Sphere *sphere = new Sphere(550.0,400, 500.0, 180.0, 0.0, 0.0, 0.0);
    (*sphere).setReflection(0.0);
    (*sphere).setShininess(50);
    (*sphere).setSpecular(1, 1, 1);
    (*sphere).setRefraction(0.5);

    objects[0] = sphere;

    sphere = new Sphere(300.0,380.0, 1000.0, 150.0, 0.0, 0.0, 1.0);
    (*sphere).setReflection(0.0);
    (*sphere).setShininess(50);
    (*sphere).setSpecular(1, 1, 1);
    (*sphere).setRefraction(0.0);

    objects[1] = sphere;

    /* Planes initialization. */

    /* Ground. */
    vector normalZero = {0, 1, 0};
    Plane *plane = new Plane(0,0,0, normalZero, 0.0,0.0,0.3);
    (*plane).setReflection(0.5);
    (*plane).setShininess(20);
    (*plane).setSpecular(0.6, 0.6, 0.6);
    (*plane).setRefraction(0.0);

    objects[2] = plane;

    /* Back wall.*/
    vector normalTwo = {0, 0, -1};
    plane = new Plane(0,0,100000, normalTwo, 0.1,0.1,0.8);
    (*plane).setReflection(0.5);
    (*plane).setShininess(0.1);
    (*plane).setSpecular(0.1, 0.1, 0.1);
    (*plane).setRefraction(0);

    objects[3] = plane;

    /* Lights initialization. */
    lights[0] = Light(300,10000,6000, 1.0, 1, 1, 1);
    lights[1] = Light(300,10000,-6000, 1.0, 1, 1, 1);
}
Example #8
0
/* SCENE DESCRIPTION:
 *    -> The triangle scene test.
 */
void sceneTriangles()
{

    /* First, allocates enough space for all the structures.*/
    noObjects = 3;
    noLights = 2;

    objects = new Object *[noObjects];
    lights = new Light[noLights];

    /* Triangles initialization. */
    Triangle *triangle = new Triangle(1.0, 0.0, 0.0);
    (*triangle).setVertix(2, 700, 400, 1000);
    (*triangle).setVertix(1, 900, 400, 200);
    (*triangle).setVertix(0, 800, 700, 1700);
    (*triangle).setNormal();
    (*triangle).setReflection(0.0);
    (*triangle).setShininess(50);
    (*triangle).setSpecular(1, 1, 1);
    (*triangle).setRefraction(0.0);

    objects[0] = triangle;

    triangle = new Triangle(0.0, 1.0, 0.0);
    (*triangle).setVertix(2, 800, 700, 1700);
    (*triangle).setVertix(1, 900, 400, 200);
    (*triangle).setVertix(0, 1200, 700, 500);
    (*triangle).setNormal();
    (*triangle).setReflection(0.0);
    (*triangle).setShininess(50);
    (*triangle).setSpecular(1, 1, 1);
    (*triangle).setRefraction(0.0);

    objects[1] = triangle;

    triangle = new Triangle(0.0, 0.0, 1.0);
    (*triangle).setVertix(2, 900, 400, 200);
    (*triangle).setVertix(1, 1600, 500, 1000);
    (*triangle).setVertix(0, 1200, 700, 500);
    (*triangle).setNormal();
    (*triangle).setReflection(0.0);
    (*triangle).setShininess(50);
    (*triangle).setSpecular(1, 1, 1);
    (*triangle).setRefraction(0.0);

    objects[2] = triangle;

    /* Lights initialization. */
    lights[0] = Light(0,10000,6000, 1.0, 1, 1, 1);
    lights[0] = Light(800,700,-6000, 1.0, 1, 1, 1);

}
Example #9
0
int main() {
   const int height = 2000;
   const int width = 2000;
        
   ofstream image;
   image.open("out.ppm");
   image << "P3" << '\n' << width << ' ' << height << '\n' << 255 << '\n';
        
   Point camera(0,0,0);
        
   Light lights [3] = { Light(Point(1200,0,800), Colour(255,0,0)),
                        Light(Point(1200,800,0), Colour(0,255,0)),
                        Light(Point(1200,-800,0), Colour(0,0,255)) };
        
   Colour background;

   Sphere sphere(Point(2000,0,0),700);

   Point plane_point;
   Point surface_point;
        
   //std::cout << illuminate(Point(0,0,0),Vector(2,2,2),Light(Point(4,4,4),Colour(2,2,2))).convertToString() << std::endl;
        
   //std::cout << Line(Point(0,0,0),Vector(1,0,0)).intersect(Sphere(Point(10,0,0),2)) << std::endl;
        
   Line ray;
   Vector direction;
   Colour point_colour;
   for (int z = 1000; z > -1000; z-=1) {
      for (int y = -1000; y < 1000; y+=1) {
         plane_point = Point(1000,y,z);
         direction = plane_point - camera;

         ray = Line(camera, direction);

         if (ray.intersect(sphere)) {
            surface_point = ray.point_intersect(sphere);
            point_colour = illuminate(surface_point, surface_point - sphere.center(), lights);
            point_colour = boundColour(point_colour, 0, 255);
            image << point_colour.convertToString() << ' ';
            //image << "255 255 255 ";
         } else {
            image << background.convertToString() << ' ';
         }
      }
      image << '\n';
   }

   image.close();

   return 0;
}
Example #10
0
int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    QTextCodec *codec = QTextCodec::codecForName("gb2312");
    QTextCodec::setCodecForCStrings(codec);
    QTextCodec::setCodecForLocale(codec);
    QTextCodec::setCodecForTr(codec);

    app.setApplicationName("bowling");
    QPixmapCache::setCacheLimit(100 * 1024); // 100 MB
    if (!createConnection())
            return -1;

    const char *map =
            "#####=######"
            "#          #"
            "#          #"
            "#          #"
            "#          #"
            "#          #"
            "#          #"
            "#          #"
            "#          *"
            "#          #"
            "#          #"
            "#          #"
            "#          #"
            "#          #"
            "#          #"
            "#          #"
            "#          $"
            "#          #"
            "#          #"
            "#######(####";

    QVector<Light> lights;
    lights << Light(QPointF(3.5, 2.5), 1)
           << Light(QPointF(3.5, 6.5), 1)
           << Light(QPointF(1.5, 10.5), 0.3);

    MazeScene *scene = new MazeScene(lights, map, 12, 20);

    View view;
    view.resize(800, 600);
    view.setScene(scene);
    view.show();

    scene->toggleRenderer();

    return app.exec();
}
Example #11
0
bool
can_see(dbref player, dbref thing, bool can_see_loc)
{
    if (!OkObj(player) || !OkObj(thing))
        return 0;

    if (player == thing || Typeof(thing) == TYPE_EXIT
        || Typeof(thing) == TYPE_ROOM)
        return 0;

    if (Light(thing))
        return 1;

    if (can_see_loc) {
        switch (Typeof(thing)) {
            case TYPE_PROGRAM:
                return ((FLAGS(thing) & LINK_OK) || controls(player, thing)
                        || (POWERS(player) & POW_SEE_ALL));
            case TYPE_PLAYER:
                if (tp_dark_sleepers) {
                    return (!Dark(thing) || online(thing)
                            || (POWERS(player) & POW_SEE_ALL));
                }
            default:
                return (!Dark(thing) || (POWERS(player) & POW_SEE_ALL) ||
                        (controls(player, thing) && !(FLAGS(player) & STICKY)));

        }
    } else {
        /* can't see loc */
        return (controls(player, thing) && !(FLAGS(player) & STICKY));
    }
}
Example #12
0
	void LightManager::popLight()
	{
		if( curNumLights > 0 )
		{
			m_Lights[ --curNumLights ] = Light();
		}
	}
void LightingManager::Init(Shader lightingShader)
{
	_shader = lightingShader.shaderPointer;
	glUseProgram(_shader);
	for (int i = 0; i < MAX_LIGHTS; ++i)
	{
		_lights[i] = Light();
		_lights[i].position = glm::vec3();
		_lights[i].linearVelocity = glm::vec3();
		_lights[i].rotation = glm::quat();
		_lights[i].rotationOrigin = glm::vec3();
		_lights[i].angularVelocity = glm::quat();
		_lights[i].transformPos = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
		_lights[i].color = glm::vec4();
		_lights[i].power = 0.0f;

		std::string currentLight = "lights[";
		char numStringBuffer[32];
		itoa(i, numStringBuffer, 10);
		currentLight += numStringBuffer;
		currentLight += "].";
		std::string pos = "position";
		std::string col = "color_difPower";
		_lights[i].uPosition = glGetUniformLocation(_shader, (currentLight + pos).c_str());
		_lights[i].uColor_difPower = glGetUniformLocation(_shader, (currentLight + col).c_str());
	}	

	_uAmbient = glGetUniformLocation(_shader, "ambient");
}
Example #14
0
void ParticleRenderer::CreateTempLight(const vec3& color, float strength, const vec3& position, const vec3& velocity, const vec3& target_velocity, float time_factor) {
	if (lights_.size() < max_light_count_) {
		lights_.push_back(Light(color, strength, position, velocity, target_velocity, time_factor));
		//log_.Infof("Creating new light with strength %f", strength);
	} else {
		int darkest_light_index = -1;
		float darkest_light_strength = 1e15f;
		int i = 0;
		LightArray::iterator x = lights_.begin();
		for (; x < lights_.end(); ++x, ++i) {
			if (x->strength_ < darkest_light_strength) {
				darkest_light_index = i;
				darkest_light_strength = x->strength_;
			}
		}
		if (strength >= darkest_light_strength && darkest_light_index >= 0) {
			//mLog.Infof("Overtaking light with render ID %i (had strength %f, got strength %f"), mLights[lDarkestLightIndex].mRenderLightId, mLights[lDarkestLightIndex].mStrength, pStrength);
			// TRICKY: don't overwrite! We must not leak the previosly allocated hardware light!
			lights_[darkest_light_index].color_ = color;
			lights_[darkest_light_index].strength_ = strength;
			lights_[darkest_light_index].position_ = position;
			lights_[darkest_light_index].velocity_ = velocity;
			lights_[darkest_light_index].target_velocity_ = target_velocity;
			lights_[darkest_light_index].time_factor_ = time_factor;
		}
	}
}
Example #15
0
//-----------------------------------------------------------------------------
void mglGraphGLUT::Window(int argc, char **argv,int (*draw)(mglGraph *gr, void *p),const char *title, void *par, void (*reload)(int next, void *p), bool maximize)
{
	NumFig=0;	curr_fig=1;	tt=0;
	_mgl_glwnd = this;
	CurFrameId = 1;

	char *tmp[1];	tmp[0]=new char[1];	tmp[0][0]=0;
	glutInit(&argc, argv ? argv:tmp);
	delete []tmp[0];
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowSize(600, 600);
	glutCreateWindow("MathPlotLibrary");

	Light(0,mglPoint(0,0,3),false);
	NumFig = draw(this,par)-1;	Finish();
	DrawFunc = draw;	FuncPar = par;
	LoadFunc = reload;
	glutSetWindowTitle(title);

	glutDisplayFunc(_mgl_display);
	glutKeyboardUpFunc(_mgl_key_up);
	glutTimerFunc(int(1000*Delay),_mgl_timer,0);

	// TODO Add window maximazing at start up ???

	glutMainLoop();
	glDeleteLists(1,NumFig);
}
Example #16
0
Light operator*(const double& scalar, const Light& light) {
  return Light(
    scalar * light.red,
    scalar * light.green,
    scalar * light.blue
  );
}
Example #17
0
BOOL CLogo::Tick(DWORD fElapsedTime, BOOL skip)
{
	m_lText += fElapsedTime;
	m_lElapsedTime += fElapsedTime;
	if (!m_bEntering && m_lText > 2500) {
		Light(RL_START);
		m_lText = 0;
		m_bEnableSkip = TRUE;
	}
	if (skip && m_bEnableSkip) m_bEntering = TRUE;
	if (echoes.empty()) {
		if (m_bEntering) return TRUE;
		else if (m_lElapsedTime > 10000) {
			Fire();
			m_lElapsedTime = 0;
		}
	} else if (echoes[0]->IsGone()) {
		ClearCircles();
	}

	for (UINT i(0); i < echoes.size(); ++i) 
		echoes[i]->Tick(fElapsedTime);
	for (ElementsIt it(elements.begin()); it != elements.end();) {
		(*it)->Tick(fElapsedTime);
		if ((*it)->IsGone()) {
			SAFE_DELETE(*it);
			it = elements.erase(it);
			continue;
		}
		++it;
	}
	//return skip;	// Toggle comment here to enable skip anytime
	return FALSE;
}
Example #18
0
Light Light::reflect_on(const rt::color& color) const {
  return Light(
    color.get_red() / 255.0 * red,
    color.get_green() / 255.0 * green,
    color.get_blue() / 255.0 * blue
  );
}
Example #19
0
/** Return the first object near another object that is visible to a player.
 *
 * BEWARE:
 *
 * first_visible() does not behave as intended. It _should_ return the first
 * object in `thing' that is !DARK. However, because of the controls() check
 * the function will return a DARK object if the player owns it.
 *
 * The behavior is left as is because so many functions in fundb.c rely on
 * the incorrect behavior to return expected values. The lv*() functions
 * also make rewriting this fairly pointless.
 *
 * \param player the looker.
 * \param thing an object in the location to be inspected.
 * \return dbref of first visible object or NOTHING.
 */
dbref
first_visible(dbref player, dbref thing)
{
  int lck = 0;
  int ldark;
  dbref loc;

  if (!GoodObject(thing) || IsRoom(thing))
    return NOTHING;
  loc = IsExit(thing) ? Source(thing) : Location(thing);
  if (!GoodObject(loc))
    return NOTHING;
  ldark = IsPlayer(loc) ? Opaque(loc) : Dark(loc);

  while (GoodObject(thing)) {
    if (can_interact(thing, player, INTERACT_SEE, NULL)) {
      if (DarkLegal(thing) || (ldark && !Light(thing))) {
        if (!lck) {
          if (See_All(player) || (loc == player) || controls(player, loc))
            return thing;
          lck = 1;
        }
        if (controls(player, thing))    /* this is what causes DARK objects to show */
          return thing;
      } else {
        return thing;
      }
    }
    thing = Next(thing);
  }
  return thing;
}
Example #20
0
void World::RenderGroup(SceneGroup *i, mat4 t) 
{
	int ii, time = 0;
	// sphere vars
	double r;
	MaterialInfo m;
	
	// light vars
	LightInfo l;
	
	// camera vars
	CameraInfo f;
	   
	// if this is a terminal node
	if (i->getChildCount() == 0) {
		
		// if this node is a sphere
		if (i->computeSphere(r,m,time)) {
			_spheres.push_back(Sphere(vec4(0,0,0,1), r, m, t));
		} else if (i->computeLight(l)) {
			
			if (l.type == LIGHT_POINT) {
				_lights[l.type].push_back(Light(vec3(t*vec4(0,0,0,1),VW),0, l));
			}else if (l.type == LIGHT_DIRECTIONAL){
				_lights[l.type].push_back(Light(0,vec3(t*vec4(0,0,-1,0),VW), l));
			}else if (l.type == LIGHT_AMBIENT)
				_ambientLight = l.color;
				
		} else if (i->computeCamera(f)) {
			vec4 eye(0.0, 0.0, 0.0, 1.0);
		    vec4 LL(f.sides[FRUS_LEFT], f.sides[FRUS_BOTTOM], -1*f.sides[FRUS_NEAR], 1.0);
		    vec4 UL(f.sides[FRUS_LEFT], f.sides[FRUS_TOP], -1*f.sides[FRUS_NEAR], 1.0);
		    vec4 LR(f.sides[FRUS_RIGHT], f.sides[FRUS_BOTTOM], -1*f.sides[FRUS_NEAR], 1.0);
		    vec4 UR(f.sides[FRUS_RIGHT], f.sides[FRUS_TOP], -1*f.sides[FRUS_NEAR], 1.0);

		    _view = Viewport(eye, LL, UL, LR, UR, IMAGE_WIDTH, IMAGE_HEIGHT);
		}
		
	} else {
		
		// expand and traverse this node
		for(ii=0; ii<i->getChildCount();ii++) 
			RenderInstance(i->getChild(ii), t);
		
	}
	
}
Example #21
0
inline Light Scene::light(unsigned i) const
{
	if(i < _lights.size()) {
		return _lights[i];
	} else {
		return Light(Point(), Colour());
	}
}
Example #22
0
Light Scene::determine_light_from_sources_at(const Point& point, const rt::vector normal_vector) const {
  Light light = Light();
  for (std::vector<Source>::const_iterator it = sources.begin(); it != sources.end(); ++it) {
    if (! this->obstructs(it->get_origin(), point)) {
      light = light + std::abs((it->get_origin() - point).unit() | normal_vector) * it->get_light();
    }
  }
  return light;
}
Example #23
0
void initSceneData() {
  scene = loadScene("data/room.obj");
  scene.generateBvhs();
  scene.setCamera(Camera(glm::vec3(0.0f, 2.0f, -4.0f),
                         glm::vec3(0.0f, 1.5f, -1.5f),
                         glm::vec3(0.0f, 1.0f, 0.0f),
                         60.0f, PROJ_WIDTH, PROJ_HEIGHT));
  scene.addLight(Light(glm::vec3(0.0f, 2.99f, -0.75f),
                       glm::vec3(1.0f, 1.0f, 1.0f), 20.0f));
}
Example #24
0
FacetApp::FacetApp():m_facet(Vector4(1.0f,2.0f,3.0f,1.0f),Vector4(1.0f,2.0f,3.0f,1.0f),
		Vector4(1.0f,2.0f,3.0f,1.0f),Vector4(1.0f,2.0f,3.0f,1.0f),Material(White,White,3.0f),
		Material(White,White,3.0f),Material(White,White,3.0f),(LearningCam*)NULL,
		(std::vector<Light*>)NULL,(Uint16*)NULL,(Uint16*)NULL,(Uint16*)NULL) {
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0,RES_X,RES_Y,0);
	glPointSize(8.0f);
	glClearColor(1.0f,1.0f,1.0,0.0f);
	m_l1 = new Uint16[SCREEN_SIZE];
	m_l2 = new Uint16[SCREEN_SIZE];
	m_l3 = new Uint16[SCREEN_SIZE];
	m_ambient = Light(AMBIENT, White, Vector4(.0f,.0f,.0f,.0f), Vector4(3.0f,.0f,.0f,.0f));
	m_dir = Light(DIR, White, Vector4(5.0f,.0f,.0f,.0f), Vector4(3.0f,1.0f,2.0f,.0f));
	m_lights.push_back(&m_ambient);
	m_lights.push_back(&m_dir);
	m_facet.SetCam(&m_cam);
	m_facet.SetLights(m_lights);
}
//----------------------------------------------------------------------------
void ReflectionsAndShadows::CreatePlanarReflection ()
{
    Light* projector = new0 Light(Light::LT_DIRECTIONAL);
    projector->DVector = -AVector::UNIT_X;
    LightNode* projectorNode = new0 LightNode(projector);
    mScene->AttachChild(projectorNode);

    mPREffect = new0 PlanarReflectionEffect(1);
    mPREffect->SetPlane(0, mPlane1);
    mPREffect->SetReflectance(0, 0.25f);
}
Example #26
0
void HDRScene::initialBind()
{
   hdrExposureProg->addUniform("M");
   hdrExposureProg->addUniform("V");
   hdrExposureProg->addUniform("P");
   hdrExposureProg->addUniform("N");
   hdrExposureProg->addUniformStruct("material", TexturedMaterial::getStruct());

   hdrExposureProg->addStructArray("pointLights",8,Light::getStruct());
   hdrExposureProg->addUniform("numPointLights");

   hdrPostProcessProg->addUniform("M");
   hdrPostProcessProg->addUniform("screenTexture");

   hdrPostProcessProg->enable();
   glm::mat4 I(1.0);
   hdrPostProcessProg->getUniform("M").bind(I);
   hdrPostProcessProg->disable();


   hdrExposureProg->enable();
   glm::mat4 P = camera.getPerspectiveMatrix();
   hdrExposureProg->getUniform("P").bind(P);
   woodTex.bind(hdrExposureProg->getUniformStruct("material"));


   std::vector<glm::vec3> lightPositions;
    lightPositions.push_back(glm::vec3(0.0f, 0.0f, 49.5f)); // back light
    lightPositions.push_back(glm::vec3(-1.4f, -1.9f, 9.0f));
    lightPositions.push_back(glm::vec3(0.0f, -1.8f, 4.0f));
    lightPositions.push_back(glm::vec3(0.8f, -1.7f, 6.0f));
    // - Colors
    std::vector<glm::vec3> lightColors;
    lightColors.push_back(glm::vec3(200.0f, 200.0f, 200.0f));
    lightColors.push_back(glm::vec3(0.1f, 0.0f, 0.0f));
    lightColors.push_back(glm::vec3(0.0f, 0.0f, 0.2f));
    lightColors.push_back(glm::vec3(0.0f, 0.1f, 0.0f));

    std::vector<float> lightAttenuation;
    lightAttenuation.push_back(20.0);
    lightAttenuation.push_back(150.0);
    lightAttenuation.push_back(150.0);
    lightAttenuation.push_back(150.0);

   Program::UniformStructArrayInfo arrInfo = hdrExposureProg->getStructArray("pointLights");
   for(int i = 0; i < 4; i++)
   {
      lights[i] = Light(glm::vec3(0.0), lightColors[i], glm::vec3(0.03), lightAttenuation[i]);
      lights[i].transform.setPosition(lightPositions[i]);
      lights[i].bind(arrInfo[i]);
   }
   hdrExposureProg->getUniform("numPointLights").bind(4);
   hdrExposureProg->disable();
}
Example #27
0
void mglCanvas::DefaultPlotParam()
{
/* NOTE: following variables and mutex will not be changed by DefaultPlotParam()
long InUse;			///< Smart pointer (number of users)
mglFont *fnt;		///< Class for printing vector text
int Quality;		///< Quality of plot (0x0-pure, 0x1-fast; 0x2-fine; 0x4 - low memory)
int Width;			///< Width of the image
int Height;			///< Height of the image
int Depth;			///< Depth of the image
int CurFrameId;		///< Number of automaticle created frames
GifFileType *gif;*/
	SetDrawReg(1,1,0);		Perspective(0);
	memcpy(mgl_mask_val, mgl_mask_def, 16*sizeof(uint64_t));	// should be > 16*8
	ax.Clear();	ay.Clear();	az.Clear();	ac.Clear();
	mgl_clear_fft();		DefMaskAn=0;	ResetMask();
	SetTickRotate(true);	SetTickSkip(true);
	SetWarn(mglWarnNone,"");	mglGlobalMess = "";
	ObjId = -1;	HighId = INT_MIN;
	SetFunc(0,0);	CutOff(0);	Ternary(0);
	Stop=false;	event_cb = NULL;	event_par=NULL;
	SetRanges(mglPoint(-1,-1,-1,-1), mglPoint(1,1,1,1));
	SetOrigin(NAN,NAN,NAN,NAN);
	SetBarWidth(0.7);	SetMarkSize(1);	SetArrowSize(1);
	SetAlphaDef(0.5);		FontDef[0]=0;
	SetTranspType(0);		SetMeshNum(0);	// NOTE: default MeshNum=0
	SetRotatedText(true);	CurrPal = 0;
	SetLegendMarks();		SetFontSize(4);
	SetTuneTicks(3);		SetAmbient();	SetDiffuse();
	clr(MGL_DISABLE_SCALE);
	clr(MGL_USE_GMTIME);	clr(MGL_NOSUBTICKS);
	SetDifLight(false);		SetReduceAcc(false);
	SetDefScheme(MGL_DEF_SCH);	SetPalette(MGL_DEF_PAL);
	SetPenPal("k-1");		Alpha(false);
	stack.clear();	Restore();	DefColor('k');
	SetPlotFactor(0);	InPlot(0,1,0,1,false);
	SetTickLen(0);	SetCut(true);
	AdjustTicks("xyzc",true);	Clf('w');

	for(int i=0;i<10;i++)	{	AddLight(i, mglPoint(0,0,1));	Light(i,false);	}
	Light(0,true);	Light(false);	SetDifLight(true);
}
//----------------------------------------------------------------------------
void ReflectionsAndShadows::CreatePlanarShadow ()
{
    Light* projector = new0 Light(Light::LT_POINT);
    projector->Position = APoint(30.0f, -50.0f, 80.0f);
    LightNode* projectorNode = new0 LightNode(projector);
    mScene->AttachChild(projectorNode);

    mPSEffect = new0 PlanarShadowEffect(1, mBiped);
    Float4 shadowColor(0.0f, 0.0f, 0.0f, 0.5f);
    mPSEffect->SetPlane(0, mPlane0);
    mPSEffect->SetProjector(0, projector);
    mPSEffect->SetShadowColor(0, shadowColor);
}
Example #29
0
//----------------------------------------------------------------------------
void PlanarShadows::CreatePlanarShadow ()
{
#if 1
	Light* projector = new0 Light(Light::LT_POINT);
	projector->Position = APoint(152.0f, -55.0f, 53.0f);
#else
	Light* projector = new0 Light(Light::LT_DIRECTIONAL);
	projector->DVector = AVector(0.25f, 0.25f, -1.0f);
	projector->DVector.Normalize();
#endif
	mProjectorNode = new0 LightNode(projector);
	mScene->AttachChild(mProjectorNode);

	mPSEffect = new0 PlanarShadowEffect(2, mBiped);
	Float4 shadowColor(0.0f, 0.0f, 0.0f, 0.5f);
	mPSEffect->SetPlane(0, mPlane0);
	mPSEffect->SetProjector(0, projector);
	mPSEffect->SetShadowColor(0, shadowColor);
	mPSEffect->SetPlane(1, mPlane1);
	mPSEffect->SetProjector(1, projector);
	mPSEffect->SetShadowColor(1, shadowColor);
}
Example #30
0
void RawSceneLoader::load(Scene& r , const std::string fileName)
{	

	Vector3f positions[] = {
		Vector3f(-0.5f, -0.5f,  0.5f),		    // left front
		Vector3f(-0.5f, -0.5f, -0.5f),		    // left rear
		Vector3f( 0.5f, -0.5f,  0.5f),			// right front
		Vector3f( 0.5f, -0.5f, -0.5f),		    // right rear
		Vector3f( 0.0f,  0.5f,  0.0f),			// peak
	};
	
	Vector3f colors[] = {
		Vector3f(0.0f, 0.0f, 1.0f),
		Vector3f(0.0f, 0.0f, 1.0f),
		Vector3f(0.0f, 1.0f, 0.0f),
		Vector3f(1.0f, 1.0f, 0.0f),
		Vector3f(1.0f, 0.0f, 0.0f),
	};
	
	unsigned int indices[] = {
		1, 3, 0,
		0, 3, 2,
		1, 0, 4,
		3, 1, 4,
		2, 3, 4,
		0, 2, 4
	};

	Vector3f normals[sizeof(positions) / sizeof(Vector3f)];
	CalcNormals(indices, sizeof(indices) / sizeof(unsigned int), positions,sizeof(positions) / sizeof(Vector3f), normals);

	Vector2f tex[] = {
		Vector2f(0.0f, 0.0f),
		Vector2f(1.0f, 0.0f),
		Vector2f(1.0f, 0.0f),
		Vector2f(0.0f, 0.0f),
		Vector2f(0.5f, 1.0f),
	};

	Vector3f lightColor = Vector3f(1.0f, 1.0f, 1.0f);
	float ambientLightIntensity = 0.1f;
	float diffuseLightIntensity = 0.3f;
	float specularIntensity = 1.0f;
	float specularPower = 32.0f;
	Vector3f direction = Vector3f(0.0,0.0f,1.0f);

	r.meshes.push_back(Mesh(5, positions, colors, tex, normals, 6, indices));
	r.lights.push_back(Light(lightColor,ambientLightIntensity,diffuseLightIntensity,direction));
	r.textures.push_back(Texture());	// load texture from file
	r.materials.push_back(Material(specularIntensity, specularPower));
}