void PerspectiveCamera::setCameraForSelection(int x,int y,int selectionWidth,int selectionHeight,float width,float height,float ratio)
{
	GLint viewport[4];
	glGetIntegerv(GL_VIEWPORT,viewport);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
/*
	glColor3ub(255,0,0);
	glBegin(GL_QUADS);
	glVertex2f(-1,-1);
glVertex2f(-1,1);
glVertex2f(1,1);
glVertex2f(1,-1);
	glEnd();
*/


	gluPickMatrix(x+selectionWidth*0.5f,viewport[3]-y-selectionHeight*0.5f,selectionWidth,selectionHeight,viewport);

	gluPerspective(fov(), ratio, nearPlane(), farPlane());
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(from()[0],from()[1],from()[2] ,to()[0],to()[1], to()[2],up()[0],up()[1],up()[2]);
}
Beispiel #2
0
QMatrix4x4 PerspectiveCamera::getProjMatrix(int width, int height)
{
    // can probably remove this now
    float pixdx = 0;
    float pixdy = 0;

    // taken from gluPerspective docs
    float aspect = (float)width / (float)height;
    float zNear = .1f;
    float zFar = 100.0f;

    float top = tan(fov()*3.14159/360.0) * zNear;
    //float top = tan(fov*0.5) * zNear;
    float bottom = -top;

    float left = aspect * bottom;
    float right = aspect * top;

    //int viewport[4];
    //glGetIntegerv(GL_VIEWPORT, viewport);
    float xwsize = right - left;
    float ywsize = top - bottom;

    // MAINT: width/height should be pulled from viewport if it doesn't match
    // size of render
    float dx = -(pixdx * xwsize / (float)width);
    float dy = -(pixdy * ywsize / (float)height);

    QMatrix4x4 m;
    m.frustum(left+dx, right+dx, bottom+dy, top+dy, zNear, zFar);
    //m.perspective(PerspectiveCamera->fov(), aspect, zNear, zFar);
    return m;
}
Beispiel #3
0
WHITEBOX_BEGIN

void CCamera::ComputeProjectionMatrix()
{
	Degree fov(45.0f);
	float w = 1.0f / Tan(fov * 0.5f);
	float h = (w * float(pRenderTarget->GetHeight())) / float(pRenderTarget->GetWidth());

	gVars->pRenderer->ComputeProjectionMatrix( 10.0f, 10000.0f, h, w, projectionMatrix );
}
void PerspectiveCamera::setCamera(float width,float height,float ratio)
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	//qDebug("%f,%f,",nearPlane(),farPlane());
	gluPerspective(fov(), ratio, nearPlane(), farPlane());
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(from()[0],from()[1],from()[2] ,to()[0],to()[1], to()[2],up()[0],up()[1],up()[2]);
}
PerspectiveCamera::PerspectiveCamera(void):Camera(QString("Perspective")),light(QString("Perspective Camera Light"))
{
	isShowInfo()=true;
	GGL::Point3f efrom(32,32,32);
	GGL::Point3f eto(0,0,0);
	lookAt(efrom,eto);

	light.setPosition(from());
	GGL::Point3f dir(to()-from());
	light.setDirection(dir);
	light.setSpotCutoff(fov());
}
Beispiel #6
0
Vec3 CCamera::GetNearPlaneHalfSize() const
{
	Vec3 size;

	float width = float(pRenderTarget->GetWidth());
	float height = float(pRenderTarget->GetHeight());

	Degree fov(45.0f);
	size.z = Tan(fov * 0.5f) * 10.0f;
	size.x = size.z * (width / height);
	size.y = 10.0f;

	return size;
}
void PerspectiveCamera::lookAt(GGL::Point3f &_from,GGL::Point3f &_to)
{
	from()=_from;
	to()=_to;
	GGL::Point3f zAxis(0,0,1);
	up()=(from()-to())^(zAxis^(from()-to()));

	light.setPosition(from());
	GGL::Point3f dir=to()-from();
	light.setDirection(dir);
	light.setSpotCutoff(fov());
					
	emit onCameraMotion(this);

}
void
Camera::drawGL()
{
	// set up the screen with our camera parameters
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(fov(), g_image->width() / (float)g_image->height(), 0.01, 10000);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	Vector3 vCenter = eye() + viewDir();
	gluLookAt(eye().x,   eye().y,   eye().z,
			  vCenter.x, vCenter.y, vCenter.z,
			  up().x,    up().y,    up().z);
}
void PerspectiveCamera::save(const QString &filename)
{
        FILE *fp=fopen(filename.toStdString().c_str(),"wb");

	float sfov=fov();

	float sfarPlane=farPlane();
	float snearPlane=nearPlane();

	GGL::Point3f sfrom=from();
	GGL::Point3f sto=to();
	GGL::Point3f sup=up();


	fwrite(&sfov,sizeof(float),1,fp);
	fwrite(&sfarPlane,sizeof(float),1,fp);
	fwrite(&snearPlane,sizeof(float),1,fp);

	float vsfrom[3];
	vsfrom[0]=from().X();
	vsfrom[1]=from().Y();
	vsfrom[2]=from().Z();

	fwrite(vsfrom,sizeof(float),3,fp);

	float vsto[3];
	vsto[0]=to().X();
	vsto[1]=to().Y();
	vsto[2]=to().Z();

	fwrite(vsto,sizeof(float),3,fp);

	float vsup[3];

	vsup[0]=up().X();
	vsup[1]=up().Y();
	vsup[2]=up().Z();


	fwrite(vsup,sizeof(float),3,fp);


	fclose(fp);
}
Beispiel #10
0
	void Camera::setup()
	{
			const  Point3d cameraVector = lookAt() - position();

			// Calculate length of vector perpendicular to camera vector.
			const Float d = cameraVector.length();
			const Float f = fov()*.5;
			const Float lenHorizontal = std::sin(f)*(d / std::cos(f)); 
			const Float lenVertical = lenHorizontal / aspectRatio();

			const Point3d tmpDown(math3d::make_vec(0, -1, 0));
			const Point3d perpendicularLeft = norm(cross(cameraVector, tmpDown)) * (lenHorizontal * 0.5);
			const Point3d perpendicularDown = norm(cross(perpendicularLeft, cameraVector))*(lenVertical*0.5);

			topLeft_ = lookAt() + perpendicularLeft - perpendicularDown - position();
			topRight_ = lookAt() - perpendicularLeft - perpendicularDown - position();
			bottomLeft_ = lookAt() + perpendicularLeft + perpendicularDown - position();
			bottomRight_ = lookAt() - perpendicularLeft + perpendicularDown - position();
	}
void PerspectiveCamera::onMouseWheel(float notch)
{				
	GGL::Point3f newfrom=from()+((to()-from()).Normalize())*notch;

	if((to()-newfrom)*((to()-from()).Normalize())>0.001f)
	{
		from()=newfrom;

	}
	else
	{
		from()=(from()-to()).Normalize()*0.1f+to();
	}

		light.setPosition(from());
	GGL::Point3f dir=to()-from();
	light.setDirection(dir);
	light.setSpotCutoff(fov());
	
	emit onCameraMotion(this);
}
Beispiel #12
0
bool AppPanini::Init(Renderer* pRenderer, RenderTarget* pRenderTarget, Gui* pGuiWindow, void (*pfnPaniniToggleCallback)(bool))
#endif
{
	ASSERT(pRenderer);
	ASSERT(pRenderTarget);
	ASSERT(pGuiWindow);
	ASSERT(pfnPaniniToggleCallback);

	bool bSuccess = initializeRenderingResources(pRenderer, pRenderTarget);
	if (!bSuccess)
	{
		LOGERRORF("Error initializing Panini Projection Post Process rendering resources.");
		return false;
	}

	// UI SETTINGS
	//----------------------------------------------------------------------------------------------------------------
	PaniniParameters& params                  = gPaniniSettingsDynamic.mParams;	// shorthand
	tinystl::vector<UIProperty>& dynamicProps = gPaniniSettingsDynamic.mDynamicUIControls.mDynamicProperties;	// shorthand

	UIProperty fov("Camera Horizontal FoV", params.FoVH, 30.0f, 179.0f, 1.0f);
	addProperty(pGuiWindow, &fov);
	
	UIProperty toggle("Enable Panini Projection", gPaniniSettingsDynamic.mEnablePaniniProjection);
	addProperty(pGuiWindow, &toggle);
	
	dynamicProps.push_back(UIProperty("Panini D Parameter", params.D, 0.0f, 1.0f, 0.001f));
	dynamicProps.push_back(UIProperty("Panini S Parameter", params.S, 0.0f, 1.0f, 0.001f));
	dynamicProps.push_back(UIProperty("Screen Scale"      , params.scale, 1.0f, 10.0f, 0.01f));
	
	if (gPaniniSettingsDynamic.mEnablePaniniProjection)
	{
		gPaniniSettingsDynamic.mDynamicUIControls.ShowDynamicProperties(pGuiWindow);
	}

	gPaniniSettingsDynamic.pGui = pGuiWindow;
	g_pfnPaniniToggleCallback = pfnPaniniToggleCallback;

	return bSuccess;
}
Beispiel #13
0
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
void
Camera::setHorizontalFOV(const Math::Radian& _fov)
{
    Ogre::Radian fov(_fov);
    m_camera.setFOVy(fov);
}
void PerspectiveCamera::onMouseMove(int x,int y)
{
	switch(motionType)
	{
		case Rotate:
			{
				int disx=x-oldX;
				int disy=y-oldY;

				GGL::Point3f zAxis(0,0,1);

				float angle=-0.0002f*disx;

				GGL::Matrix44f rotation;
				rotation.SetRotate(angle,zAxis);
				up()=rotation*up();
				from()=rotation*(from()-to())+to();

				GGL::Point3f roAxis=up()^(from()-to());

				angle=-0.0002f*disy;

				rotation.SetRotate(angle,roAxis);
				from()=rotation*(from()-to())+to();
				up()=rotation*up();

	light.setPosition(from());
				GGL::Point3f dir=to()-from();
	light.setDirection(dir);
	light.setSpotCutoff(fov());

				emit onCameraMotion(this);
			}
			break;
		
		case Pan:
			{
				int disx=oldX-x;
				int disy=y-oldY;

				GGL::Point3f zAxis(0,0,disy*0.002);

				GGL::Point3f horizontal=(up()^(from()-to())).Normalize();
					
				horizontal*=disx*0.002;

				from()+=horizontal;
				to()+=horizontal;

				from()+=zAxis;
				to()+=zAxis;

					light.setPosition(from());
				GGL::Point3f dir=to()-from();
	light.setDirection(dir);
	light.setSpotCutoff(fov());

				emit onCameraMotion(this);

			}
			break;
		case Zoom:
			{
				int disy=y-oldY;
				GGL::Point3f newfrom=from()+((to()-from()).Normalize())*0.01*disy;

				if((to()-newfrom)*((to()-from()).Normalize())>0.001f)
				{
					from()=newfrom;
				}
				else
				{
					from()=(from()-to()).Normalize()*0.1f+to();
				}

					light.setPosition(from());
				GGL::Point3f dir=to()-from();
	light.setDirection(dir);
	light.setSpotCutoff(fov());
								emit onCameraMotion(this);

			}
			break;
	}
}
Beispiel #15
0
// ---------------------------------------------------------------------------------------------------------------------
bool cube_tick(const FrameInput& input, FrameOutput& output, FXState& state)
{
  EffectData* data = (EffectData*)state.store;

  output.fade(3);


  Fix16 dial2((int16_t)input.dialChange[2]);
  dial2 *= fix16_from_float(1.75f);

  data->rotY += dial2;
  data->rotX -= dial2 * fix16_pt_five;
  data->delta += Fix16((int16_t)input.dialChange[1]) * fix16_from_float(0.05f);

  if (data->delta > fix16_one)
    data->delta = fix16_one;
  if (data->delta < fix16_zero)
    data->delta = fix16_zero;


  Fxp3D pj[8];

  Fix16 fov(9.0f), dist;

  dist = dist.cos(data->distPulse);
  dist *= 0.5f;
  dist += 2.2f;

  for (int i=0; i<8; i++)
  {
    pj[i] = verts[i].eulerProject(data->rotX, data->rotY, data->rotZ, fov, dist);
  }

  data->rotX += Fix16(0.6f) * data->delta;
  data->rotY += Fix16(1.7f) * data->delta;
  data->rotZ += Fix16(0.3f) * data->delta;
  data->distPulse += Fix16(0.04f) * data->delta;

  for (int f=0; f<6; f++)
  {
    int bi = (f * 4);
    draw::WuLine(output.frame,
      pj[ faces[bi + 0] ].x,
      pj[ faces[bi + 0] ].y,
      pj[ faces[bi + 1] ].x,
      pj[ faces[bi + 1] ].y,
      data->ccCycle);

    draw::WuLine(output.frame,
      pj[ faces[bi + 1] ].x,
      pj[ faces[bi + 1] ].y,
      pj[ faces[bi + 2] ].x,
      pj[ faces[bi + 2] ].y,
      data->ccCycle);

    draw::WuLine(output.frame,
      pj[ faces[bi + 2] ].x,
      pj[ faces[bi + 2] ].y,
      pj[ faces[bi + 3] ].x,
      pj[ faces[bi + 3] ].y,
      data->ccCycle);

    draw::WuLine(output.frame,
      pj[ faces[bi + 3] ].x,
      pj[ faces[bi + 3] ].y,
      pj[ faces[bi + 0] ].x,
      pj[ faces[bi + 0] ].y,
      data->ccCycle);
  }
  return true;
}
	int Renderer::preview( const std::string& fileName, const liqPreviewShaderOptions& options )
	{
		CM_TRACE_FUNC("Renderer::preview("<<fileName<<","<<options.shaderNodeName<<")");

		  std::string shaderFileName;
  liqShader currentShader;
  MObject	shaderObj;
  MString shader_type_TempForRefactoring;//  [2/14/2012 yaoyansi]

  if ( options.fullShaderPath ) 
  {
	  // a full shader path was specified
	  //cout <<"[liquid] got full path for preview !"<<endl;
	  //shaderFileName = const_cast<char*>(options.shaderNodeName);

	  std::string tmp( options.shaderNodeName );
	  currentShader.setShaderFileName(tmp.substr( 0, tmp.length() -  4 ) );

	  if ( options.type == "surface" ){
		  assert(0&&"we should use currentShader.shader_type_ex = \"surface\"");
		  //currentShader.shader_type = SHADER_TYPE_SURFACE;//  [2/14/2012 yaoyansi]
		  shader_type_TempForRefactoring = "surface";
	  }else if ( options.type == "displacement" ){
		  assert(0&&"we should use currentShader.shader_type_ex = \"displacement\"");
		  //currentShader.shader_type = SHADER_TYPE_DISPLACEMENT;//  [2/14/2012 yaoyansi]
		  shader_type_TempForRefactoring = "displacement";
	  }
	  //cout <<"[liquid]   options.shaderNodeName = " << options.shaderNodeName << endl;
	  //cout <<"[liquid]   options.type = "<<options.type<<endl;
  } 
  else 
  {
	  // a shader node was specified
	  MSelectionList shaderNameList;
	  shaderNameList.add( options.shaderNodeName.c_str() );
	  shaderNameList.getDependNode( 0, shaderObj );
	  if( shaderObj == MObject::kNullObj )
	  {
		  MGlobal::displayError( std::string( "Can't find node for " + options.shaderNodeName ).c_str() );
		  RiEnd();
		  return 0;
	  }
	  currentShader = liqShader( shaderObj );
	  shader_type_TempForRefactoring = currentShader.shader_type_ex;
	  shaderFileName = currentShader.getShaderFileName();
  }
  MFnDependencyNode assignedShader( shaderObj );


  // Get the Pathes in globals node
  MObject globalObjNode;
  MString liquidShaderPath = "",liquidTexturePath = "",liquidProceduralPath = "";
  MStatus status;
  MSelectionList globalList;
	
	// get the current project directory
  MString MELCommand = "workspace -q -rd";
  MString MELReturn;
  MGlobal::executeCommand( MELCommand, MELReturn );
  MString liquidProjectDir = MELReturn;
	
  status = globalList.add( "liquidGlobals" );
  if ( globalList.length() > 0 ) 
	{
    status.clear();
    status = globalList.getDependNode( 0, globalObjNode );
    MFnDependencyNode globalNode( globalObjNode );
		liquidGetPlugValue( globalNode, "shaderPath", liquidShaderPath, status);
    liquidGetPlugValue( globalNode, "texturePath", liquidTexturePath, status);
    liquidGetPlugValue( globalNode, "proceduralPath", liquidProceduralPath, status);
  }
  if( fileName.empty() ) 
	{
    RiBegin_liq( NULL );
#ifdef DELIGHT
    //RtPointer callBack( progressCallBack );
    //RiOption( "statistics", "progresscallback", &callBack, RI_NULL );
#endif
  } 
	else {
	liquidMessage2(messageInfo,"preview rib file: [%s]", fileName.c_str());
    RiBegin_liq( (RtToken)fileName.c_str() );
  }

  std::string liquidHomeDir = liquidSanitizeSearchPath( getEnvironment( "LIQUIDHOME" ) );
  std::string shaderPath( "&:@:.:~:" + liquidHomeDir + "/lib/shaders" );
  std::string texturePath( "&:@:.:~:" + liquidHomeDir + "/lib/textures" );
  std::string proceduralPath( "&:@:.:~:" + liquidHomeDir + "/lib/shaders" );

  std::string projectDir = std::string( liquidSanitizeSearchPath( liquidProjectDir ).asChar() );
  if ( liquidProjectDir != "")
  {
    shaderPath += ":" + projectDir;	
    texturePath += ":" + projectDir;
    proceduralPath += ":" + projectDir;
  }
  if ( liquidShaderPath != "" )
		shaderPath += ":" + std::string( liquidSanitizeSearchPath( parseString( liquidShaderPath, false ) ).asChar());	
  if ( liquidTexturePath != "" )
		texturePath += ":" + std::string( liquidSanitizeSearchPath( parseString( liquidTexturePath, false) ).asChar());	
  if ( liquidProceduralPath != "" )
		proceduralPath += ":" + std::string( liquidSanitizeSearchPath( parseString( liquidProceduralPath, false) ).asChar());	
	
  RtString list( const_cast< RtString >( shaderPath.c_str() ) );
  RiOption( "searchpath", "shader", &list, RI_NULL );
	
  RtString texPath( const_cast< RtString >( texturePath.c_str() ) );
  if( texPath[ 0 ] )
    RiOption( "searchpath","texture", &texPath, RI_NULL );
	
  RtString procPath( const_cast< RtString >( proceduralPath.c_str() ) );
  
  if( procPath[ 0 ] )
    RiOption( "searchpath","procedural", &procPath, RI_NULL );

  RiShadingRate( ( RtFloat )options.shadingRate );
  RiPixelSamples( options.pixelSamples, options.pixelSamples );

#ifdef PRMAN
  if ( MString( "PRMan" ) == liqglo.liquidRenderer.renderName )
	RiPixelFilter( RiCatmullRomFilter, 4., 4. );
#elif defined( DELIGHT )
  if ( MString( "3Delight" ) == liqglo.liquidRenderer.renderName )
    RiPixelFilter( RiSeparableCatmullRomFilter, 4., 4. );
//    RiPixelFilter( RiMitchellFilter, 4., 4.);
#else
  RiPixelFilter( RiCatmullRomFilter, 4., 4. );
#endif

  RiFormat( ( RtInt )options.displaySize, ( RtInt )options.displaySize, 1.0 );
  if( options.backPlane ) 
	{
    RiDisplay( const_cast< RtString >( options.displayName.c_str() ),
               const_cast< RtString >( options.displayDriver.c_str() ), RI_RGB, RI_NULL );
  } 
	else 
	{ // Alpha might be useful
    RiDisplay( const_cast< RtString >( options.displayName.c_str() ),
               const_cast< RtString >( options.displayDriver.c_str() ), RI_RGBA, RI_NULL );
  }
  RtFloat fov( 22.5 );
  RiProjection( "perspective", "fov", &fov, RI_NULL );
  RiTranslate( 0, 0, 2.75 );
  RiExposure(1, currentShader.m_previewGamma);
  
  RtInt visible = 1;
  RtString transmission = "transparent";

  RiAttribute( "visibility", ( RtToken ) "camera", &visible, RI_NULL );
  RiAttribute( "visibility",  ( RtToken ) "trace", &visible, RI_NULL );
  // RiAttribute( "visibility", ( RtToken ) "transmission", ( RtPointer ) &transmission, RI_NULL );
  
  RiWorldBegin();
  RiReverseOrientation();
  RiTransformBegin();
  RiRotate( -90., 1., 0., 0. );
  RiCoordinateSystem( "_environment" );
  RiTransformEnd();
  RtLightHandle ambientLightH, directionalLightH;
  RtFloat intensity;
  intensity = 0.05 * (RtFloat)options.previewIntensity;
  ambientLightH = RiLightSource( "ambientlight", "intensity", &intensity, RI_NULL );
  intensity = 0.9 * (RtFloat)options.previewIntensity;
  RtPoint from;
  RtPoint to;
  from[0] = -1.; from[1] = 1.5; from[2] = -1.;
  to[0] = 0.; to[1] = 0.; to[2] = 0.;
  RiTransformBegin();
    RiRotate( 55.,  1, 0, 0 );
    RiRotate( 30.,  0, 1, 0 );
    directionalLightH = RiLightSource( "liquiddistant", "intensity", &intensity, RI_NULL );
  RiTransformEnd();
  intensity = 0.2f * (RtFloat)options.previewIntensity;
  from[0] = 1.3f; from[1] = -1.2f; from[2] = -1.;
  RiTransformBegin();
    RiRotate( -50.,  1, 0, 0 );
    RiRotate( -40.,  0, 1, 0 );
    directionalLightH = RiLightSource( "liquiddistant", "intensity", &intensity, RI_NULL );
  RiTransformEnd();

  RiAttributeBegin();


  //ymesh omit this section, because liqShader::writeRibAttributes() do this work in that branch
  //I don't use liqShader::writeRibAttributes(), so I use this section. -yayansi
  float displacementBounds = 0.;
	liquidGetPlugValue( assignedShader, "displacementBound", displacementBounds, status);
  
  if ( displacementBounds > 0. ) 
	{
    RtString coordsys = "shader";
	RiArchiveRecord( RI_COMMENT, "ymesh omit this section, because liqShader::writeRibAttributes do this work in that branch" );
    RiAttribute( "displacementbound", "coordinatesystem", &coordsys, RI_NULL );	
    RiAttribute( "displacementbound", "sphere", &displacementBounds, "coordinatesystem", &coordsys, RI_NULL );
  }

  //LIQ_GET_SHADER_FILE_NAME( shaderFileName, options.shortShaderName, currentShader );

	// output shader space
  MString shadingSpace;
	liquidGetPlugValue( assignedShader, "shaderSpace", shadingSpace, status);
  
  if ( shadingSpace != "" ) 
	{
    RiTransformBegin();
    RiCoordSysTransform( (char*) shadingSpace.asChar() );
  }

  RiTransformBegin();
  // Rotate shader space to make the preview more interesting
  RiRotate( 60., 1., 0., 0. );
  RiRotate( 60., 0., 1., 0. );
  RtFloat scale( 1.f / ( RtFloat )options.objectScale );
  RiScale( scale, scale, scale );

  if ( shader_type_TempForRefactoring=="surface" || shader_type_TempForRefactoring=="shader"/*currentShader.shader_type == SHADER_TYPE_SURFACE || currentShader.shader_type == SHADER_TYPE_SHADER */ ) //  [2/14/2012 yaoyansi]
	{
		RiColor( currentShader.rmColor );
		RiOpacity( currentShader.rmOpacity );
		//cout << "Shader: " << shaderFileName << endl;
		if ( options.fullShaderPath ) 
				RiSurface( (RtToken)shaderFileName.c_str(), RI_NULL );
		else
		{
			liqShader liqAssignedShader( shaderObj );
			liqAssignedShader.forceAs = SHADER_TYPE_SURFACE;
			liqAssignedShader.write();
		}
  } 
	else if ( shader_type_TempForRefactoring=="displacement"/*currentShader.shader_type == SHADER_TYPE_DISPLACEMENT*/ ) //  [2/14/2012 yaoyansi]
	{
		RtToken Kd( "Kd" );
		RtFloat KdValue( 1. );
#ifdef GENERIC_RIBLIB    
    // !!! current ribLib has wrong interpretation of RiSurface parameters 
    RiSurface( "plastic", Kd, &KdValue, RI_NULL );
#else
		RiSurface( "plastic", &Kd, &KdValue, RI_NULL );
#endif    
		if ( options.fullShaderPath ) 
			RiDisplacement( (RtToken)shaderFileName.c_str(), RI_NULL );
		else 
		{
			liqShader liqAssignedShader( shaderObj );
			liqAssignedShader.forceAs = SHADER_TYPE_DISPLACEMENT;
			liqAssignedShader.write();
		}
  }
  RiTransformEnd();
  if ( shadingSpace != "" ) 
		RiTransformEnd();

 switch( options.primitiveType ) 
 {
    case CYLINDER: 
		{
      RiReverseOrientation();
      RiScale( 0.95, 0.95, 0.95 );
      RiRotate( 60., 1., 0., 0. );
      RiTranslate( 0., 0., -0.05 );
      RiCylinder( 0.5, -0.3, 0.3, 360., RI_NULL );
      RiTranslate( 0., 0., 0.3f );
      RiTorus( 0.485, 0.015, 0., 90., 360., RI_NULL );
      RiDisk( 0.015, 0.485, 360., RI_NULL );
      RiTranslate( 0., 0., -0.6 );
      RiTorus( 0.485, 0.015, 270., 360., 360., RI_NULL );
      RiReverseOrientation();
      RiDisk( -0.015, 0.485, 360., RI_NULL );
      break;
    }
    case TORUS: 
		{
      RiRotate( 45., 1., 0., 0. );
      RiTranslate( 0., 0., -0.05 );
      RiReverseOrientation();
      RiTorus( 0.3f, 0.2f, 0., 360., 360., RI_NULL );
      break;
    }
    case PLANE: 
		{
      RiScale( 0.5, 0.5, 0.5 );
      RiReverseOrientation();
      static RtPoint plane[4] = {
        { -1.,  1.,  0. },
        {  1.,  1.,  0. },
        { -1., -1.,  0. },
        {  1., -1.,  0. }
      };
      RiPatch( RI_BILINEAR, RI_P, (RtPointer) plane, RI_NULL );
      break;
    }
    case TEAPOT: 
		{
      RiTranslate( 0.06f, -0.18f, 0. );
      RiRotate( -120., 1., 0., 0. );
      RiRotate( 130., 0., 0., 1. );
      RiScale( 0.2f, 0.2f, 0.2f );
			RiArchiveRecord( RI_VERBATIM, "Geometry \"teapot\"" );
      break;
    }
    case CUBE: 
		{
      /* Lovely cube with rounded corners and edges */
      RiScale( 0.35f, 0.35f, 0.35f );
      RiRotate( 60., 1., 0., 0. );
      RiRotate( 60., 0., 0., 1. );

      RiTranslate( 0.11f, 0., -0.08f );

      RiReverseOrientation();

      static RtPoint top[ 4 ] = { { -0.95, 0.95, -1. }, { 0.95, 0.95, -1. }, { -0.95, -0.95, -1. },  { 0.95, -0.95, -1. } };
      RiPatch( RI_BILINEAR, RI_P, ( RtPointer ) top, RI_NULL );

      static RtPoint bottom[ 4 ] = { { 0.95, 0.95, 1. }, { -0.95, 0.95, 1. }, { 0.95, -0.95, 1. }, { -0.95, -0.95, 1. } };
      RiPatch( RI_BILINEAR, RI_P, ( RtPointer ) bottom, RI_NULL );

      static RtPoint right[ 4 ] = { { -0.95, -1., -0.95 }, { 0.95, -1., -0.95 }, { -0.95, -1., 0.95 }, { 0.95, -1., 0.95 } };
      RiPatch( RI_BILINEAR, RI_P, ( RtPointer ) right, RI_NULL );

      static RtPoint left[ 4 ] = { { 0.95, 1., -0.95 }, { -0.95, 1., -0.95 }, { 0.95, 1., 0.95 }, { -0.95, 1., 0.95 } };
      RiPatch( RI_BILINEAR, RI_P, ( RtPointer ) left, RI_NULL );

      static RtPoint front[ 4 ] = { {-1., 0.95, -0.95 }, { -1., -0.95, -0.95 }, { -1., 0.95, 0.95 }, { -1., -0.95, 0.95 } };
      RiPatch( RI_BILINEAR, RI_P, ( RtPointer ) front, RI_NULL );

      static RtPoint back[ 4 ] = { { 1., -0.95, -0.95 }, { 1., 0.95, -0.95 }, { 1., -0.95, 0.95 }, { 1., 0.95, 0.95 } };
      RiPatch( RI_BILINEAR, RI_P, ( RtPointer ) back, RI_NULL );

      RiTransformBegin();
      RiTranslate( 0.95, 0.95, 0. );
      RiCylinder( 0.05, -0.95, 0.95, 90., RI_NULL );
      RiTransformEnd();

      RiTransformBegin();
      RiTranslate( 0.95, -0.95, 0. );
      RiRotate( -90., 0., 0., 1. );
      RiCylinder( 0.05, -0.95, 0.95, 90., RI_NULL );
      RiTransformEnd();

      RiTransformBegin();
      RiTranslate( -0.95, 0.95, 0. );
      RiRotate( 90., 0., 0., 1. );
      RiCylinder( 0.05, -0.95, 0.95, 90., RI_NULL );
      RiTransformEnd();

      RiTransformBegin();
      RiTranslate( -0.95, -0.95, 0. );
      RiRotate( 180., 0., 0., 1. );
      RiCylinder( 0.05, -0.95, 0.95, 90., RI_NULL );
      RiTransformEnd();

      RiTransformBegin();
      RiTranslate( 0., 0., 0.95 );

      RiTransformBegin();

      RiTransformBegin();
      RiTranslate( 0.95, 0.95, 0. );
      RiSphere( 0.05, 0., 0.05, 90., RI_NULL );
      RiTransformEnd();

      RiTransformBegin();
      RiTranslate( 0.95, -0.95, 0. );
      RiRotate( -90., 0., 0., 1. );
      RiSphere( 0.05, 0., 0.05, 90., RI_NULL );
      RiTransformEnd();

      RiRotate( 180., 0., 0., 1. );

      RiTransformBegin();
      RiTranslate( 0.95, 0.95, 0. );
      RiSphere( 0.05, 0., 0.05, 90., RI_NULL );
      RiTransformEnd();

      RiTransformBegin();
      RiTranslate( 0.95, -0.95, 0. );
      RiRotate( -90., 0., 0., 1. );
      RiSphere( 0.05, 0., 0.05, 90., RI_NULL );
      RiTransformEnd();

      RiTransformEnd();

      RiRotate( 90., 1., 0., 0. );

      RiTransformBegin();
      RiTranslate( 0.95, 0., 0. );
      RiCylinder( 0.05, -0.95, 0.95, 90., RI_NULL );
      RiTransformEnd();

      RiTransformBegin();
      RiTranslate( -0.95, 0., 0. );
      RiRotate( 90., 0., 0., 1. );
      RiCylinder( 0.05, -0.95, 0.95, 90., RI_NULL );
      RiTransformEnd();

      RiRotate( 90., 0., 1., 0. );

      RiTransformBegin();
      RiTranslate( 0.95, 0.,  0. );
      RiCylinder( 0.05, -0.95, 0.95, 90., RI_NULL );
      RiTransformEnd();

      RiTransformBegin();
      RiTranslate( -0.95, 0., 0. );
      RiRotate( 90., 0., 0., 1. );
      RiCylinder( 0.05, -0.95, 0.95, 90., RI_NULL );
      RiTransformEnd();

      RiTransformEnd();

      RiTransformBegin();
      RiTranslate( 0., 0., -0.95 );

      RiTransformBegin();

      RiTransformBegin();
      RiTranslate( 0.95, 0.95, 0. );
      RiSphere( 0.05, -0.05, 0., 90., RI_NULL );
      RiTransformEnd();

      RiTransformBegin();
      RiTranslate( 0.95, -0.95, 0. );
      RiRotate( -90., 0., 0., 1. );
      RiSphere( 0.05, -0.05, 0., 90., RI_NULL );
      RiTransformEnd();

      RiRotate( 180., 0., 0., 1. );

      RiTransformBegin();
      RiTranslate( 0.95, 0.95, 0. );
      RiSphere( 0.05, -0.05, 0., 90., RI_NULL );
      RiTransformEnd();

      RiTransformBegin();
      RiTranslate( 0.95, -0.95, 0. );
      RiRotate( -90., 0., 0., 1. );
      RiSphere( 0.05, -0.05, 0., 90., RI_NULL );
      RiTransformEnd();

      RiTransformEnd();

      RiRotate( 90., 1., 0., 0. );

      RiTransformBegin();
      RiTranslate( -0.95, 0.,  0. );
      RiRotate( 180., 0., 0., 1. );
      RiCylinder( 0.05, -0.95, 0.95, 90., RI_NULL );
      RiTransformEnd();

      RiTransformBegin();
      RiTranslate( 0.95, 0.,  0. );
      RiRotate( -90., 0., 0., 1. );
      RiCylinder( 0.05, -0.95, 0.95, 90., RI_NULL );
      RiTransformEnd();

      RiRotate( 90., 0., 1., 0. );

      RiTransformBegin();
      RiTranslate( 0.95, 0.,  0. );
      RiRotate( -90., 0., 0., 1. );
      RiCylinder( 0.05, -0.95, 0.95, 90., RI_NULL );
      RiTransformEnd();

      RiTransformBegin();
      RiTranslate( -0.95, 0.,  0. );
      RiRotate( 180., 0., 0., 1. );
      RiCylinder( 0.05, -0.95, 0.95, 90., RI_NULL );
      RiTransformEnd();

      RiTransformEnd();

      break;
    }
    case CUSTOM: 
		{
      //cout <<"custom : "<<options.customRibFile<<endl;
      if ( fileExists( options.customRibFile.c_str() ) ) 
			{
        RiReadArchive( const_cast< RtToken >( options.customRibFile.c_str() ), NULL, RI_NULL );
      }
      break;
    }
    case SPHERE:
    default: 
		{
      RiRotate( 60., 1., 0., 0. );
      RiReverseOrientation();
      RiSphere( 0.5, -0.5, 0.5, 360., RI_NULL );
      break;
    }
  }

  RiAttributeEnd();
  /*
   * Backplane
   */
  if( options.backPlane ) 
	{
    if ( options.customBackplane.empty() ) 
		{
      RiAttributeBegin();
      RiScale( 0.91, 0.91, 0.91 );
      if( MString("displacement")==shader_type_TempForRefactoring/*SHADER_TYPE_DISPLACEMENT == currentShader.shader_type*/ ) //  [2/14/2012 yaoyansi]
			{
        RtColor bg = { 0.698, 0.698, 0. };
        RiColor( bg );
      } else 
        RiSurface( const_cast< RtToken >( options.backPlaneShader.c_str() ), RI_NULL );




      static RtPoint backplane[4] = {
        { -1.,  1.,  2. },
        {  1.,  1.,  2. },
        { -1., -1.,  2. },
        {  1., -1.,  2. }
      };
      RiPatch( RI_BILINEAR, RI_P, (RtPointer) backplane, RI_NULL );
      RiAttributeEnd();
    } 
		else 
		{
      if ( fileExists( options.customBackplane.c_str() ) ) 
			{
        RiAttributeBegin();
          RiScale( 1., 1., -1. );
          RiReadArchive( const_cast< RtString >( options.customBackplane.c_str() ), NULL, RI_NULL );
        RiAttributeEnd();
      }
    }
  }

  RiWorldEnd();

/* this caused maya to hang up under windoof - Alf
#ifdef _WIN32
//	Wait until the renderer is done
	while( !fileFullyAccessible( options.displayName.c_str() ) );
#endif
*/
  RiEnd();
  if(liqglo.m_logMsgFlush)
  {
	fflush( NULL );
  }
	}
Beispiel #17
0
int main() {
	//current dungeon level
	int level=1;

	srand((unsigned)time(NULL));
	init_curses();
	init_map();
	init_ents(level);
	init_items();

	//the player's coordinates
	int *y=&ent_l[0].y;
	int *x=&ent_l[0].x;

	//last key pressed
	chtype key=0;
	do {
		//move player
		if ('8'==key)//up
			move_to(y,x,-1,0);
		if ('2'==key)//down
			move_to(y,x,1,0);
		if ('4'==key)//left
			move_to(y,x,0,-1);
		if ('6'==key)//right
			move_to(y,x,0,1);
		if ('7'==key)//upper left
			move_to(y,x,-1,-1);
		if ('9'==key)//upper right
			move_to(y,x,-1,1);
		if ('1'==key)//lower left
			move_to(y,x,1,-1);
		if ('3'==key)//lower right
			move_to(y,x,1,1);
		if (('<'==key || ','==key) && NEXT_LEVEL==map[*y][*x].type) {
			if (++level>LAST_LEVEL)
				you_won();
			init_map();
			init_ents(level);
			init_items();
		}
		//move living enemies in the player's direction
		for (int e=1;e<ENTS_;e++) {
			if (ent_l[e].hp>0)
				move_enemy(&ent_l[e],&ent_l[0]);
		}

		//use unused item if the player is standing on one
		item* ci=item_m[*y][*x];
		if (NULL!=ci && !ci->used) {
			//heal hp
			if (MED_PACK==ci->type && ent_l[0].hp<PLAYER_HP) {
				ent_l[0].hp=min(ent_l[0].hp+MED_CHARGE,PLAYER_HP);
				ci->used=true;
			}
			//replenish air
			if (AIR_CAN==ci->type && ent_l[0].air<PLAYER_AIR) {
				ent_l[0].air=min(ent_l[0].air+AIR_CHARGE,PLAYER_AIR);
				ci->used=true;
			}
		}

		//mark last turn's field of view as SEEN
		for (int yy=0;yy<Y_;yy++)
			for (int xx=0;xx<X_;xx++)
				if (IN_SIGHT==view_m[yy][xx])
					view_m[yy][xx]=SEEN;
		//mark current field of view as IN_SIGHT
		fov(*y,*x, FOV_RADIUS);

		//draw map
		for (int yy=0; yy<Y_; yy++) {
			for (int xx=0; xx<X_ ;xx++) {
				chtype tile=map[yy][xx].type;
				if (IN_SIGHT==view_m[yy][xx]) {
					mvaddch(yy,xx,tile);
				} else if (SEEN==view_m[yy][xx]) {
					if (WALL==tile)
						mvaddch(yy,xx,tile);
					else
						mvaddch(yy,xx,' ');
				} else {
					mvaddch(yy,xx,' ');
				}
			}
		}
		//draw items
		for (int i=0; i<ITEMS_; i++) {
			if (!item_l[i].used && view_m[item_l[i].y][item_l[i].x]==IN_SIGHT)
				mvaddch(item_l[i].y,item_l[i].x,item_l[i].type);
		}
		//draw entities
		for (int e=0; e<ENTS_; e++) {
			if (ent_l[e].hp>0 && view_m[ent_l[e].y][ent_l[e].x]==IN_SIGHT)
				mvaddch(ent_l[e].y,ent_l[e].x,ent_l[e].type);
		}

		print_info(level);
		ent_l[0].air--;
		key=getch();
	} //exit when the player is dead or when ESC or q are pressed
	while (ent_l[0].hp>0 && ent_l[0].air>0 && ESC!=key && 'q'!=key);
	you_lost();
}