示例#1
0
int process_server_message(char *message, char *result)
{
  float px, py, pz;
  int x, y, z, deg, id;
  char buf[MESSAGE_LENGTH];

  if(message == NULL || result == NULL)
  {
    fprintf(stderr, "NULL while attempting to process server message.\n");
  }

  sscanf(message, "%s", buf);
  printf("m: %s\n", message);
  if(strcmp(buf, "done") == 0)
  {
    strcpy(result, buf);
    return 0;
  }
  if(strcmp(buf, "player") == 0)
  {
    sscanf(message, "player %f %f %f %d %d", &px, &py, &pz, &deg, &id);
    setPlayerPosition(id,px,py,pz,deg);
  }
  if(strcmp(buf, "mob") == 0)
  {
    sscanf(message, "mob %f %f %f %d %d", &px, &py, &pz, &deg, &id);
    setMobPosition(id,px,py,pz,deg);
  }
  if(strcmp(buf, "sun") == 0)
  {
    sscanf(message, "sun %f %f %f", &px, &py, &pz);
    setLightPosition(px,py,pz);
  }
  if(strcmp(buf, "dig") == 0)
  {
    sscanf(message, "dig %d %d %d", &x, &y, &z);
    world[x][y][z] = EMPTY;
    trimout();
  }
  if(strcmp(buf, "cloud") == 0)
  {
    sscanf(message, "cloud %d %d %d %d", &x, &y, &z, &id);
    world[x][y][z] = id;
  }

  return 0;
}
void ramSimpleShadow::setup()
{
	enable = true;

	// defulat light position
	setLightPosition(ofVec3f(-100.0f, 500.0f, 200.0f));
	shadow_color.set(ramColor::SHADOW);

#define _S(src) # src

	const char *vs = _S(
			uniform vec4 shadow_color;
			uniform mat4 shadow_matrix;
			uniform mat4 modelview_matrix;
			uniform mat4 modelview_matrix_inv;

			void main()
			{
				mat4 model_matrix = modelview_matrix_inv * gl_ModelViewMatrix;

				gl_FrontColor = shadow_color;
				gl_Position = gl_ProjectionMatrix * modelview_matrix * shadow_matrix * model_matrix * gl_Vertex;
			}
示例#3
0
ShaderExplodeVolumesAlpha::ShaderExplodeVolumesAlpha(bool withColorPerFace):
m_wcpf(withColorPerFace)
{
	m_nameVS = "ShaderExplodeVolumes_vs";
	m_nameFS = "ShaderExplodeVolumes_fs";
	m_nameGS = "ShaderExplodeVolumes_gs";

	std::string glxvert(*GLSLShader::DEFINES_GL);
	glxvert.append(vertexShaderText);

	std::string glxgeom;
	glxgeom.append(GLSLShader::defines_Geom("lines_witw_adjacency", "triangle_strip", 3));

	if (withColorPerFace)
		glxgeom.append("#define WITH_COLORPF 1\n");
	glxgeom.append(geometryShaderText);

	std::string glxfrag(*GLSLShader::DEFINES_GL);
	glxfrag.append(fragmentShaderText);

	loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_LINES_ADJACENCY_EXT , GL_TRIANGLE_STRIP,4);

	getLocations();

	//Default values
	m_ambient = Geom::Vec4f(0.05f, 0.05f, 0.1f, 0.0f);
	m_backColor = Geom::Vec4f(1.0f, 0.1f, 0.1f, 0.0f);
	m_light_pos = Geom::Vec3f(10.0f, 10.0f, 1000.0f);
	m_plane   = Geom::Vec4f(0.0f, 0.0f, 1000.f, 1000000000000000000000000000.0f);
	m_depthPeeling = 0;

	setAmbient(m_ambient);
	setBackColor(m_backColor);
	setLightPosition(m_light_pos);
	setClippingPlane(m_plane);
	setDepthPeeling(m_depthPeeling);
}
示例#4
0
/* -for assignment 3, mob control and digging goes here */
void update()
{
  float vx, vy, vz, mx, my, mz, rx, ry, rz;
//  sample_mob_code(); // came with the file; can be replaced
  static long int last = 0;
  static int save = 0;
  static int deg;
  static int x = 0;
  static int y = 0;
  int z = 50;
  int now;
  //char buf[MESSAGE_LENGTH];

  if(netClient && netServer) fprintf(stderr, "error: client and server at once\n");

  if(netClient == 1)
  {
    get_stuff_from_server();
    send_stuff_to_server();
  }

  if(netServer == 1)
  {
    send_stuff_to_clients();
    get_stuff_from_client();
  }

  /* check your watch */
  now = time(NULL);
  if((now - last) >= 1)
  {		
    /* restore a previously saved position */
    world[x][y][z] = save;

    /* calculate position of the light */
    x = (WORLDX/2.0)-1+(WORLDX/2.0)*cos(deg*PI/180.0);
    y = (WORLDY/2.0)-1+(WORLDY/2.0)*sin(deg*PI/180.0);

    /* save the state of the cube the light will fill */
    save = world[x][y][z];

    /* place the light and the white cube */
    world[x][y][z] = WHITE;
    /*printf("x, y: %d, %d\n", x, y);*/
    setLightPosition(x,y-1,z);
    sun_flag = 1;
    /* using this as a timestep for the light and clouds */
    deg++;
    if(deg > 180) deg = 0;

    /* Every few timesteps, update the clouds */
    if((int)deg % 3 == 0)
    {
      perlin_clouds(90, 8, deg);
      clouds_flag = 1;
      mob_action();
    }
    /* save the time for FPS control */
    last = now;
  }


  /* sample use of the dig flag, it is set equal to 1 when the user */
  /*  presses the space bar, you need to reset it to 0 */
  if (dig == 1)
  {
    digflag[0] = 1;
    getViewOrientation(&mx,&my,&mz);
    getViewPosition(&vx,&vy,&vz);

    vx *= -1;
    vy *= -1;
    vz *= -1;

    while(mx >= 360) mx -= 360;
    while(my >= 360) my -= 360;
    while(mz >= 360) mz -= 360;
    printf("dig: mx, my, mz: %f, %f, %f\t", mx, my, mz);
    printf("pos: vx, vy, vz: %f, %f, %f\t", vx, vy, vz);
    rx = vx+sin(my)*cos(mx);//vx+sin(my)*cos(mx) * 1;
    rz = vz+(-1 * cos(my))*cos(mx);//vz+cos(my)*cos(mx) * 1;
    ry = vy-sin(mx);//(vy+sin(mx) * 1);
    printf("got: rx, ry, rz: %f, %f, %f\t", rx, ry, rz);
    world[(int)round(rx)][(int)round(ry)][(int)round(rz)] = EMPTY;
    trimout();
//    buildDisplayList();
    digflag[1] = -1*(int)round(rx);
    digflag[2] = -1*(int)round(ry);
    digflag[3] = -1*(int)round(rz);
    printf("dug: rx, ry, rz: %d, %d, %d\n", -1*(int)round(rx), -1*(int)round(ry), -1*(int)round(rz));

    dig = 0;
  }

  if(flycontrol == 0)
  {
    getViewPosition(&vx,&vy,&vz);
    vx *= -1;
    vy *= -1;
    vz *= -1;
    if(world[(int)vx][(int)(vy-1.6)][(int)vz] == 0)
    {
      vy -= 0.35;
      vx *= -1;
      vy *= -1;
      vz *= -1;
      setViewPosition(vx,vy,vz);
    }
  }

  /* your code goes here */
}
static void
cubemodelPaintInside (CompScreen              *s,
                      const ScreenPaintAttrib *sAttrib,
                      const CompTransform     *transform,
                      CompOutput              *output,
                      int                     size)
{
    int                i;
    static const float matShininess[] = { 60.0 };
    static const float matSpecular[] = { 0.6, 0.6, 0.6, 1.0 };
    static const float matDiffuse[] = { 1.0, 1.0, 1.0, 1.0 };
    static const float matAmbient[] = { 0.8, 0.8, 0.9, 1.0 };

    static const float lmodelLocalviewer[] = { 0.0 };
    static       float lmodelTwoside[] = { 0.0 };
    static       float lmodelAmbient[] = { 0.4, 0.4, 0.4, 0.4 };
    static       float lmodelDiffuse[] = { 1.0, 1.0, 1.0, 1.0 };
    static       float lmodelSpecular[]= { 0.6, 0.6, 0.6, 0.6 };

    ScreenPaintAttrib  sA = *sAttrib;
    CompTransform      mT = *transform;
    Bool               enabledCull;
    int                cull;
    float              scale, outputRatio = 1.0f;

    CUBEMODEL_SCREEN (s);
    CUBE_SCREEN (s);

    if (cms->hsize != s->hsize * cs->nOutput)
    {
	initWorldVariables (s);
	updateModel (s, 0, cms->numModels);
    }

    sA.yRotate += cs->invert * (360.0f / size) *
		  (cs->xRotations - (s->x* cs->nOutput));

    (*s->applyScreenTransform) (s, &sA, output, &mT);

    glPushMatrix ();

    if (cubemodelGetRotateLighting (s))
	setLightPosition (s, GL_LIGHT1);

    glLoadMatrixf (mT.m);

    if (!cubemodelGetRotateLighting (s))
	setLightPosition (s, GL_LIGHT1);


    glTranslatef (cs->outputXOffset, -cs->outputYOffset, 0.0f);
    glScalef (cs->outputXScale, cs->outputYScale, 1.0f);

    glPushAttrib (GL_COLOR_BUFFER_BIT | GL_TEXTURE_BIT |
		  GL_LIGHTING_BIT     | GL_DEPTH_BUFFER_BIT);

    glEnable (GL_BLEND);
    glColorMaterial (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

    lmodelAmbient[0]  = cubemodelGetLightAmbient (s);
    lmodelDiffuse[0]  = cubemodelGetLightDiffuse (s);
    lmodelSpecular[0] = cubemodelGetLightSpecular (s);

    for (i = 1; i < 4; i++)
    {
	lmodelAmbient[i]  = lmodelAmbient[0];
	lmodelDiffuse[i]  = lmodelDiffuse[0];
	lmodelSpecular[i] = lmodelSpecular[0];
    }

    lmodelTwoside[0] = (cubemodelGetRenderFrontAndBack (s) ? 1.0f : 0.0f);


    glLightModelfv (GL_LIGHT_MODEL_LOCAL_VIEWER, lmodelLocalviewer);
    glLightModelfv (GL_LIGHT_MODEL_TWO_SIDE, lmodelTwoside);
    glLightModelfv (GL_LIGHT_MODEL_AMBIENT,  lmodelAmbient);
    glLightfv (GL_LIGHT1, GL_DIFFUSE,   lmodelDiffuse);
    glLightfv (GL_LIGHT1, GL_SPECULAR,  lmodelSpecular);

    enabledCull = glIsEnabled (GL_CULL_FACE);

    glGetIntegerv (GL_CULL_FACE_MODE, &cull);
    glEnable (GL_CULL_FACE);

    glCullFace (~cull & (GL_FRONT | GL_BACK));
    glCullFace (cull);

    glPushMatrix ();

    glColor4usv (defaultColor);

    glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, matShininess);
    glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, matSpecular);
    glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, matDiffuse);
    glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, matAmbient);

    glEnable (GL_NORMALIZE);
    glEnable (GL_DEPTH_TEST);
    glEnable (GL_COLOR_MATERIAL);
    glEnable (GL_LIGHTING);
    glEnable (GL_LIGHT1);
    glDisable (GL_LIGHT0);

    glDepthFunc (GL_LEQUAL); /* for transparency maps */
    glShadeModel(GL_SMOOTH);

    glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    scale = cs->distance;

    if (cubemodelGetRescaleWidth (s))
    {
	if (cs->moMode == CUBE_MOMODE_AUTO && cs->nOutput < s->nOutputDev)
	    outputRatio = (float) s->width / (float) s->height;
	else
	    outputRatio = (float) output->width / (float) output->height;
    }

    glScalef (scale / outputRatio, scale, scale / outputRatio);

    glPushMatrix ();

    glColor4f (1.0, 1.0, 1.0, 1.0);

    for (i = 0; i < cms->numModels; i++)
    {
	glPushMatrix ();
	cubemodelDrawModelObject (s, cms->models[i],
	                          cubemodelGetGlobalModelScaleFactor (s));
	glPopMatrix ();

    }
    glPopMatrix ();

    glPopMatrix ();

    glDisable (GL_LIGHT1);
    glDisable (GL_NORMALIZE);

    if (!s->lighting)
	glDisable (GL_LIGHTING);

    glDisable (GL_DEPTH_TEST);

    if (enabledCull)
	glDisable (GL_CULL_FACE);

    glPopMatrix ();

    glPopAttrib ();

    cms->damage = TRUE;

    UNWRAP (cms, cs, paintInside);
    (*cs->paintInside) (s, sAttrib, transform, output, size);
    WRAP (cms, cs, paintInside, cubemodelPaintInside);
}
示例#6
0
void Light::applyLightPosition(GLenum property,int type)
{
    setLightPosition(type);//0 For Directional, 1 For Positional 
    glLightfv(property, GL_POSITION, this->lightPos);
    
}
void BasicProgram::setActualProgram(){
	program->linkProgramHandler();
	//Si se linkea el program handler se pierde la uniform as� que hay que pasarla aca
	setLightPosition();
}