예제 #1
0
파일: moveutil.c 프로젝트: Limsik/e17
int
processMove(moveContext *context)
{
   const unsigned int hues[] = { 4 << 24, 4 << 24, 4 << 24, 4 << 24 };
   int ret = -1;

   if (readCamera (context) > 0)
     {
        ret = gemUpdateStart (context->camRead.buffer, context->camRead.timestamp);
        //printf ("Return from gemUpdateStart %X\n", ret);
        if (ret == 0)
          {
             ret = gemUpdateFinish ();
             //printf ("Return from gemUpdateFinish %X\n", ret);
             if (ret == 0)
               {
                  ret = gemGetState (0, STATE_LATEST_IMAGE_TIME, 0, &context->state);
                  switch (ret) {
                     case 2:
                       gemForceRGB (0, 0.5, 0.5, 0.5);
                       break;

                     case 5:
                       gemTrackHues (hues, NULL);
                       break;

                     default:
                       break;
                    }
               }
          }
     }

   return ret;
}
예제 #2
0
//--------------------------------------------------------------
void testApp::update(){
    
    fftLive.setThreshold(audioThreshold);
    fftLive.setPeakDecay(audioPeakDecay);
    fftLive.setMaxDecay(audioMaxDecay);
    fftLive.setMirrorData(audioMirror);
    fftLive.update();
    
    fftLive.getFftPeakData(rawFFT, nbins);
    
    bool newFrame = useKinect ? readKinect() : readCamera();
    
    if (newFrame) {
        diff.absDiff(grayImage, grayImagePrev);
        diffFloat = diff;
        diffFloat *= (1.0f + glowExtra * lows);
        
        if (!bufferFloat.bAllocated)
            bufferFloat = diffFloat;
        else {
            bufferFloat *= 0.85;
            bufferFloat += diffFloat;
        }
        
		contourFinder.findContours(grayImage, blobMin, (inputWidth*inputHeight)/2, 100, false);
    }

}
예제 #3
0
int SetupandLoad(){
    //memset to ensure we dont have unusual char attributes at starting
    memset(&Enemy, 0, sizeof(Character));
    memset(&Player, 0, sizeof(Character));
    //TODO temp hardcoding
    Enemy.weaponRange = 6;
    Player.weaponRange = 2.5;

    //get access to dark souls memory
    char * processName = "DARKSOULS.exe";
    //get the process id from the name
    int processId = GetProcessIdFromName(processName);
    //open the handle
    processHandle = OpenProcess(PROCESS_ALL_ACCESS, 0, processId);
    //get the base address of the process and append all other addresses onto it
    memorybase = GetModuleBase(processId, processName);
    Enemy_base_add += memorybase;
    player_base_add += memorybase;

    ReadPointerEndAddresses(processHandle);

    //start gui
    guiStart();

    //get current camera details to lock
    readCamera(&processHandle, memorybase);

    //load neural network and threads
    int error = ReadyThreads();
    if (error){
        return error;
    }

    //TODO load vJoy driver(we ONLY want the driver loaded when program running)
    //want to use controller input, instead of keyboard, as analog stick is more precise movement
    int loadresult = loadvJoy(iInterface);
    if (loadresult != 0){
        return loadresult;
    }
    iReport.bDevice = (BYTE)iInterface;
    ResetVJoyController();

    //set window focus
    HWND h = FindWindow(NULL, TEXT("DARK SOULS"));
    SetForegroundWindow(h);
    SetFocus(h);

    return EXIT_SUCCESS;
}
예제 #4
0
파일: Picture.cpp 프로젝트: alwalker/TTU
void Picture::render(Pixel* pix)
{
	double eX, eY, eZ, aX, aY, aZ, fov, zMin, zMax;
	Vector *vUp;
	vUp = readCamera(&eX, &eY, &eZ, &aX, &aY, &aZ);
	readFOV(&zMax, &zMin, &fov);
	BasicObject* obj = readObject("sphere.txt");
	InstanceObject* io = buildInstanceObject("trs.txt", obj);
	Scene *sc;
	Matrix *windowTransform = AffineTransforms::getWindowTransform(pix->getWidth(), pix->getHeight());
	Matrix *aspectRatioTransform = AffineTransforms::getAspectTransform(pix->getWidth(), pix->getHeight(), fov);
	Matrix *normalTransform = AffineTransforms::getNormalTransform(zMin, zMax);
	Matrix *cameraTransform = AffineTransforms::getCameraTransform(eX, eY, eZ, aX, aY, aZ, vUp);
	Matrix *WNAC;

	/*printf("\nCamera: \n");
	cameraTransform->printMatrix();
	printf("\nNormal: \n");
	normalTransform->printMatrix();
	printf("\nAspect Ratio: \n");
	aspectRatioTransform->printMatrix();
	printf("\nWindow: \n");
	windowTransform->printMatrix();*/
	
	Matrix *temp = aspectRatioTransform->multiply(cameraTransform);
	Matrix *temp2 = normalTransform->multiply(temp);
	WNAC = windowTransform->multiply(temp2);

	
	//WNAC->printMatrix();

	delete temp;
	delete temp2;
	delete cameraTransform;
	delete normalTransform;
	delete windowTransform;
	delete aspectRatioTransform;
	
	sc = new Scene(WNAC);


	sc->addNode(io);

	sc->render(pix);

	delete sc;
	printf("\n\n");
}
예제 #5
0
TC_GAME_API void LoadM2Cameras(std::string const& dataPath)
{
    sFlyByCameraStore.clear();
    TC_LOG_INFO("server.loading", ">> Loading Cinematic Camera files");

    boost::filesystem::path camerasPath = boost::filesystem::path(dataPath) / "cameras";

    uint32 oldMSTime = getMSTime();
    for (CinematicCameraEntry const* cameraEntry : sCinematicCameraStore)
    {
        boost::filesystem::path filename = camerasPath / Trinity::StringFormat("FILE%08X.xxx", cameraEntry->ModelFileDataID);

        // Convert to native format
        filename.make_preferred();

        std::ifstream m2file(filename.string().c_str(), std::ios::in | std::ios::binary);
        if (!m2file.is_open())
            continue;

        // Get file size
        m2file.seekg(0, std::ios::end);
        std::streamoff const fileSize = m2file.tellg();

        // Reject if not at least the size of the header
        if (static_cast<uint32 const>(fileSize) < sizeof(M2Header) + 4)
        {
            TC_LOG_ERROR("server.loading", "Camera file %s is damaged. File is smaller than header size", filename.string().c_str());
            m2file.close();
            continue;
        }

        // Read 4 bytes (signature)
        m2file.seekg(0, std::ios::beg);
        char fileCheck[5];
        m2file.read(fileCheck, 4);
        fileCheck[4] = '\0';

        // Check file has correct magic (MD21)
        if (strcmp(fileCheck, "MD21"))
        {
            TC_LOG_ERROR("server.loading", "Camera file %s is damaged. File identifier not found.", filename.string().c_str());
            m2file.close();
            continue;
        }

        // Now we have a good file, read it all into a vector of char's, then close the file.
        std::vector<char> buffer(fileSize);
        m2file.seekg(0, std::ios::beg);
        if (!m2file.read(buffer.data(), fileSize))
        {
            m2file.close();
            continue;
        }
        m2file.close();

        bool fileValid = true;
        uint32 m2start = 0;
        char const* ptr = buffer.data();
        while (m2start + 4 < buffer.size() && *reinterpret_cast<uint32 const*>(ptr) != '02DM')
        {
            ++m2start;
            ++ptr;
            if (m2start + sizeof(M2Header) > buffer.size())
            {
                fileValid = false;
                break;
            }
        }

        if (!fileValid)
        {
            TC_LOG_ERROR("server.loading", "Camera file %s is damaged. File is smaller than header size.", filename.string().c_str());
            continue;
        }

        // Read header
        M2Header const* header = reinterpret_cast<M2Header const*>(buffer.data() + m2start);

        if (m2start + header->ofsCameras + sizeof(M2Camera) > static_cast<uint32 const>(fileSize))
        {
            TC_LOG_ERROR("server.loading", "Camera file %s is damaged. Camera references position beyond file end", filename.string().c_str());
            continue;
        }

        // Get camera(s) - Main header, then dump them.
        M2Camera const* cam = reinterpret_cast<M2Camera const*>(buffer.data() + m2start + header->ofsCameras);
        if (!readCamera(cam, fileSize - m2start, header, cameraEntry))
            TC_LOG_ERROR("server.loading", "Camera file %s is damaged. Camera references position beyond file end", filename.string().c_str());
    }
    TC_LOG_INFO("server.loading", ">> Loaded " SZFMTD " cinematic waypoint sets in %u ms", sFlyByCameraStore.size(), GetMSTimeDiffToNow(oldMSTime));
}
예제 #6
0
/*
* private:
*/
ScenePointer SceneLoader::readScene(const QDomNode &rootNode) const {
  if (rootNode.toElement().tagName() != "scene") {
    std::cerr << "Scene parsing error: invalid root tag name, 'scene' expected" << std::endl;
    return ScenePointer(NULL);
  }

  ScenePointer scene = ScenePointer(new Scene());

  bool isCameraIntialized = false;
  bool isBackgroundMaterialInitialized = false;

  QDomElement element = rootNode.firstChildElement();
  while (!element.isNull()) {
    QString elementTagName = element.tagName();        
    
    if (elementTagName == "camera") {
      if (isCameraIntialized) {
        std::cerr << "Scene parsing error: 'camera' tag occurred twice, only one camera is allowed" << std::endl;
        return ScenePointer(NULL);
      }            
      
      CameraPointer camera = readCamera(element);           
      if (camera == NULL) {
        std::cerr << "Scene parsing error: failed camera parameters reading" << std::endl;
        return ScenePointer(NULL);
      }
      
      scene->setCamera(camera);
      isCameraIntialized = true;
    } else if (elementTagName == "light") {
      LightSourcePointer lightSource = readLightSource(element);
      if (lightSource == NULL) {
        std::cerr << "Scene parsing error: failed light source parameters reading" << std::endl;
        return ScenePointer(NULL);
      }
      scene->addLightSource(lightSource);
    } else if (elementTagName == "object") {
      ShapePointer shape = readShape(element);
      if (shape == NULL) {
        std::cerr << "Scene parsing error: failed shape parameters reading" << std::endl;
        return ScenePointer(NULL);
      }
      scene->addShape(shape);
    } else if (elementTagName == "csg") {
      CSGTreePointer csgTree = readCSGTree(element);
      if (csgTree == NULL) {
        std::cerr << "Scene parsing error: failed CSG tree parameters reading" << std::endl;
        return ScenePointer(NULL);
      }
      scene->addShape(csgTree);
    } else if (elementTagName == "background") {
      if (isBackgroundMaterialInitialized) {
        std::cerr << "Scene parsing error: 'background' tag occurred twice" << std::endl;
        return ScenePointer(NULL);
      }

      MaterialPointer material = readMaterial(element);
      if (material == NULL) {
        std::cerr << "Scene parsing error: failed background material parameters reading" << std::endl;
        return ScenePointer(NULL);
      }

      scene->setBackgroundMaterial(material);
      isBackgroundMaterialInitialized = true;
    } else {
      std::cerr << "Scene parsing error: unknown tag '" << elementTagName.toUtf8().constData() << "'" << std::endl;
      return ScenePointer(NULL);
    }

    element = element.nextSiblingElement();
  }
  
  if (!isCameraIntialized) {
    std::cerr << "Scene parsing error: camera parameters are not specified" << std::endl;
    return ScenePointer(NULL);
  }
  if (!isBackgroundMaterialInitialized) {
    std::cerr << "Scene parsing error: background material parameters are not specified" << std::endl;
    return ScenePointer(NULL);
  }

  return scene;
}
예제 #7
0
void LoadM2Cameras(std::string const& dataPath)
{
    sFlyByCameraStore.clear();

    uint32 oldMSTime = WorldTimer::getMSTime();
    for (uint32 i = 0; i < sCinematicCameraStore.GetNumRows(); ++i)
    {
        if (CinematicCameraEntry const* dbcentry = sCinematicCameraStore.LookupEntry(i))
        {
            std::string filename = dataPath;
            filename.append(dbcentry->Model);

            // Replace slashes
            std::replace(filename.begin(), filename.end(), '\\', '/');

            // Replace mdx to .m2
            size_t loc = filename.find(".mdx");
            if (loc != std::string::npos)
                filename.replace(loc, 4, ".m2");

            std::ifstream m2file(filename.c_str(), std::ios::in | std::ios::binary);
            if (!m2file.is_open())
                continue;

            // Get file size
            m2file.seekg(0, std::ios::end);
            std::streamoff const fileSize = m2file.tellg();

            // Reject if not at least the size of the header
            if (static_cast<uint32 const>(fileSize) < sizeof(M2Header))
            {
                sLog.outError("Camera file %s is damaged. File is smaller than header size", filename.c_str());
                m2file.close();
                continue;
            }

            // Read 4 bytes (signature)
            m2file.seekg(0, std::ios::beg);
            char fileCheck[5];
            m2file.read(fileCheck, 4);
            fileCheck[4] = 0;

            // Check file has correct magic (MD20)
            if (strcmp(fileCheck, "MD20"))
            {
                sLog.outError("Camera file %s is damaged. File identifier not found", filename.c_str());
                m2file.close();
                continue;
            }

            // Now we have a good file, read it all into a vector of char's, then close the file.
            std::vector<char> buffer(fileSize);
            m2file.seekg(0, std::ios::beg);
            if (!m2file.read(buffer.data(), fileSize))
            {
                m2file.close();
                continue;
            }
            m2file.close();

            // Read header
            M2Header const* header = reinterpret_cast<M2Header const*>(buffer.data());

            if (header->ofsCameras + sizeof(M2Camera) > static_cast<uint32 const>(fileSize))
            {
                sLog.outError("Camera file %s is damaged. Camera references position beyond file end (header)", filename.c_str());
                continue;
            }

            // Get camera(s) - Main header, then dump them.
            M2Camera const* cam = reinterpret_cast<M2Camera const*>(buffer.data() + header->ofsCameras);
            if (!readCamera(cam, fileSize, header, dbcentry))
                sLog.outError("Camera file %s is damaged. Camera references position beyond file end (camera)", filename.c_str());
        }
    }
    sLog.outString(">> Loaded %u cinematic waypoint sets in %u ms", static_cast<uint32 const>(sFlyByCameraStore.size()), WorldTimer::getMSTimeDiff(oldMSTime, WorldTimer::getMSTime()));
    sLog.outString();
}