Example #1
0
////////////////////////////////////////////////////////////////////////////////
// constructor & desctructor
////////////////////////////////////////////////////////////////////////////////
IntelCamera::IntelCamera(int device_num)
: sps(2), images(2)
{
	printf("start Soft Kinetic Camera... device #%d ",device_num);

	// create color image buffer
	color_image = cvCreateImage(cvSize(COLOR_WIDTH,COLOR_HEIGHT), IPL_DEPTH_8U , 3);
	depth_image = cvCreateImage(cvSize(DEPTH_WIDTH,DEPTH_HEIGHT), IPL_DEPTH_16U, 1);
	confi_image = cvCreateImage(cvSize(DEPTH_WIDTH,DEPTH_HEIGHT), IPL_DEPTH_16U, 1);

	// create buffer for projection & fill constant 2d coordinate at first
	pos2d = new PXCPoint3DF32[DEPTH_WIDTH*DEPTH_HEIGHT];
	for(int j=0;j<DEPTH_HEIGHT;j++)
	for(int i=0;i<DEPTH_WIDTH ;i++){
		pos2d[i+j*DEPTH_WIDTH].x = (pxcF32)i;
		pos2d[i+j*DEPTH_WIDTH].y = (pxcF32)j;
	}
	posc  = new PXCPointF32    [DEPTH_WIDTH*DEPTH_HEIGHT];
	pos3d = new PXCPoint3DF32  [DEPTH_WIDTH*DEPTH_HEIGHT];

	// initialize camera
	if(InitCamera(device_num)==-1){
		fprintf(stderr,"Failed to initialize Intel Camera device.\n");
		exit(1);
	}

	printf("working now!\n");
}
Example #2
0
/*************
 * DESCRIPTION:   Calculate ray direction
 * INPUT:         x     x position
 *                y     y position
 *                ray   ray structure
 *                world world structure
 *                time  actual time
 * OUTPUT:        none
 *************/
void CAMERA::CalcRay(float x, float y, RAY *ray, WORLD *world, const float time)
{
	// update camera
	if((posactor || viewactor) && this->time != time)
	{
		Update(time);
		InitCamera();
	}

	// Set startpoint to eye-point
	ray->start = pos;

	// Calculate ray direction.
	ray->dir.x = firstray.x + x*scrnx.x + y*scrny.x;
	ray->dir.y = firstray.y + x*scrnx.y + y*scrny.y;
	ray->dir.z = firstray.z + x*scrnx.z + y*scrny.z;

	VecNormalizeNoRet(&ray->dir);

	if(fabs(ray->dir.x) < EPSILON)
		ray->dir.x = 0.f;
	if(fabs(ray->dir.y) < EPSILON)
		ray->dir.y = 0.f;
	if(fabs(ray->dir.z) < EPSILON)
		ray->dir.z = 0.f;

	// do only depth of field if aperture > 0, supersampling on and fastDOF off
	if((aperture > 0.f) && (world->samples > 1) && !(flags & FASTDOF))
		this->FocusBlurRay(ray, world);

	ray->ray_length = 0.f;
}
Example #3
0
void list_devices( CAMCameraListPtr pList)
{
    uint32_t         ctr;
    char *           pName;
    CAMHandle        hCam;
    CAMUsbInfo *     ptr;
    CAMDeviceInfoPtr pInfo;

    printf( "\n Device list\n ===========\n");
    printf( " Bus  Device  VendorID  ProductID  Camera\n");

    for (ctr=0, ptr=pList->Cameras; ctr < pList->cntCameras; ctr++, ptr++) {

        hCam = 0;
        pInfo = 0;

        if (InitCamera( ptr->Device, &hCam))
            pName = "could not open device";
        else
        if (GetDeviceInfo( hCam, &pInfo))
            pName = "could not get device info";
        else
            pName = pInfo->Model;

        printf( " %2s     % d     0x%04X    0x%04X    %s\n",
                ptr->BusName, ptr->DeviceNbr, ptr->VendorId,
                ptr->ProductId, pName);

        free( pInfo);
        TermCamera( &hCam);
    }

    return;
}
Example #4
0
//////////////////////////////////////////////////////////////////////////////////
// OpenCamera --------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////////////
BOOL ofxUeye::OpenCamera(int id){
	int nRet;

    m_hCam = (HCAM)id; 
    nRet = InitCamera (&m_hCam, m_hwndDisp);    // init camera
    if( nRet == IS_SUCCESS )
    {
        is_GetCameraInfo( m_hCam, &m_ci);

        // retrieve original image size
        is_GetSensorInfo( m_hCam, &m_si);

        GetMaxImageSize(&m_nSizeX, &m_nSizeY);

        // setup the bitmap or directdraw display mode
        nRet = InitDisplayMode();

        if(nRet == IS_SUCCESS)
        {
            // Enable Messages
            nRet = is_EnableMessage( m_hCam, IS_DEVICE_REMOVED, m_hwndDisp );
            nRet = is_EnableMessage( m_hCam, IS_DEVICE_RECONNECTED, m_hwndDisp );
            nRet = is_EnableMessage( m_hCam, IS_FRAME, m_hwndDisp );
        }   // end if( nRet == IS_SUCCESS )
    }   // end if( nRet == IS_SUCCESS )

    return (nRet == IS_SUCCESS);
}
Example #5
0
/*Camera control initial*/
int CameraCtrlInit(int com)
{
	int ret = -1;
	int fd;
	int baudrate = 9600, databits = 8;
	int stopbits = 1, parity = 'N';

	baudrate = gRemote.comm.baud;
	databits = gRemote.comm.databits;
	parity = gRemote.comm.parity;
	stopbits = gRemote.comm.stopbits;

	fd = InitPort(com, baudrate, databits, stopbits, parity);

	if(fd <= 0) {
		return -1;
	}

	ret = InitCamera(fd);

	if(ret != 0) {
		return -1;
	}

	return fd;
}
Example #6
0
    /*
    ==============================
    ==============================
    */
    void IKAModule::Start()
    {
        xml_document<>* doc = new xml_document<>;

        xml_load(doc, defaultFile);

        InitLimb();
        InitCamera();
    }
Example #7
0
int init_resources(void) {

	InitProgram();
	InitCamera();
	InitWriter();

	InitWell();

	return 1;
}
void CreateScene (NewtonWorld* world, SceneManager* sceneManager)
{
	Entity* floor;
	NewtonBody* floorBody;
	NewtonCollision* shape;

	// initialize the camera
	InitCamera (dVector (-15.0f, 5.0f, 0.0f, 0.0f), dVector (1.0f, 0.0f, 0.0f));

	// Create a large body to be the floor
	floor = sceneManager->CreateEntity();
	floor->LoadMesh ("FloorBox.dat");

	// add static floor Physics
	shape = CreateNewtonBox (world, floor, 0);
	floorBody = CreateRigidBody (world, floor, shape, 0.0f);
	NewtonDestroyCollision(shape);

	// set the Transformation Matrix for this rigid body
	dMatrix matrix (floor->m_curRotation, floor->m_curPosition);
	NewtonBodySetMatrix (floorBody, &matrix[0][0]);


	// find the floor base, and add some distance up;
	dFloat floorY = FindFloor (world, 0.0f, 0.0f) + 2.0f;

	// this is the width of the Box;
	dFloat boxWidth = 0.42f;

	// Make a small pyramid of Boxes
	for (int i = 0; i < PYRAMID_BASE + 1; i ++) {
		for (int j = 0; j < PYRAMID_BASE - i; j ++) {
			Entity* smilly;
			NewtonBody* smillyBody;

			// crate a visual Box and place in a pyramid formation above the floor
			smilly = sceneManager->CreateEntity();
			smilly->LoadMesh ("Smilly.dat");
			smilly->m_curPosition.m_x = 0.0f;
			smilly->m_curPosition.m_z = dFloat (j) * boxWidth + dFloat (i) * (boxWidth * 0.5f);
			smilly->m_curPosition.m_y = floorY + dFloat (i) * boxWidth;
			smilly->m_prevPosition = smilly->m_curPosition;

			// add a body with a box shape
			shape = CreateNewtonBox (world, smilly, 0);
			smillyBody = CreateRigidBody (world, smilly, shape, 10.0f);
			NewtonDestroyCollision(shape);

			// we want some nice object placement, with zero penetration and and zero jitter
			// therefore we are going use use a Convex Cast function to snap the Box to the closest contact surface
			ConvexCastPlacement (smillyBody);
		}
	}
}
Example #9
0
HV_Camera::HV_Camera()
{	 
	 DeviceId          = 1;
	 Resolution          = RES_MODE1;
	 SnapMode            = CONTINUATION;
	 ConvertType = BAYER2RGB_NEIGHBOUR1;

	 Gain               = 10;
	 ExposureTint_Upper = 60;
	 ExposureTint_Lower = 1000;
	 ShutterDelay       = 0;
	 ADCLevel           = ADC_LEVEL2;
	 XStart              = 0;
	 YStart              = 0;
	 Width               = 640;
	 Height              = 512;
	 lVBlanking         = 0;
	 SnapSpeed = HIGH_SPEED;
	 ObjNum++;

	for(int i=0;i<256;i++)
	{
		m_pLutR[i] = i;
		m_pLutG[i] = i;
		m_pLutB[i] = i;
	}

	// 消隐默认值
	m_lHBlanking = 0;
	m_lVBlanking = 0;


	//只考虑1个2个相机的情况 0个相机将输出错误 多余两个将都输出第一个相机
	if(CameraCount()==2)
	{
		if( ObjNum==1)
		{
			 DeviceId =1;
		}
		else if(ObjNum==2)
		{
			DeviceId =2;
		}
		
	}
	


	InitCamera();

}
Example #10
0
/*摄像头的控制*/
int CameraControl()
{
	int ret = -1;
	int fd;
	int baudrate = 9600, databits = 8;
	int stopbits = 1, parity = 'N';

	baudrate = gRemote.comm.baud;
	databits = gRemote.comm.databits;
	parity = gRemote.comm.parity;
	stopbits = gRemote.comm.stopbits;


	Printf("Initial succeed\n");
	fd = InitPort(PORT_COM2, baudrate, databits, stopbits, parity);
	ret = InitCamera(fd);

	if(ret != 0) {
		return -1;
	}

	/*	sleep(1);
		CCtrlUpStart(fd,1,10);
		sleep(10);
		CCtrlUpStop(fd,1);
		usleep(100);

		CCtrlDownStart(fd,1,10);
		sleep(10);
		CCtrlDownStop(fd,1);
		usleep(100);
	*/
	CCtrlLeftStart(fd, 1, 10);
	sleep(10);
	CCtrlLeftStop(fd, 1);
	/*	usleep(100);
		CCtrlRightStart(fd,1,10);
		sleep(20);
		CCtrlRightStop(fd,1);
		usleep(100);
		CCtrlZoomAddStart(fd,1);
		sleep(10);
		CCtrlZoomAddStop(fd,1);
		usleep(100);
		CCtrlZoomDecStart(fd,1);
		sleep(20);
		CCtrlZoomDecStop(fd,1);
		usleep(100);*/
	return 0;
}
Example #11
0
int  CamReadThread::SetCamera_StartThread(string url)
{
	int iRet = -1;
	m_videoStream = url;
	iRet = InitCamera();
	if(iRet < 0)	return	iRet;

	iRet = CreateCamReadThread();
	if(iRet < 0)
	{	
		return -1;
	}
	
	resume();
	return 0;
}
Example #12
0
// Default Ctor
ShipRace::ShipRace()
	: mBaseCamPos(0, 0, 0)
	, mGameStarted(false)
	, mGameOver(false)
	, mScreenCamPos(0, 0, -1000)
	, screenPosition(500)
{
	// Load the needed assets
	LoadAssets();
	
	// Initialize the camera of the game
	InitCamera();
	
	// Setup of a "StartScreen"
	title = new Sprite(Texture::ID::TITLE);
	title->SetPosition(-screenPosition, screenPosition);
	title->SetRotationDeg(0, 180.f, 0);
}
Example #13
0
void EditDialog::InitLayout(wxGLContext* glctx, const ee::SprPtr& edited, const ee::MultiSpritesImpl* sprite_impl)
{
	wxSplitterWindow* right_splitter = new wxSplitterWindow(this);
	wxSplitterWindow* left_splitter = new wxSplitterWindow(right_splitter);

	LibraryPanel* library = new LibraryPanel(left_splitter);
	StagePanel* stage = new StagePanel(left_splitter, this, glctx, edited, sprite_impl, library);
	m_stage = stage;

	InitCamera(edited);

	left_splitter->SetSashGravity(0.15f);
	left_splitter->SplitVertically(library, stage);

	ToolbarPanel* toolbar = new ToolbarPanel(right_splitter, stage);

	right_splitter->SetSashGravity(0.85f);
	right_splitter->SplitVertically(left_splitter, toolbar);
}
Example #14
0
//////////////////////////////////////////////////////////////////////////
// Main initialization call
//////////////////////////////////////////////////////////////////////////
void Initialize(int argc, char** argv) {

	InitCamera();

	// Initialize GL
	InitGL(argc, argv);

	scene = new HScene();
	scene->LoadSceneFile();
	renderer = new HRenderer(camera);
	renderer->InitScene(scene);

	// OpenGL callback registration
	glfwSetWindowSizeCallback(window, Resize);
	glfwSetKeyCallback(window, Keyboard);
	glfwSetMouseButtonCallback(window, Mouse);
	glfwSetCursorPosCallback(window, Motion);
	glfwSetScrollCallback(window, Scroll);
}
Example #15
0
bool OBJLoaderApp::StartUp()
{

	if (!glfwInit())
	{
		return false;
	}

	mWindow = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE, nullptr, nullptr);

	if (nullptr == mWindow)
	{
		glfwTerminate();
		return false;
	}

	glfwMakeContextCurrent(mWindow);

	if (ogl_LoadFunctions() == ogl_LOAD_FAILED)
	{
		glfwDestroyWindow(mWindow);
		glfwTerminate();
		return false;
	}

	//load model file
	LoadGeometry(OBJ_MODEL_FILE_PATH);
	//LoadGeometry(FBX_MODEL_FILE_PATH);

	InitCamera();

	// create shaders
	const char* vsSource = "#version 330\n \
							layout(location=0) in vec4 Position; \
							layout(location=1) in vec4 Colour; \
							out vec4 vColour; \
							uniform mat4 ProjectionView; \
							void main() \
							{ \
								vColour = Colour; \
								gl_Position = ProjectionView * Position;\
							}";
HRESULT SWLPRVenusCameraParameter::Initialize(CSWString strFilePath)
{
	// 初始化前重新设置默认值
	ResetParam();
	
    // 先基类的初始化
    if (S_OK == CSWParameter<ModuleParams>::Initialize(strFilePath)
        && S_OK == InitSystem()
        && S_OK == InitCamera()
        && S_OK == InitHvDsp()
        && S_OK == InitCharacter()
        && S_OK == InitGB28181()
		&& S_OK == InitONVIF())
    {
        return S_OK ;
    }

    SW_TRACE_DEBUG("<SWLPRVenusCameraParameter> Initialize failed.\n");
    return E_FAIL ;
}
Example #17
0
int main(int argc, char **argv)
{ 
	srand( (unsigned)time( NULL ) );
	
	InitGLUT(argc, argv, "Shooter", 500, 500) ;
	InitDisplay(true, true, false) ; 
	InitCamera(10) ;
	InitMouse() ;

	glutDisplayFunc(DisplayHandler) ;
 	glutKeyboardFunc(KeyboardHandler) ;
	glutMouseFunc(MouseButtonHandler) ;
	glutMotionFunc(MotionHandler) ;

	InitOptions() ;

 	glutMainLoop() ;
 
	return 0 ;
}
Example #18
0
    SceneEditorApp::SceneEditorApp() {

        if (App::App() == false) {
            return false;
        }

        if (InitCamera() == false || InitPointLight() == false ||
            InitSpecialPoint() == false) {
            return false;
        }

        SetProcessors();
        SetCameraProcessors();
        SetDragDropProcessors();
        GetDebugRenderer().SetTexCoordsScale(0.5);
        timer.Reset(true);

        //    moveablePoint.SetSize(100);
        return true;
        // GetGeometryManager().CreateSceneObjectFromTemplate("Object1",SceneObjectParams());
    }
Example #19
0
/**\brief (de-)activate 1394b support in a compliant camera
 * \param on Whether to turn 1394b support on (TRUE) or off (FALSE)
 * \return
 *  - CAM_ERROR_BUSY if in the middle of image acquisition
 *  - CAM_ERROR_UNSUPPORTED if the camera does not support 1394b
 *  - Other errors: Bad things happened in Register I/O
 *
 * After successfully changing 1394b support, we must re-read all the
 * format, mode, rate, etc registers
 */
int C1394Camera::Set1394b(BOOL on)
{
	int ret;
	if(this->m_hDeviceAcquisition != INVALID_HANDLE_VALUE)
		return CAM_ERROR_BUSY;
	
	if(Has1394b())
	{
		unsigned long ulData;
		if((ret = ReadQuadlet(0x60c, &ulData)) != CAM_SUCCESS)
			return ret;
		if(on)
			ulData |= 0x00008000;
		else
			ulData &= ~0x00008000;
		if((ret = WriteQuadlet(0x60c, ulData)) != CAM_SUCCESS)
			return ret;
		// by changing this setting, other random stuff may change as well
		return InitCamera();
	}
	return CAM_ERROR_UNSUPPORTED;
}
Example #20
0
int main(int argc, char **argv)
{
	InitGLUTWindow(argc, argv, "Scene", 400, 400) ;
	InitDisplay(true, true, true) ; // initialize variables and display modes
	InitMouse () ;
	InitCamera() ;
	glEnable(GL_AUTO_NORMAL) ;
	glEnable(GL_NORMALIZE) ;

	InitVars() ;
	ToggleLighting(true) ;

	glutDisplayFunc(DisplayHandler) ;

 	glutKeyboardFunc(KeyboardHandler) ;
	glutSpecialFunc(SpecialKeyHandler) ;

	glutTimerFunc(20, UpdatePosition, 0);

 	glutMainLoop() ;

	return 0 ;
 }
Example #21
0
void PathOCLRenderThread::InitRender() {
	Scene *scene = renderEngine->renderConfig->scene;

	cl::Context &oclContext = intersectionDevice->GetOpenCLContext();
	cl::Device &oclDevice = intersectionDevice->GetOpenCLDevice();
	const OpenCLDeviceDescription *deviceDesc = intersectionDevice->GetDeviceDesc();

	double tStart, tEnd;

	//--------------------------------------------------------------------------
	// FrameBuffer definition
	//--------------------------------------------------------------------------

	InitFrameBuffer();

	//--------------------------------------------------------------------------
	// Camera definition
	//--------------------------------------------------------------------------

	InitCamera();

	//--------------------------------------------------------------------------
	// Scene geometry
	//--------------------------------------------------------------------------

	InitGeometry();

	//--------------------------------------------------------------------------
	// Translate material definitions
	//--------------------------------------------------------------------------

	InitMaterials();

	//--------------------------------------------------------------------------
	// Translate area lights
	//--------------------------------------------------------------------------

	InitAreaLights();

	//--------------------------------------------------------------------------
	// Check if there is an infinite light source
	//--------------------------------------------------------------------------

	InitInfiniteLight();

	//--------------------------------------------------------------------------
	// Check if there is an sun light source
	//--------------------------------------------------------------------------

	InitSunLight();

	//--------------------------------------------------------------------------
	// Check if there is an sky light source
	//--------------------------------------------------------------------------

	InitSkyLight();

	const unsigned int areaLightCount = renderEngine->compiledScene->areaLights.size();
	if (!skyLightBuff && !sunLightBuff && !infiniteLightBuff && (areaLightCount == 0))
		throw runtime_error("There are no light sources supported by PathOCL in the scene");

	//--------------------------------------------------------------------------
	// Translate mesh texture maps
	//--------------------------------------------------------------------------

	InitTextureMaps();

	//--------------------------------------------------------------------------
	// Allocate Ray/RayHit buffers
	//--------------------------------------------------------------------------

	const unsigned int taskCount = renderEngine->taskCount;

	tStart = WallClockTime();

	LM_LOG_ENGINE("[PathOCLRenderThread::" << threadIndex << "] Ray buffer size: " << (sizeof(Ray) * taskCount / 1024) << "Kbytes");
	raysBuff = new cl::Buffer(oclContext,
			CL_MEM_READ_WRITE,
			sizeof(Ray) * taskCount);
	deviceDesc->AllocMemory(raysBuff->getInfo<CL_MEM_SIZE>());

	LM_LOG_ENGINE("[PathOCLRenderThread::" << threadIndex << "] RayHit buffer size: " << (sizeof(RayHit) * taskCount / 1024) << "Kbytes");
	hitsBuff = new cl::Buffer(oclContext,
			CL_MEM_READ_WRITE,
			sizeof(RayHit) * taskCount);
	deviceDesc->AllocMemory(hitsBuff->getInfo<CL_MEM_SIZE>());

	tEnd = WallClockTime();
	LM_LOG_ENGINE("[PathOCLRenderThread::" << threadIndex << "] OpenCL buffer creation time: " << int((tEnd - tStart) * 1000.0) << "ms");

	//--------------------------------------------------------------------------
	// Allocate GPU task buffers
	//--------------------------------------------------------------------------

	// TODO: clenup all this mess

	const size_t gpuTaksSizePart1 =
		// Seed size
		sizeof(PathOCL::Seed);

	const size_t uDataEyePathVertexSize =
		// IDX_SCREEN_X, IDX_SCREEN_Y
		sizeof(float) * 2 +
		// IDX_DOF_X, IDX_DOF_Y
		((scene->camera->lensRadius > 0.f) ? (sizeof(float) * 2) : 0);
	const size_t uDataPerPathVertexSize =
		// IDX_TEX_ALPHA,
		((texMapAlphaBuff) ? sizeof(float) : 0) +
		// IDX_BSDF_X, IDX_BSDF_Y, IDX_BSDF_Z
		sizeof(float) * 3 +
		// IDX_DIRECTLIGHT_X, IDX_DIRECTLIGHT_Y, IDX_DIRECTLIGHT_Z
		(((areaLightCount > 0) || sunLightBuff) ? (sizeof(float) * 3) : 0) +
		// IDX_RR
		sizeof(float);
	const size_t uDataSize = (renderEngine->sampler->type == PathOCL::INLINED_RANDOM) ?
		// Only IDX_SCREEN_X, IDX_SCREEN_Y
		(sizeof(float) * 2) :
		((renderEngine->sampler->type == PathOCL::METROPOLIS) ?
			(sizeof(float) * 2 + sizeof(unsigned int) * 5 + sizeof(Spectrum) + 2 * (uDataEyePathVertexSize + uDataPerPathVertexSize * renderEngine->maxPathDepth)) :
			(uDataEyePathVertexSize + uDataPerPathVertexSize * renderEngine->maxPathDepth));

	size_t sampleSize =
		// uint pixelIndex;
		((renderEngine->sampler->type == PathOCL::METROPOLIS) ? 0 : sizeof(unsigned int)) +
		uDataSize +
		// Spectrum radiance;
		sizeof(Spectrum);

	stratifiedDataSize = 0;
	if (renderEngine->sampler->type == PathOCL::STRATIFIED) {
		PathOCL::StratifiedSampler *s = (PathOCL::StratifiedSampler *)renderEngine->sampler;
		stratifiedDataSize =
				// stratifiedScreen2D
				sizeof(float) * s->xSamples * s->ySamples * 2 +
				// stratifiedDof2D
				((scene->camera->lensRadius > 0.f) ? (sizeof(float) * s->xSamples * s->ySamples * 2) : 0) +
				// stratifiedAlpha1D
				((texMapAlphaBuff) ? (sizeof(float) * s->xSamples) : 0) +
				// stratifiedBSDF2D
				sizeof(float) * s->xSamples * s->ySamples * 2 +
				// stratifiedBSDF1D
				sizeof(float) * s->xSamples +
				// stratifiedLight2D
				// stratifiedLight1D
				(((areaLightCount > 0) || sunLightBuff) ? (sizeof(float) * s->xSamples * s->ySamples * 2 + sizeof(float) * s->xSamples) : 0);

		sampleSize += stratifiedDataSize;
	}

	const size_t gpuTaksSizePart2 = sampleSize;

	const size_t gpuTaksSizePart3 =
		// PathState size
		((((areaLightCount > 0) || sunLightBuff) ? sizeof(PathOCL::PathStateDL) : sizeof(PathOCL::PathState)) +
			//unsigned int diffuseVertexCount;
			((renderEngine->maxDiffusePathVertexCount < renderEngine->maxPathDepth) ? sizeof(unsigned int) : 0));

	const size_t gpuTaksSize = gpuTaksSizePart1 + gpuTaksSizePart2 + gpuTaksSizePart3;
	LM_LOG_ENGINE("[PathOCLRenderThread::" << threadIndex << "] Size of a GPUTask: " << gpuTaksSize <<
			"bytes (" << gpuTaksSizePart1 << " + " << gpuTaksSizePart2 << " + " << gpuTaksSizePart3 << ")");
	LM_LOG_ENGINE("[PathOCLRenderThread::" << threadIndex << "] Tasks buffer size: " << (gpuTaksSize * taskCount / 1024) << "Kbytes");

	// Check if the task buffer is too big
	if (oclDevice.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>() < gpuTaksSize * taskCount) {
		stringstream ss;
		ss << "The GPUTask buffer is too big for this device (i.e. CL_DEVICE_MAX_MEM_ALLOC_SIZE=" <<
				oclDevice.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>() <<
				"): try to reduce opencl.task.count and/or path.maxdepth and/or to change Sampler";
		throw std::runtime_error(ss.str());
	}

	tasksBuff = new cl::Buffer(oclContext,
			CL_MEM_READ_WRITE,
			gpuTaksSize * taskCount);
	deviceDesc->AllocMemory(tasksBuff->getInfo<CL_MEM_SIZE>());

	//--------------------------------------------------------------------------
	// Allocate GPU task statistic buffers
	//--------------------------------------------------------------------------

	LM_LOG_ENGINE("[PathOCLRenderThread::" << threadIndex << "] Task Stats buffer size: " << (sizeof(PathOCL::GPUTaskStats) * taskCount / 1024) << "Kbytes");
	taskStatsBuff = new cl::Buffer(oclContext,
			CL_MEM_READ_WRITE,
			sizeof(PathOCL::GPUTaskStats) * taskCount);
	deviceDesc->AllocMemory(taskStatsBuff->getInfo<CL_MEM_SIZE>());

	//--------------------------------------------------------------------------
	// Compile kernels
	//--------------------------------------------------------------------------

	InitKernels();

	//--------------------------------------------------------------------------
	// Initialize
	//--------------------------------------------------------------------------

	// Set kernel arguments
	SetKernelArgs();

	cl::CommandQueue &oclQueue = intersectionDevice->GetOpenCLQueue();

	// Clear the frame buffer
	oclQueue.enqueueNDRangeKernel(*initFBKernel, cl::NullRange,
			cl::NDRange(RoundUp<unsigned int>(frameBufferPixelCount, initFBWorkGroupSize)),
			cl::NDRange(initFBWorkGroupSize));

	// Initialize the tasks buffer
	oclQueue.enqueueNDRangeKernel(*initKernel, cl::NullRange,
			cl::NDRange(taskCount), cl::NDRange(initWorkGroupSize));
	oclQueue.finish();

	// Reset statistics in order to be more accurate
	intersectionDevice->ResetPerformaceStats();
}
Example #22
0
void PathOCLRenderThread::EndEdit(const EditActionList &editActions) {
	//--------------------------------------------------------------------------
	// Update OpenCL buffers
	//--------------------------------------------------------------------------

	if (editActions.Has(FILM_EDIT)) {
		// Resize the Framebuffer
		InitFrameBuffer();
	}

	if (editActions.Has(CAMERA_EDIT)) {
		// Update Camera
		InitCamera();
	}

	if (editActions.Has(GEOMETRY_EDIT)) {
		// Update Scene Geometry
		InitGeometry();
	}

	if (editActions.Has(MATERIALS_EDIT) || editActions.Has(MATERIAL_TYPES_EDIT)) {
		// Update Scene Materials
		InitMaterials();
	}

	if  (editActions.Has(AREALIGHTS_EDIT)) {
		// Update Scene Area Lights
		InitAreaLights();
	}

	if  (editActions.Has(INFINITELIGHT_EDIT)) {
		// Update Scene Infinite Light
		InitInfiniteLight();
	}

	if  (editActions.Has(SUNLIGHT_EDIT)) {
		// Update Scene Sun Light
		InitSunLight();
	}

	if  (editActions.Has(SKYLIGHT_EDIT)) {
		// Update Scene Sun Light
		InitSkyLight();
	}

	//--------------------------------------------------------------------------
	// Recompile Kernels if required
	//--------------------------------------------------------------------------

	if (editActions.Has(FILM_EDIT) || editActions.Has(MATERIAL_TYPES_EDIT))
		InitKernels();

	if (editActions.Size() > 0)
		SetKernelArgs();

	//--------------------------------------------------------------------------
	// Execute initialization kernels
	//--------------------------------------------------------------------------

	if (editActions.Size() > 0) {
		cl::CommandQueue &oclQueue = intersectionDevice->GetOpenCLQueue();

		// Clear the frame buffer
		oclQueue.enqueueNDRangeKernel(*initFBKernel, cl::NullRange,
			cl::NDRange(RoundUp<unsigned int>(frameBufferPixelCount, initFBWorkGroupSize)),
			cl::NDRange(initFBWorkGroupSize));

		// Initialize the tasks buffer
		oclQueue.enqueueNDRangeKernel(*initKernel, cl::NullRange,
				cl::NDRange(renderEngine->taskCount), cl::NDRange(initWorkGroupSize));
	}

	// Reset statistics in order to be more accurate
	intersectionDevice->ResetPerformaceStats();

	StartRenderThread();
}
void CreateScene (NewtonWorld* world, SceneManager* sceneManager)
{
	Entity* floor;
	NewtonCollision* shape;
	NewtonBody* floorBody;
	void* materialManager;
	SoundManager* sndManager;
	PhysicsMaterialInteration matInterations;
	
	sndManager = sceneManager->GetSoundManager();

	// Create the material for this scene, and attach it to the Newton World
	materialManager = CreateMaterialManager (world, sndManager);

	// add the Material table
	matInterations.m_restitution = 0.6f;
	matInterations.m_staticFriction = 0.6f;
	matInterations.m_kineticFriction = 0.3f;
	matInterations.m_scrapingSound = NULL;

	matInterations.m_impactSound = sndManager->LoadSound ("metalMetal.wav");
	AddMaterilInteraction (materialManager, m_metal, m_metal, &matInterations);

	matInterations.m_impactSound = sndManager->LoadSound ("boxBox.wav");
	AddMaterilInteraction (materialManager, m_wood, m_wood, &matInterations);

	matInterations.m_impactSound = sndManager->LoadSound ("metalBox.wav");
	AddMaterilInteraction (materialManager, m_metal, m_wood, &matInterations);
	
	matInterations.m_impactSound = sndManager->LoadSound ("grass0.wav");
	AddMaterilInteraction (materialManager, m_wood, m_grass, &matInterations);

	matInterations.m_impactSound = sndManager->LoadSound ("boxHit.wav");
	AddMaterilInteraction (materialManager, m_wood, m_bricks, &matInterations);

	matInterations.m_impactSound = sndManager->LoadSound ("grass1.wav");
	AddMaterilInteraction (materialManager, m_metal, m_grass, &matInterations);
	AddMaterilInteraction (materialManager, m_grass, m_bricks, &matInterations);

	matInterations.m_impactSound = sndManager->LoadSound ("metal.wav");
	AddMaterilInteraction (materialManager, m_metal, m_bricks, &matInterations);
	AddMaterilInteraction (materialManager, m_grass, m_grass, &matInterations);
	
	

	// Create a large body to be the floor
	floor = sceneManager->CreateEntity();
	floor->LoadMesh ("LevelMesh.dat");

	// add static floor Physics
	int materialMap[] = {m_bricks, m_grass, m_wood,	m_metal};
	shape = CreateMeshCollision (world, floor, materialMap);
	floorBody = CreateRigidBody (world, floor, shape, 0.0f);
	NewtonReleaseCollision (world, shape);


	// set the Transformation Matrix for this rigid body
	dMatrix matrix (floor->m_curRotation, floor->m_curPosition);
	NewtonBodySetMatrix (floorBody, &matrix[0][0]);

	// now we will use the properties of this body to set a proper world size.
	dVector minBox;
	dVector maxBox;
	NewtonCollisionCalculateAABB (shape, &matrix[0][0], &minBox[0], &maxBox[0]);

	// add some extra padding
	minBox.m_x -=  50.0f;
	minBox.m_y -= 500.0f;
	minBox.m_z -=  50.0f;

	maxBox.m_x +=  50.0f;
	maxBox.m_y += 500.0f;
	maxBox.m_z +=  50.0f;

	// set the new world size
	NewtonSetWorldSize (world, &minBox[0], &maxBox[0]);

	// add some visual entities.
	dFloat y0 = FindFloor (world, 0.0f, 0.0f) + 10.0f;
	for (int i = 0; i < 5; i ++) {
		Entity* smilly;
		NewtonBody* smillyBody;
		smilly = sceneManager->CreateEntity();
		smilly->LoadMesh ("Smilly.dat");
		smilly->m_curPosition.m_y = y0;
		y0 += 2.0f;
		smilly->m_prevPosition = smilly->m_curPosition;

		// add a body with a box shape
		shape = CreateNewtonBox (world, smilly, m_metal);
		smillyBody = CreateRigidBody (world, smilly, shape, 10.0f);
		NewtonReleaseCollision (world, shape);
	}

	// add some visual entities.
	y0 = FindFloor (world, 0.0f, 0.4f) + 10.5f;
	for (int i = 0; i < 5; i ++) {
		Entity* frowny;
		NewtonBody* frownyBody;
		frowny = sceneManager->CreateEntity();
		frowny->LoadMesh ("Frowny.dat");
		frowny->m_curPosition.m_z = 0.4f;
		frowny->m_curPosition.m_y = y0;
		y0 += 2.0f;
		frowny->m_prevPosition = frowny->m_curPosition;

		// add a body with a Convex hull shape
		shape = CreateNewtonConvex (world, frowny, m_wood);
		frownyBody = CreateRigidBody (world, frowny, shape, 10.0f);
		NewtonReleaseCollision (world, shape);
	}

	y0 = FindFloor (world, 0.0f, 2.0f) + 10.5f;
	for (int i = 0; i < 5; i ++) {
		Entity* frowny;
		NewtonBody* frownyBody;

		frowny = sceneManager->CreateEntity();
		frowny->LoadMesh ("dumb.dat");
		frowny->m_curPosition.m_z = 2.0f;
		frowny->m_curPosition.m_y = y0;
		y0 += 2.0f;
		frowny->m_prevPosition = frowny->m_curPosition;

		// add a body with a Convex hull shape
		int materialMap[] = {m_grass, m_wood, m_metal, m_metal};
		shape = CreateNewtonCompoundFromEntitySubmesh (world, frowny, materialMap);
		frownyBody = CreateRigidBody (world, frowny, shape, 10.0f);
		NewtonReleaseCollision (world, shape);
	}


	// set the Camera EyePoint close to the scene action
	InitCamera (dVector (-15.0f, FindFloor (world, -15.0f, 0.0f) + 5.0f, 0.0f), dVector (1.0f, 0.0f, 0.0f));
}
Example #24
0
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
    hInst = hInstance; // 将实例句柄存储在全局变量中
    
    //创建并将主窗口句柄存储在全局变量中
    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
    
    if (!hWnd)
    {
       return FALSE;
    }
    
    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);


    /*
     timer
    */
    //创建WaitableTimer
    HTimer = CreateWaitableTimer(NULL,FALSE,NULL);
    DebugAssert(NULL!=HTimer, "CreateWaitableTimer 失败: %d", GetLastError());
    //初始化WaitableTimer
    LARGE_INTEGER liDueTime;
    liDueTime.QuadPart = -1i64;   //1秒后开始计时
    SetWaitableTimer(HTimer, &liDueTime, 100, NULL, NULL, 0);  //周期200ms = 0.2s
    FrameCount = 0;

    /*
        GraphicsDevice
    */
    pGDevice = GraphicsDevice::getInstance(hWnd);
    pGDevice->BuildViewports();
    /*
        Camera
    */
    InitCamera();
    cube.SetVertexData(0);
    cube.Create(pGDevice->m_pD3DDevice);
    /*
        Axis
    */
	axis.SetVertexData(0);  //参数实际上不起作用 TODO: 改进设计
    axis.Create(pGDevice->m_pD3DDevice);
    //axis.CreateXYZ(pGDevice->m_pD3DDevice);
    //axis.UpdateXYZ(fixedEyePoint);
    /*
        读取fbx,加载Skinned mesh
    */
    // 获取输出文件路径 测试用
    char fileSrc[MAX_PATH];
    GetTestFileName(fileSrc);
    skinMesh.Load(fileSrc, pGDevice->m_pD3DDevice);
    /*
        Matrix
    */
    D3DXMatrixIdentity(&identity);    
    D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI / 4.0f,
        (float)pGDevice->mDefaultViewport.Width / (float)pGDevice->mDefaultViewport.Height, 1.0f, 1000.0f);    
    return TRUE;
}
void CreateScene (NewtonWorld* world, SceneManager* sceneManager)
{
	Entity* floor;
	Entity* smilly;
	Entity* frowny;
	NewtonBody* floorBody;
	NewtonBody* smillyBody;
	NewtonBody* frownyBody;
	NewtonCollision* shape;

	// Create the material for this scene
	CreateMateials (world, sceneManager);

	// Create a large body to be the floor
	floor = sceneManager->CreateEntity();

	// add scene collision from a level mesh
	shape = CreateHeightFieldCollision (world, "h2.raw", 0);
	floorBody = CreateRigidBody (world, floor, shape, 0.0f);
	NewtonReleaseCollision (world, shape);

	// make a visual mesh for the collision data
	CreateHeightFieldMesh (shape, floor);

	// set the matrix at the origin
	dVector boxP0; 
	dVector boxP1; 
	dMatrix matrix (floor->m_curRotation, floor->m_curPosition);
	NewtonCollisionCalculateAABB (shape, &matrix[0][0], &boxP0.m_x, &boxP1.m_x); 

	// place the origin of the visual mesh at the center of the height field
	matrix.m_posit = (boxP0 + boxP1).Scale (-0.5f);
	matrix.m_posit.m_w = 1.0f;
	floor->m_curPosition = matrix.m_posit;
	floor->m_prevPosition = matrix.m_posit;

	// relocate the body;
	NewtonBodySetMatrix (floorBody, &matrix[0][0]);

	// now we will use the properties of this body to set a proper world size.
	NewtonCollisionCalculateAABB (shape, &matrix[0][0], &boxP0.m_x, &boxP1.m_x); 

	// add some extra padding
	boxP0.m_x -=  50.0f;
	boxP0.m_y -= 500.0f;
	boxP0.m_z -=  50.0f;

	boxP1.m_x +=  50.0f;
	boxP1.m_y += 500.0f;
	boxP1.m_z +=  50.0f;

	// set the new world size
	NewtonSetWorldSize (world, &boxP0[0], &boxP1[0]);


	// assign an Material ID to this body
	NewtonBodySetMaterialGroupID (floorBody, g_floorMaterial);


	// add some visual entities.
	dFloat y0 = FindFloor (world, 0.0f, 0.0f) + 10.0f;
	for (int i = 0; i < 5; i ++) {
		smilly = sceneManager->CreateEntity();
		smilly->LoadMesh ("Smilly.dat");
		smilly->m_curPosition.m_y = y0;
		y0 += 2.0f;
		smilly->m_prevPosition = smilly->m_curPosition;

		// add a body with a box shape
		shape = CreateNewtonBox (world, smilly, 0);
		smillyBody = CreateRigidBody (world, smilly, shape, 10.0f);
		NewtonReleaseCollision (world, shape);

		// assign an Material ID to this body
		NewtonBodySetMaterialGroupID (smillyBody, g_metalMaterial);
	}


	// add some visual entities.
	y0 = FindFloor (world, 0.0f, 0.4f) + 10.5f;
	for (int i = 0; i < 5; i ++) {
		frowny = sceneManager->CreateEntity();
		frowny->LoadMesh ("Frowny.dat");
		frowny->m_curPosition.m_z = 0.4f;
		frowny->m_curPosition.m_y = y0;
		y0 += 2.0f;
		frowny->m_prevPosition = frowny->m_curPosition;

		// add a body with a Convex hull shape
		shape = CreateNewtonConvex (world, frowny, 0);
		frownyBody = CreateRigidBody (world, frowny, shape, 10.0f);
		NewtonReleaseCollision (world, shape);

		// assign an Material ID to this body
		NewtonBodySetMaterialGroupID (frownyBody, g_woodMaterial);
	}

	// set the Camera EyePoint close to the scene action
	InitCamera (dVector (-15.0f, FindFloor (world, -15.0f, 0.0f) + 5.0f, 0.0f), dVector (1.0f, 0.0f, 0.0f));
}
Example #26
0
int CALLBACK WinMain(HINSTANCE Instance, HINSTANCE PrevInstance, LPSTR CommandLine, int ShowFlags)
{
	DWORD error;
	UINT DesiredSchedulerMS = 1;

	float MSPerFrame = 0;
	float TargetSecondsPerFrame;

	int width;
	int height;
	
	HWND Window;
	RECT ClientRect;

	HGLRC RC;

	GLenum err = 0;

	GameState state = {0};

	WNDCLASSEX WindowClass;
	WindowClass.cbSize = sizeof(WindowClass);
    WindowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    WindowClass.lpfnWndProc = MyWindowProc;
    WindowClass.cbClsExtra = 0;
    WindowClass.cbWndExtra = 0;
    WindowClass.hInstance = Instance;
    WindowClass.hIcon = 0;
    WindowClass.hCursor = 0;
    WindowClass.hbrBackground = 0;
    WindowClass.lpszMenuName = NULL;
    WindowClass.lpszClassName = "WindowClass";
    WindowClass.hIconSm = 0;

	if( RegisterClassEx(&WindowClass) )
	{
		width = GetSystemMetrics(SM_CXMAXIMIZED);
		height = GetSystemMetrics(SM_CYMAXIMIZED);

		Window = CreateWindowExA(0, WindowClass.lpszClassName, "My Test Window",
									  WS_OVERLAPPEDWINDOW|WS_VISIBLE|WS_MAXIMIZE,
									  0, 0, width, height,
									  0, 0, Instance, 0);

		TargetSecondsPerFrame = 1.0f / 60.0f;

		if(Window)
		{
			HDC DC = GetDC(Window);
			SetupPixelFormat(DC);
            RC = wglCreateContext(DC);
            wglMakeCurrent(DC, RC);

			err = glewInit();
			if (GLEW_OK != err)
				fprintf(stderr, "Error: %s\n", glewGetErrorString(err));

			GetClientRect(Window, &ClientRect);

			width = ClientRect.right - ClientRect.left;
			height = ClientRect.bottom - ClientRect.top;

			state.width = (float)width;
			state.height = (float)height;

			glViewport(0,0, width, height);
			glEnable(GL_DEPTH_TEST);

			//V3 p1 = { -8.0f, 6.0f, 4.3f };
			V3 p1 = { 0.0f, 6.0f, 4.0f };
			InitCamera(&state.main, p1);
			
			state.deltaT = TargetSecondsPerFrame;
			
			InitGame(&state);
			
			Running = 1;

			LARGE_INTEGER start, end;

			float timeElasped;
			DWORD sleepMS;

			while(Running)
			{
				start = Win32GetTime();

				ProcessMessages(&state);

				if(state.keys & Z_KEY){
					glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		    	}else {
					glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
				}
				
				UpdateAndRender(&state);

				end = Win32GetTime();
				timeElasped = Win32GetSecondsElapsed(start, end);

				if(timeElasped < TargetSecondsPerFrame){
					sleepMS = (DWORD)((TargetSecondsPerFrame*1000) - (timeElasped*1000));
					Sleep(sleepMS);
				}else{
					OutputDebugString("Missed Frame");
				}


				SwapBuffers(DC);
			}
		}
		else
		{
			error = GetLastError();
		}
	}
	else
	{
		error = GetLastError();
	}

	return 0;
}
Example #27
0
int main(void)
{
	
	DDRD = 0b01110000;
	DDRA = 0b00000001;
	
	//wdt_reset();
	//wdt_disable();
	char replyDat[2];
	i2c_init();
	USART roverPort;
	USART devicePort;
	CommInterface inf;
	CommPacket commPkt;
	char commData[20];
	char commRet;
	Timer accelTimer;
	Timer dataTimer;
	int sensorError;
	
	//PORTA = 1;
	//_delay_ms(250);
	//PORTA = 0;
	//_delay_ms(250);
	
	USART_InitPortStructs();

	setDeviceCamera();
	USART_Open(&roverPort, 0, USART_BAUD_38400, 20, 32, true);
	CommInterfaceInit(&inf, &roverPort);
	USART_Open(&devicePort, 1, USART_BAUD_9600, 20, 5, false);
	setDeviceServo();
	sensorError = InitAccelerometer(&inf);
	sensorError = InitBarometer(&inf);
	InitServos(&devicePort);
	InitCamera(&devicePort);
	InitTimers();
	//StartTimer(&accelTimer);
	//StartTimer(&dataTimer);

	setDeviceServo();
	PORTA |= 1;
	PanTiltSetPosition(TILT_SERVO, TILT_CENTER);
	PanTiltSetPosition(PAN_SERVO, PAN_CENTER);
    char pingRespond = 0xAA;
	
	commPkt.data = commData;
	
	CommPacket pkt;
	
	char textBuffer[40];
	char length;
	unsigned char aclBuf[6];
	//ServiceBarometer(3);
	
	//Enable Watchdog
	//wdt_enable(0b111);
	while(1) {
			
		while(CommRXPacketsAvailable(&inf)) {
			commRet = CommGetPacket(&inf, &commPkt, 20);
			
			if (!commRet) // didn't get packet returned, even though it said we had one. give up for now
				break;
			
			if (commPkt.length==0) { // bad 0-length packet, skip to the next one
				continue;
			}
			
			// must at least have a length of 1, check the first byte to see what device this is targeted at
			if (commPkt.data[0]==SYS_PANTILT) {
				PORTA &= ~1;
				setDeviceServo();
				PanTiltHandlePacket(&commPkt);
				PORTA = sensorError;
				
			}
			else if (commPkt.data[0]==SYS_CAMERA) {
				PORTA &= ~1;
				setDeviceCamera();
				CameraHandlePacket(&commPkt);
				PORTA = sensorError;
			}
			else if (commPkt.data[0]==SYS_BAROMETER) {
				PORTA &= ~1;
				BarometerHandlePacket(&commPkt);
				PORTA = sensorError;
			}
			else if (commPkt.data[0]==SYS_ACCEL) {
				PORTA &= ~1;
				AccelHandlePacket(&commPkt);
				PORTA = sensorError;
			}
			else if (commPkt.data[0]==SYS_PING)
			{
				pkt.target = 1;
				pkt.length = 1;
				pkt.data = &pingRespond;
				CommSendPacket(&inf,&pkt);
			}
		}
		/*
		if (GetSpanUs(&dataTimer) > FROM_uS(1000000))
		{
			
			USART_WriteByte(&roverPort,0xFE);
			
			USART_WriteByte(&roverPort,temperatureData>>8);
			USART_WriteByte(&roverPort,temperatureData&0xFF);
			
			USART_WriteByte(&roverPort,barometerData>>16);
			USART_WriteByte(&roverPort,(barometerData>>8)&0xFF);
			USART_WriteByte(&roverPort,barometerData&0xFF);
			AccelGetAverage(aclBuf);
	
			length = sprintf(textBuffer,"X: %d \tY: %d \n\r",(aclBuf[0]<<8)|aclBuf[1], (aclBuf[2]<<8)|aclBuf[3]);
			
			USART_Write(&roverPort,textBuffer,length);
			StartTimer(&dataTimer);
		}
		*/
		/*
		if (GetSpanUs(&accelTimer) > 39)
		{
			sensorError |= AccelAddDataToBuffer();
			StartTimer(&accelTimer);
		}
		
		if (BarometerGetState() == 1)
		{	
			sensorError |= ServiceBarometer(3);
		}*/				
	}
}
Example #28
0
void KeyboardHandler (unsigned char cKey, int iX, int iY) // keyboard input handling function
{
	switch (cKey)
	{
	case 'p' :
	case 'P' :
		bPause = !bPause ;
	break ;
#ifdef _DEBUG
	case 'm' : // toggle filling
	case 'M' :
		ToggleFilling(!bFilling) ;
	break ;

	case 'n' : // toggle lighting
	case 'N' :
		ToggleLighting(!bLighting) ;
	break ;
#endif

	case 'i' : 
	case 'I' :
		InitCamera(10) ;
	break ;

	case 'a' :
	case 'A' :
		bAutofire = !bAutofire ;
	break ;

	case ' ' :
		if (!bExplode && !bPause) FireShot(&Player, pPlayerShots) ;
	break ;
	case 'w' :
	case 'W' :
		fCameraAngle[0] += 10 ;
	break ;
	case 'x' :
	case 'X' :
		fCameraAngle[0] -= 10 ;
	break ;
	case 's' :
    case 'S' :
		fCameraAngle[2] += 10 ;
	break ;
	case 'd' :
	case 'D' :
		fCameraAngle[2] -= 10 ;
	break ;

	case 'r' :
	case 'R' :
		iScore = 0 ;
		bExplode = !bExplode ;
		iCount = 0 ;
	break ;

	case 'c' :
	case 'C' :
		bRotate = !bRotate ;
	break ;

	case 'q' : // quit program
	case 'Q' :
		ClearEntitys(pPlayerShots) ;
		ClearEntitys(pEnemyShots) ;
		ClearEntitys(pStars) ;
		ClearEntitys(pPlanets) ;

		Particles.Clear(true) ;
		exit(0) ;
	break ;
	}
}
Example #29
0
int OpenCameraByID(int camid)
{   
    qhyusb = new QUsb();

    qhyccd_device *dev;
    qhyccd_device_model *model;

    qhyusb->qhyccd_init();
    
    ssize_t n_device;
    n_device = qhyusb->qhyccd_get_device_list(&(qhyusb->QCam.device_list));
    #ifdef QHYCCD_DEBUG
    printf("Total devices %d\n",n_device);
    #endif
    
    int i;
    for(i = 0;i < n_device;i++)
    {
        model = qhyusb->qhyccd_get_device_model(qhyusb->QCam.device_list[i]);
        
        #ifdef QHYCCD_DEBUG
        printf("model is %d\n",model->model_id);
        #endif
        dev = qhyusb->QCam.device_list[i];
        qhyusb->qhyccd_open(dev,&(qhyusb->QCam.ccd_handle));

        if(model->model_id == QHYCCD_QHY5II)
        {            
            unsigned char buf[16];
            EepromRead(0x10,buf,16);
            if(buf[1] == 1)
                qhyusb->QCam.isColor = true;
            else 
                qhyusb->QCam.isColor = false;

            if(buf[0] == 6 && camid == DEVICETYPE_QHY5LII)
            {
                qhyusb->QCam.CAMERA = DEVICETYPE_QHY5LII;   
                q5lii = new QHY5LII();
                InitCamera();
                return DEVICETYPE_QHY5LII;
            }
            else if(buf[0] == 1 && camid == DEVICETYPE_QHY5II)
            {
                qhyusb->QCam.CAMERA = DEVICETYPE_QHY5II;
                q5ii = new QHY5II();
                InitCamera();
                return DEVICETYPE_QHY5II;
            }
        }
        else if(model->model_id == QHYCCD_QHY6 && camid == DEVICETYPE_QHY6)
        {
            #ifdef QHYCCD_DEBUG
            printf("QHY6 Found\n");
            #endif
            qhy6 = new QHY6();
            qhyusb->QCam.CAMERA = DEVICETYPE_QHY6;
            InitCamera();
            return DEVICETYPE_QHY6;
        }
        else if(model->model_id == QHYCCD_QHY9 && camid == DEVICETYPE_QHY9)
        {
            #ifdef QHYCCD_DEBUG
            printf("QHY9 Found\n");
            #endif
            qhy9 = new QHY9();
            qhyusb->QCam.CAMERA = DEVICETYPE_QHY9;
            InitCamera();
            return DEVICETYPE_QHY9;
        }
        else if(model->model_id == QHYCCD_IC8300 && camid == DEVICETYPE_IC8300)
        {
            ic8300 = new IC8300();
            qhyusb->QCam.CAMERA = DEVICETYPE_IC8300;
            InitCamera();
            ic8300->send2oled("USB CAM");
            return DEVICETYPE_IC8300;
        }
        else if(model->model_id == QHYCCD_QHY11 && camid == DEVICETYPE_QHY11)
        {
            qhy11 = new QHY11();
            qhyusb->QCam.CAMERA = DEVICETYPE_QHY11;
            InitCamera();
            return DEVICETYPE_QHY11;
        }
        else if(model->model_id == QHYCCD_QHY22 && camid == DEVICETYPE_QHY22)
        {
            qhy22 = new QHY22();
            #ifdef QHYCCD_DEBUG
            printf("QHY22 Found\n");
            #endif
            qhyusb->QCam.CAMERA = DEVICETYPE_QHY22;
            InitCamera();
            return DEVICETYPE_QHY22;
        }
        else if(model->model_id == QHYCCD_QHY21 && camid == DEVICETYPE_QHY21)
        {
            qhy21 = new QHY21();
            #ifdef QHYCCD_DEBUG
            printf("QHY21 Found\n");
            #endif
            qhyusb->QCam.CAMERA = DEVICETYPE_QHY21;
            InitCamera();
            return DEVICETYPE_QHY21;
        }  
        else if(model->model_id == QHYCCD_QHY23 && camid == DEVICETYPE_QHY23)
        {
            qhy23 = new QHY23();
            #ifdef QHYCCD_DEBUG
            printf("QHY23 Found\n");
            #endif
            qhyusb->QCam.CAMERA = DEVICETYPE_QHY23;
            InitCamera();
            return DEVICETYPE_QHY23;
        }      
        else if(model->model_id == QHYCCD_QHY16000 && camid == DEVICETYPE_QHY16000)
        {
            qhy16000 = new QHY16000();
            #ifdef QHYCCD_DEBUG
            printf("QHY16000 Found\n");
            #endif
            qhyusb->QCam.CAMERA = DEVICETYPE_QHY16000;
            InitCamera();
            return DEVICETYPE_QHY16000;
        } 
    }
    #ifdef QHYCCD_DEBUG
    printf("please check USB link or camid\n");
    #endif
    return DEVICETYPE_UNKOWN;   
}
Example #30
0
void CCube::RenderCube(const GLfloat* asize)
{
    static double dOff[3] = {-1.0f, -1.0f, -.5f};
    static const double dMin[3] = {-1.0f, -1.0f, -.5f};
    static const double dMax[3] = {2.0f, 1.5f, 1.0f};
    static const double dFactor[3] = {.01f, .01f, .01f};
    static bool bDec[3] = { false, false, false};

    InitCamera();

    glLineWidth(3);

    diffuse[0] = diffuse[1] = diffuse[2] = 0.8 + scaleAll;
    specular[0] = specular[1] = specular[2] = 1.0;

    glPushMatrix();   // light matrix
    OrthographicMatrix();

    // get an appropriate lOffset if available - we want at least 100 points + 2 for "padding"
    long lOffset = 0;
    if (sm && sm->bSensorFound) {
        if (sm->lOffset > MAX_PLOT_POINTS+2) { // note the two point "padding" so we are reading the latest value that isn't in use by the sensor (i.e. writing)
            lOffset = sm->lOffset-2;
        }
    }

    if (bIsQCNLive) {
        glTranslatef(asize[E_DX], asize[E_DZ], 0.0);//Jesse Lawrence Changed - X & Z MOTIONS (Y IS SIZE)
    } else {
        glTranslatef(-.50 + dOff[0], dOff[1], dOff[2]);
    }

    for (int i = 0; i < 3; i++)  {
        if (dOff[i]>dMax[i]) {
            bDec[i] = true;
        }
        else if (dOff[i]<dMin[i]) {
            bDec[i] = false;
        }
        dOff[i] += (dFactor[i] * (bDec[i] ? -1.0 : 1.0));
    }

    glRotatef(rot.x, rot.y, rot.y/3.0f, 0.0);
    rot.x += rotationSpeed * 1.9134f;
    rot.y += rotationSpeed * 2.1234f;

    glPushMatrix();

    //glTranslatef(0.0f, 0.0f,-7.0f);	// Translate Into The Screen 7.0 Units
    //glRotatef(rotqube,0.0f,1.0f,0.0f);	// Rotate The cube around the Y axis
    //glRotatef(rotqube,1.0f,1.0f,1.0f);

    if (bIsQCNLive) {
        float asize_all = asize[E_DY];//Jesse Lawrence Added - Constant size for all dimensions
        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(blue);          // Color Green
        glVertex3f( asize_all, asize_all, -asize_all);      // Top Right Of The Quad (Top)
        glVertex3f(-asize_all, asize_all,-asize_all);      // Top Left Of The Quad (Top)
        glVertex3f(-asize_all, asize_all, asize_all);      // Bottom Left Of The Quad (Top)
        glVertex3f( asize_all, asize_all, asize_all);      // Bottom Right Of The Quad (Top)
        glEnd();
        // note the asize in DrawPlot below should be the "y-axis" for whichever face we're looking at
//  DrawPlot(lOffset ? (const GLfloat*) &(sm->x0[lOffset]) : NULL, asize, CUBE_TOP);  // x-axis is green

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(blue);         // Color Yellow
        glVertex3f( asize_all,-asize_all, asize_all);      // Top Right Of The Quad (Bottom)
        glVertex3f(-asize_all,-asize_all, asize_all);      // Top Left Of The Quad (Bottom)
        glVertex3f(-asize_all,-asize_all,-asize_all);      // Bottom Left Of The Quad (Bottom)
        glVertex3f( asize_all,-asize_all,-asize_all);      // Bottom Right Of The Quad (Bottom)
        glEnd();
//  DrawPlot(lOffset ? (const float*) &(sm->y0[lOffset]) : NULL, asize, CUBE_BOTTOM);   // y-axis is yellow

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(orange);           // Color Blue
        glVertex3f( asize_all, asize_all, asize_all);      // Top Right Of The Quad (Front)
        glVertex3f(-asize_all, asize_all, asize_all);      // Top Left Of The Quad (Front)
        glVertex3f(-asize_all,-asize_all, asize_all);      // Bottom Left Of The Quad (Front)
        glVertex3f( asize_all,-asize_all, asize_all);      // Bottom Right Of The Quad (Front)
        glEnd();
//  DrawPlot(lOffset ? (const float*) &(sm->z0[lOffset]) : NULL, asize, CUBE_FRONT);  // z-axis is blue

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(green);            // Color Red
        glVertex3f( asize_all,-asize_all,-asize_all);      // Top Right Of The Quad (Back)
        glVertex3f(-asize_all,-asize_all,-asize_all);      // Top Left Of The Quad (Back)
        glVertex3f(-asize_all, asize_all,-asize_all);      // Bottom Left Of The Quad (Back)
        glVertex3f( asize_all, asize_all,-asize_all);      // Bottom Right Of The Quad (Back)
        glEnd();
//  DrawPlot(lOffset ? (const float*) &(sm->fsig[lOffset]) : NULL, asize, CUBE_BACK);   // fsig/significance is red

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(green);           // Color Cyan
        glVertex3f(-asize_all, asize_all, asize_all);      // Top Right Of The Quad (Left)
        glVertex3f(-asize_all, asize_all,-asize_all);      // Top Left Of The Quad (Left)
        glVertex3f(-asize_all,-asize_all,-asize_all);      // Bottom Left Of The Quad (Left)
        glVertex3f(-asize_all,-asize_all, asize_all);      // Bottom Right Of The Quad (Left)
        glEnd();
//  DrawPlot(lOffset ? (const float*) &(sm->fmag[lOffset]) : NULL, asize, CUBE_LEFT);   // magnitude

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(orange);        // Color Magenta
        glVertex3f( asize_all, asize_all,-asize_all);      // Top Right Of The Quad (Right)
        glVertex3f( asize_all, asize_all, asize_all);      // Top Left Of The Quad (Right)
        glVertex3f( asize_all,-asize_all, asize_all);      // Bottom Left Of The Quad (Right)
        glVertex3f( asize_all,-asize_all,-asize_all);      // Bottom Right Of The Quad (Right)
        glEnd();
//  DrawPlot(lOffset ? (const float*) &(sm->vari[lOffset]) : NULL, asize, CUBE_RIGHT);   // variance
    } else {  // screensaver mode
        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(green);          // Color Green
        glVertex3f( asize[E_DX], asize[E_DY], -asize[E_DZ]);      // Top Right Of The Quad (Top)
        glVertex3f(-asize[E_DX], asize[E_DY],-asize[E_DZ]);      // Top Left Of The Quad (Top)
        glVertex3f(-asize[E_DX], asize[E_DY], asize[E_DZ]);      // Bottom Left Of The Quad (Top)
        glVertex3f( asize[E_DX], asize[E_DY], asize[E_DZ]);      // Bottom Right Of The Quad (Top)
        glEnd();
        // note the asize in DrawPlot below should be the "y-axis" for whichever face we're looking at
        DrawPlot(lOffset ? (const GLfloat*) &(sm->x0[lOffset]) : NULL, asize, CUBE_TOP);  // x-axis is green

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(yellow);         // Color Yellow
        glVertex3f( asize[E_DX],-asize[E_DY], asize[E_DZ]);      // Top Right Of The Quad (Bottom)
        glVertex3f(-asize[E_DX],-asize[E_DY], asize[E_DZ]);      // Top Left Of The Quad (Bottom)
        glVertex3f(-asize[E_DX],-asize[E_DY],-asize[E_DZ]);      // Bottom Left Of The Quad (Bottom)
        glVertex3f( asize[E_DX],-asize[E_DY],-asize[E_DZ]);      // Bottom Right Of The Quad (Bottom)
        glEnd();
        DrawPlot(lOffset ? (const float*) &(sm->y0[lOffset]) : NULL, asize, CUBE_BOTTOM);   // y-axis is yellow

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(blue);           // Color Blue
        glVertex3f( asize[E_DX], asize[E_DY], asize[E_DZ]);      // Top Right Of The Quad (Front)
        glVertex3f(-asize[E_DX], asize[E_DY], asize[E_DZ]);      // Top Left Of The Quad (Front)
        glVertex3f(-asize[E_DX],-asize[E_DY], asize[E_DZ]);      // Bottom Left Of The Quad (Front)
        glVertex3f( asize[E_DX],-asize[E_DY], asize[E_DZ]);      // Bottom Right Of The Quad (Front)
        glEnd();
        DrawPlot(lOffset ? (const float*) &(sm->z0[lOffset]) : NULL, asize, CUBE_FRONT);  // z-axis is blue

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(red);            // Color Red
        glVertex3f( asize[E_DX],-asize[E_DY],-asize[E_DZ]);      // Top Right Of The Quad (Back)
        glVertex3f(-asize[E_DX],-asize[E_DY],-asize[E_DZ]);      // Top Left Of The Quad (Back)
        glVertex3f(-asize[E_DX], asize[E_DY],-asize[E_DZ]);      // Bottom Left Of The Quad (Back)
        glVertex3f( asize[E_DX], asize[E_DY],-asize[E_DZ]);      // Bottom Right Of The Quad (Back)
        glEnd();
        DrawPlot(lOffset ? (const float*) &(sm->fsig[lOffset]) : NULL, asize, CUBE_BACK);   // fsig/significance is red

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(cyan);           // Color Cyan
        glVertex3f(-asize[E_DX], asize[E_DY], asize[E_DZ]);      // Top Right Of The Quad (Left)
        glVertex3f(-asize[E_DX], asize[E_DY],-asize[E_DZ]);      // Top Left Of The Quad (Left)
        glVertex3f(-asize[E_DX],-asize[E_DY],-asize[E_DZ]);      // Bottom Left Of The Quad (Left)
        glVertex3f(-asize[E_DX],-asize[E_DY], asize[E_DZ]);      // Bottom Right Of The Quad (Left)
        glEnd();
        DrawPlot(lOffset ? (const float*) &(sm->fmag[lOffset]) : NULL, asize, CUBE_LEFT);   // magnitude

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(magenta);        // Color Magenta
        glVertex3f( asize[E_DX], asize[E_DY],-asize[E_DZ]);      // Top Right Of The Quad (Right)
        glVertex3f( asize[E_DX], asize[E_DY], asize[E_DZ]);      // Top Left Of The Quad (Right)
        glVertex3f( asize[E_DX],-asize[E_DY], asize[E_DZ]);      // Bottom Left Of The Quad (Right)
        glVertex3f( asize[E_DX],-asize[E_DY],-asize[E_DZ]);      // Bottom Right Of The Quad (Right)
        glEnd();
        DrawPlot(lOffset ? (const float*) &(sm->vari[lOffset]) : NULL, asize, CUBE_RIGHT);   // variance
    }

    glPopMatrix();
    glPopMatrix(); // rotation matrix

    glFlush();
}