Ejemplo n.º 1
0
int GzRotXMat(float degree, GzMatrix mat)
{
	// Create rotate matrix : rotate along x axis
	// Pass back the matrix using mat value
	/*GzMatrix  mat = {
	1, 0, 0, 0,
	0, cos(radian), -sin(radian), 0,
	0, sin(radian), cos(radian), 0,
	0, 0, 0, 1
	};*/
	InitGzMatrix(mat);

	float radian = (float)DEGREE_TO_RADIAN(degree);

	mat[1][1] = cos(radian);
	mat[1][2] = -sin(radian);
	mat[2][1] = sin(radian);
	mat[2][2] = cos(radian);

	return GZ_SUCCESS;
}
/**
 * Convert RA/DEC coordinates to 3D coordinates {x,y,z}:
 *   x=cos(ra)*cos(dec)
 *   y=sin(ra)*cos(dec)
 *   z=sin(dec)
 * The idea of such mapping is to change coordinate system in such way that for near stars we will have
 * |x1-x2| < e, |y1-y2| < e, |z1-z2| < e where e is some small number.
 * It will allow us to split array into chunks with fixed overlap and proceed each chunk independently (and concurrently).
 * Also it allows as to split chunk into cubes and use hash function for fast location of matched stars.
 * Looks like it is not possible to map equatorial RA/DEC coordinates to any 2D coordinates so that this requirement is satisfied.
 * So we have to use 3D.
 * @param ra right ascension (degrees)
 * @param dec declination (degrees)
 * @return z: [-1,1]
 */
static void radec2z(const Value** args, Value* res, void*)
{
    double dec = DEGREE_TO_RADIAN(args[1]->getDouble());
    double z = sin(dec);
    res->setDouble(z);
}
Ejemplo n.º 3
0
void Surface::drawLU(Vector2<int> position, Vector3<int> color, Vector2<float> scale, int rotation, float alpha, BLEND_TYPE blendType, int widthNo, int heightNo) {

	glDisable(GL_DEPTH_TEST);
	glDisable(GL_CULL_FACE);
	glDisable(GL_LIGHTING);
	glDisable(GL_LIGHT0);
	glColor4f((float)color.r/255.0f,(float)color.g/255.0f,(float)color.b/255.0f,alpha);

	//アルファブレンドのオンオフ
	//glDisable(GL_BLEND);
	glEnable(GL_BLEND);
	glAlphaFunc(GL_GEQUAL, 0.0);
	glEnable(GL_ALPHA_TEST);
	if (blendType == ALPHABLEND) {
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	//アルファブレンド
	} else if (blendType == ADDITIVE) {
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);					//加算合成
	}
	
	glPushMatrix();

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	glOrtho(0.0, getWindowWidth(), getWindowHeight(), 0.0, -1.0, 1.0);
	glBindTexture(GL_TEXTURE_2D , texture[0]);
	glEnable(GL_TEXTURE_2D);
	glBegin(GL_POLYGON);
	heightNo = heightDivideNum - heightNo;
	heightNo %= heightDivideNum;
	int x, y;
	int center_x = position.x , center_y = position.y;
	float length = 0.0f;
	//= sqrt((float)size.width*scale.x/2*(float)size.width*scale.x/2 + (float)size.height*scale.y/2*(float)size.height*scale.y/2);
	glTexCoord2f((float)((float)widthNo+1.0f)*(float)(1.0f/(float)widthDivideNum), (float)((float)heightNo-1.0f)*(float)(1.0f/(float)heightDivideNum));
	int angle = 0;
	angle = getAnglePointToPoint(center_x, center_y, center_x - size.width*scale.x/2, center_y + size.height*scale.y/2);
	x = center_x + length * cos(DEGREE_TO_RADIAN(rotation+angle));
	y = center_y + length * sin(DEGREE_TO_RADIAN(rotation+angle));
	glVertex2d(x , y);	//左上
	
	length = size.width*scale.x;
	glTexCoord2f((float)((float)widthNo    ) * (float)(1.0f/(float)widthDivideNum), (float)((float)heightNo-1.0f)*(float)(1.0f/(float)heightDivideNum));
	angle = getAnglePointToPoint(center_x, center_y, center_x + size.width*scale.x/2, center_y + size.height*scale.y/2);
	x = center_x + length * cos(DEGREE_TO_RADIAN(rotation+angle));
	y = center_y + length * sin(DEGREE_TO_RADIAN(rotation+angle));
	glVertex2d(x , y);	//右上
	
	length = sqrt((float)size.width*scale.x*(float)size.width*scale.x + (float)size.height*scale.y*(float)size.height*scale.y);
	glTexCoord2f((float)((float)widthNo    ) * (float)(1.0f/(float)widthDivideNum), (float)((float)heightNo+0.0f)*(float)(1.0f/(float)heightDivideNum));
	angle = getAnglePointToPoint(center_x, center_y, center_x + size.width*scale.x/2, center_y - size.height*scale.y/2);
	x = center_x + length * cos(DEGREE_TO_RADIAN(rotation+angle));
	y = center_y + length * sin(DEGREE_TO_RADIAN(rotation+angle));
	glVertex2d(x , y);	//右下
	
	length = size.height*scale.y;
	glTexCoord2f((float)((float)widthNo+1.0f)* (float)(1.0f/(float)widthDivideNum), (float)((float)heightNo+0.0f)*(float)(1.0f/(float)heightDivideNum));
	angle = getAnglePointToPoint(center_x, center_y, center_x - size.width*scale.x/2, center_y - size.height*scale.y/2);
	x = center_x + length * cos(DEGREE_TO_RADIAN(rotation+angle));
	y = center_y + length * sin(DEGREE_TO_RADIAN(rotation+angle));
	glVertex2d(x , y);	//左下

	glEnd();
	glDisable(GL_ALPHA_TEST);
	glDisable(GL_TEXTURE_2D);

	glPopMatrix();
	
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	
	//glViewport(0, 0, getWindowWidth(), getWindowHeight());
	//gluPerspective(30, (double)getWindowWidth()/getWindowHeight(), 1.0f, 30000.0f);
}
Ejemplo n.º 4
0
DWORD WINAPI Thread(LPVOID)
{
	while (true)
	{
		Sleep(0);
		D3DDrv = GetModuleHandle("D3DDrv");
		WinDrv = GetModuleHandle("WinDrv");
		Engine = GetModuleHandle("Engine");
		if (D3DDrv && WinDrv && Engine)
			break;
	}

	auto pattern = hook::module_pattern(D3DDrv, "C7 05 ? ? ? ? 01 00 00 00"); //0x1000CE5E
	static uint32_t* dword_1003DBA4 = *pattern.get(1).get<uint32_t*>(-4);
	static uint32_t* dword_1003DBA0 = dword_1003DBA4 - 1;
	static uint32_t* dword_1003DBC0 = *pattern.get(1).get<uint32_t*>(2);
	struct UD3DRenderDevice_SetRes_Hook
	{
		void operator()(injector::reg_pack&)
		{
			*dword_1003DBA0 = Screen.Width;
			*dword_1003DBA4 = Screen.Height;
			*dword_1003DBC0 = 1;
		}
	}; injector::MakeInline<UD3DRenderDevice_SetRes_Hook>(pattern.get(1).get<uint32_t>(0), pattern.get(1).get<uint32_t>(10));

	//HUD
	Screen.fHudOffset = (Screen.fWidth - Screen.fHeight * (4.0f / 3.0f)) / 2.0f;
	Screen.HUDScaleX = 1.0f / Screen.fWidth * (Screen.fHeight / 480.0f);
	pattern = hook::module_pattern(Engine, "D8 C9 D8 0D ? ? ? ?");
	injector::WriteMemory<float>(*pattern.get(0).get<uint32_t*>(4), Screen.HUDScaleX, true); //(DWORD)Engine + 0x1E9F78

	uint32_t pfDrawTile = injector::ReadMemory<uint32_t>((uint32_t)GetProcAddress(Engine, "?DrawTile@UCanvas@@UAEXPAVUMaterial@@MMMMMMMMMVFPlane@@1@Z") + 0x1, true) + (uint32_t)GetProcAddress(Engine, "?DrawTile@UCanvas@@UAEXPAVUMaterial@@MMMMMMMMMVFPlane@@1@Z") + 5;
	auto DrawTile = hook::range_pattern(pfDrawTile, pfDrawTile + 0x800, "8B ? 94 00 00 00 E8");
	pattern = hook::module_pattern(Engine, "8B ? 94 00 00 00 52 E8");

	injector::MakeCALL(DrawTile.get(0).get<uint32_t>(6), FCanvasUtilDrawTileHook, true); //(uint32_t)Engine + 0xC8ECE
	injector::MakeCALL(pattern.get(0).get<uint32_t>(7), FCanvasUtilDrawTileHook, true); //(uint32_t)Engine + 0xC9B7C
	injector::MakeCALL(pattern.get(1).get<uint32_t>(7), FCanvasUtilDrawTileHook, true); //(uint32_t)Engine + 0xC9DE1

	//FMV
	Screen.fFMVoffsetStartX = (Screen.fWidth - 640.0f) / 2.0f;
	Screen.fFMVoffsetStartY = (Screen.fHeight - 480.0f) / 2.0f;
	pattern = hook::module_pattern(D3DDrv, "DA ? ? 00 00 00 D8 0D");
	injector::MakeNOP(pattern.get(0).get<uint32_t>(0), 6, true);
	injector::MakeNOP(pattern.get(1).get<uint32_t>(0), 6, true);
	injector::WriteMemory<float>(*pattern.get(0).get<uint32_t*>(8), Screen.fFMVoffsetStartX * (1.0f / 640.0f), true); //(DWORD)D3DDrv + 0x31860
	injector::WriteMemory<float>(*pattern.get(1).get<uint32_t*>(8), Screen.fFMVoffsetStartY * (1.0f / 480.0f), true); //(DWORD)D3DDrv + 0x31864

	//FOV
	fDynamicScreenFieldOfViewScale = 2.0f * RADIAN_TO_DEGREE(atan(tan(DEGREE_TO_RADIAN(fScreenFieldOfViewVStd * 0.5f)) * Screen.fAspectRatio)) * (1.0f / SCREEN_FOV_HORIZONTAL);
	//uint32_t pfDraw = injector::ReadMemory<uint32_t>((uint32_t)GetProcAddress(Engine, "?Draw@UGameEngine@@UAEXPAVUViewport@@HPAEPAH@Z") + 0x1, true) + (DWORD)GetProcAddress(Engine, "?Draw@UGameEngine@@UAEXPAVUViewport@@HPAEPAH@Z") + 5;

	pattern = hook::module_pattern(Engine, "8B 46 34 8B 88 B0 02 00 00");
	struct UGameEngine_Draw_Hook
	{
		void operator()(injector::reg_pack& regs)
		{
			*(float*)&regs.ecx = *(float*)(regs.eax + 0x2B0) * fDynamicScreenFieldOfViewScale;
		}
	}; injector::MakeInline<UGameEngine_Draw_Hook>(pattern.get(0).get<uint32_t>(3)/*pfDraw + 0x104*/, pattern.get(0).get<uint32_t>(3 + 6));

	fWidescreenHudOffset = ((Screen.fHeight * (4.0f / 3.0f)) / (640.0f / fWidescreenHudOffset));
	if (Screen.fAspectRatio < (16.0f / 9.0f))
	{
		fWidescreenHudOffset = fWidescreenHudOffset / (((16.0f / 9.0f) / (Screen.fAspectRatio)) * 1.5f);
	}

	return 0;
}
Ejemplo n.º 5
0
  ////////////////////////////////////////////////////////////////////////////////////////////////////////
  //
  //
  //
  //  ReadCrystalStructureFile
  // 
  //  Note:  Units used in this file is angstrom as opposed to mm everywhere else.  This is because
  //  the actual measurement of the scattering vector is rarely used in conjunction with the geometric aspect.
  // (Typically unit vectors are used)
  //
  //////////////////////////////////////////////////////////////////////////////////////////////////////////
  bool ReadCrystalStructureFile(CUnitCell &oCell, const string &filename)
  {
    char *pBuffer = NULL;
    Size_Type nBufSize = 0;
    vector< vector<string> > vsTokens;
	
    pBuffer = ReadFileToBuf(nBufSize, filename);
    if(pBuffer == NULL){
      return false;
    }

    string sBuffStr( pBuffer, nBufSize );
    
    // RUNTIME_ASSERT(oCell.oTranslationVector.size() == 0, "Vector screwed up\n");
    GeneralLib::Tokenize( vsTokens, sBuffStr, ",# \t\n");
    RUNTIME_ASSERT( vsTokens.size() >= 4,
                   "[ReadCrystalStructureFile] ERROR: Invalid file type (too short)\n" );
	
    // parse a, b, c unit cell lengths
    RUNTIME_ASSERT( vsTokens[0].size() >= 3,
                   "[ReadCrystalStructureFile] ERROR: failed to parse a, b, c\n" );

    oCell.SetUnitCellLength(  atof( vsTokens[0][0].c_str() ),
                              atof( vsTokens[0][1].c_str() ),
                              atof( vsTokens[0][2].c_str() ) );
                              
    // parse alpha, beta, gamma unit cell angles
    RUNTIME_ASSERT(vsTokens[1].size() >= 3,
                   "[ReadCrystalStructureFile] ERROR: failed to parse alpha, beta, gamma\n");

    oCell.SetUnitCellBasisAngles( DEGREE_TO_RADIAN( atof(vsTokens[1][0].c_str()) ),
                                  DEGREE_TO_RADIAN( atof(vsTokens[1][1].c_str()) ),
                                  DEGREE_TO_RADIAN( atof(vsTokens[1][2].c_str()) )  );
    
    // parse number of basis atoms
    RUNTIME_ASSERT(vsTokens[2].size() >= 1,
                   "[ReadCrystalStructureFile] ERROR: failed to parse number of atoms \n");
    //    oCell.nNumAtoms = atoi(vsTokens[2][0].c_str());	

    oCell.SetNumAtoms( atoi( vsTokens[2][0].c_str() ) );
    
    // parse Z, number of protons in the atom, and the three coordinates
    //          of the Premitive Translation Vectors
    for(Size_Type i = 3; i < vsTokens.size(); i ++){
      
      RUNTIME_ASSERT( (vsTokens[i].size() >= 4), 
                      "[ReadCrystalStructureFile] ERROR: Invalid translation vector\n");
      CAtom pVector;		

      SVector3 oPos ( atof( vsTokens[i][1].c_str() ), 
                      atof( vsTokens[i][2].c_str() ), 
                      atof( vsTokens[i][3].c_str() ) );
      // oCell.oTranslationVector.push_back( pVector );
  
      oCell.AddAtom( atoi( vsTokens[i][0].c_str() ), oPos );
    }
	
    oCell.InitializeCoordinateSystem();

    delete [] pBuffer;
    return true;
  }
//void Init()
DWORD WINAPI Init()
{
	CIniReader iniReader("");
	res_x = iniReader.ReadInteger("MAIN", "X", 0);
	res_y = iniReader.ReadInteger("MAIN", "Y", 0);
	FOV = iniReader.ReadFloat("MAIN", "FOV", 0.0f);

	if (!res_x || !res_y) {
		HMONITOR monitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
		MONITORINFO info;
		info.cbSize = sizeof(MONITORINFO);
		GetMonitorInfo(monitor, &info);
		res_x = info.rcMonitor.right - info.rcMonitor.left;
		res_y = info.rcMonitor.bottom - info.rcMonitor.top;
	}
	//MessageBox(0, "0", "0", 0);
	//CPatch::RedirectJump(0x446B08, asm_446B08);
	CPatch::RedirectJump(0x487D6D, asm_487D6D);

	CPatch::Nop(0x48B10E, 6);
	CPatch::Nop(0x48B108, 6);

	CPatch::Nop(0x48B0BC, 6);
	CPatch::Nop(0x48B0B6, 6);

	
	CPatch::SetUInt(0x487C40 + 0x6, res_x);
	CPatch::SetUInt(0x487C4A + 0x6, res_y);

	CPatch::SetUInt(0x622B21 + 0x6, res_x);
	CPatch::SetUInt(0x622B17 + 0x6, res_y);

	CPatch::SetUInt(0x487C40 + 0x6, res_x);
	CPatch::SetUInt(0x487C4A + 0x6, res_y);

	CPatch::SetUInt(0x7716C8, res_x);
	CPatch::SetUInt(0x7716C4, res_y);

	CPatch::SetUInt(0x4D5599, res_x);
	CPatch::SetUInt(0x4D5594, res_y);


	CPatch::SetUInt(0x7A33C8, res_x);
	CPatch::SetUInt(0x7ACFB8, res_x);
	CPatch::SetUInt(0x7BB890, res_x);
	CPatch::SetUInt(0x7BCF1C, res_x);
	CPatch::SetUInt(0x7C5650, res_x);
	CPatch::SetUInt(0x7C6CCC, res_x);
	CPatch::SetUInt(0x7C8348, res_x);

	CPatch::SetUInt(0x7A33C8 - 0x4, res_y);
	CPatch::SetUInt(0x7ACFB8 - 0x4, res_y);
	CPatch::SetUInt(0x7BB890 - 0x4, res_y);
	CPatch::SetUInt(0x7BCF1C - 0x4, res_y);
	CPatch::SetUInt(0x7C5650 - 0x4, res_y);
	CPatch::SetUInt(0x7C6CCC - 0x4, res_y);
	CPatch::SetUInt(0x7C8348 - 0x4, res_y);
	

	//stretching
	CPatch::Nop(0x4152CE, 5);
	CPatch::SetFloat(0x756E50, (static_cast<float>(res_x) / static_cast<float>(res_y)));

	//FOV
	/*fScale = (0.5f *(static_cast<float>(res_x) / static_cast<float>(res_y))) / (4.0f / 3.0f);
	fScale > 1.0f ? fScale = 1.0f : fScale;
	CPatch::SetPointer(0x60121A + 0x2, &fScale);*/

	fres_x = static_cast<float>(res_x);
	fres_y = static_cast<float>(res_y);

	fAspectRatio = fres_x / fres_y;
	fDynamicScreenFieldOfViewScale = 2.0f * RADIAN_TO_DEGREE(atan(tan(DEGREE_TO_RADIAN(SCREEN_FOV_VERTICAL * 0.5f)) * fAspectRatio));
	
	if (!FOV)
	{
		CPatch::SetFloat(0x6FFF08, fDynamicScreenFieldOfViewScale);
	} else {
		CPatch::SetFloat(0x6FFF08, FOV);
	}

	//HUD
	res_x43 = static_cast<int>(res_x / (4.0f / 3.0f));

	if (iniReader.ReadInteger("MAIN", "HUD_PATCH", 0))
	{
		while (*(DWORD *)0x77166C == 0)
			Sleep(1000);

		//485246 48580A 48AFA3 cuts viewport
		CPatch::SetPointer(0x400000 + 0xE47D, &res_x43);
		CPatch::SetPointer(0x400000 + 0xE4D1, &res_x43);
		CPatch::SetPointer(0x400000 + 0xE4DB, &res_x43);
		CPatch::SetPointer(0x400000 + 0xE4FF, &res_x43);
		CPatch::SetPointer(0x400000 + 0xE52E, &res_x43);
		CPatch::SetPointer(0x400000 + 0xE53F, &res_x43);
		CPatch::SetPointer(0x400000 + 0xE54E, &res_x43);
		CPatch::SetPointer(0x400000 + 0xE55C, &res_x43);
		CPatch::SetPointer(0x400000 + 0xE5B2, &res_x43);
		CPatch::SetPointer(0x400000 + 0xE9AF, &res_x43);
		CPatch::SetPointer(0x400000 + 0xFABE, &res_x43);
		CPatch::SetPointer(0x400000 + 0xFAFA, &res_x43);
		CPatch::SetPointer(0x400000 + 0x156C0, &res_x43);
		CPatch::SetPointer(0x400000 + 0x24CF4, &res_x43);
		CPatch::SetPointer(0x400000 + 0x6BCF5, &res_x43);
		CPatch::SetPointer(0x400000 + 0x6BE92, &res_x43);
		CPatch::SetPointer(0x400000 + 0x6BED2, &res_x43);
		CPatch::SetPointer(0x400000 + 0x6BF15, &res_x43);
		CPatch::SetPointer(0x400000 + 0x6BF66, &res_x43);
		CPatch::SetPointer(0x400000 + 0x6C003, &res_x43);
		CPatch::SetPointer(0x400000 + 0x6C075, &res_x43);
		CPatch::SetPointer(0x400000 + 0x6DF1C, &res_x43);
		CPatch::SetPointer(0x400000 + 0x6E26B, &res_x43);
		CPatch::SetPointer(0x400000 + 0x6E4CB, &res_x43);
		CPatch::SetPointer(0x400000 + 0x72744, &res_x43);
		CPatch::SetPointer(0x400000 + 0x733C4, &res_x43);
		CPatch::SetPointer(0x400000 + 0x73677, &res_x43);
		CPatch::SetPointer(0x400000 + 0x73D62, &res_x43);
		CPatch::SetPointer(0x400000 + 0x798C8, &res_x43);
		CPatch::SetPointer(0x400000 + 0x7E009, &res_x43);
		CPatch::SetPointer(0x400000 + 0x7E0F0, &res_x43);
		CPatch::SetPointer(0x400000 + 0x7E4B6, &res_x43);
		CPatch::SetPointer(0x400000 + 0x7E4CC, &res_x43);
		CPatch::SetPointer(0x400000 + 0x7E7BD, &res_x43);
		CPatch::SetPointer(0x400000 + 0x7E8E8, &res_x43);
		CPatch::SetPointer(0x400000 + 0x7E921, &res_x43);
		CPatch::SetPointer(0x400000 + 0x7EA63, &res_x43);
		CPatch::SetPointer(0x400000 + 0x7EABF, &res_x43);
		CPatch::SetPointer(0x400000 + 0x7EF35, &res_x43);
		CPatch::SetPointer(0x400000 + 0x7F39E, &res_x43);
		CPatch::SetPointer(0x400000 + 0x80375, &res_x43);
		CPatch::SetPointer(0x400000 + 0x8067E, &res_x43);
		CPatch::SetPointer(0x400000 + 0x81B62, &res_x43);
		CPatch::SetPointer(0x400000 + 0x8239D, &res_x43);
		CPatch::SetPointer(0x400000 + 0x824A4, &res_x43);
		CPatch::SetPointer(0x400000 + 0x824D5, &res_x43);
		CPatch::SetPointer(0x400000 + 0x84E40, &res_x43);
		CPatch::SetPointer(0x400000 + 0x85208, &res_x43);
		CPatch::SetPointer(0x400000 + 0x879AE, &res_x43);
		CPatch::SetPointer(0x400000 + 0x8913E, &res_x43);
		CPatch::SetPointer(0x400000 + 0x90951, &res_x43);
		CPatch::SetPointer(0x400000 + 0x90B01, &res_x43);
		CPatch::SetPointer(0x400000 + 0x90C92, &res_x43);
		CPatch::SetPointer(0x400000 + 0x9B1DD, &res_x43);
		CPatch::SetPointer(0x400000 + 0xA08A3, &res_x43);
		CPatch::SetPointer(0x400000 + 0xA09CA, &res_x43);
		CPatch::SetPointer(0x400000 + 0xA45E5, &res_x43);
		CPatch::SetPointer(0x400000 + 0xA45EF, &res_x43);
		CPatch::SetPointer(0x400000 + 0xAC31A, &res_x43);
		CPatch::SetPointer(0x400000 + 0xAC551, &res_x43);
		CPatch::SetPointer(0x400000 + 0xAC5D3, &res_x43);
		CPatch::SetPointer(0x400000 + 0xAC620, &res_x43);
		CPatch::SetPointer(0x400000 + 0xAC6AF, &res_x43);
		CPatch::SetPointer(0x400000 + 0xAC954, &res_x43);
		CPatch::SetPointer(0x400000 + 0xACEBE, &res_x43);
		CPatch::SetPointer(0x400000 + 0xAD080, &res_x43);
		CPatch::SetPointer(0x400000 + 0xADC05, &res_x43);
		CPatch::SetPointer(0x400000 + 0xADE83, &res_x43);
		CPatch::SetPointer(0x400000 + 0xADFE2, &res_x43);
		CPatch::SetPointer(0x400000 + 0xAE205, &res_x43);
		CPatch::SetPointer(0x400000 + 0xAFBC1, &res_x43);
		CPatch::SetPointer(0x400000 + 0xB13C7, &res_x43);
		CPatch::SetPointer(0x400000 + 0xB1F16, &res_x43);
		CPatch::SetPointer(0x400000 + 0xBECB5, &res_x43);
		CPatch::SetPointer(0x400000 + 0xBEEF5, &res_x43);
		CPatch::SetPointer(0x400000 + 0xC1820, &res_x43);
		CPatch::SetPointer(0x400000 + 0xC3ADD, &res_x43);
		CPatch::SetPointer(0x400000 + 0xC7787, &res_x43);
		CPatch::SetPointer(0x400000 + 0xC7DDE, &res_x43);
		CPatch::SetPointer(0x400000 + 0xC8278, &res_x43);
		CPatch::SetPointer(0x400000 + 0xC8301, &res_x43);
		CPatch::SetPointer(0x400000 + 0xC8361, &res_x43);
		CPatch::SetPointer(0x400000 + 0xC850B, &res_x43);
		CPatch::SetPointer(0x400000 + 0xC89FB, &res_x43);
		CPatch::SetPointer(0x400000 + 0xC8DB4, &res_x43);
		CPatch::SetPointer(0x400000 + 0xC9138, &res_x43);
		CPatch::SetPointer(0x400000 + 0xC93A8, &res_x43);
		CPatch::SetPointer(0x400000 + 0xC9747, &res_x43);
		CPatch::SetPointer(0x400000 + 0xC97D0, &res_x43);
		CPatch::SetPointer(0x400000 + 0xC9C47, &res_x43);
		CPatch::SetPointer(0x400000 + 0xC9D0D, &res_x43);
		CPatch::SetPointer(0x400000 + 0xC9F68, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCA359, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCA45C, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCA4D5, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCA551, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCA618, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCB357, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCBD25, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCCFC2, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCCFEF, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCD16D, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCD1B1, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCD3C6, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCD3F2, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCD6EF, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCD71F, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCD9FD, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCDB3D, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCDF45, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCE249, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCE783, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCEB41, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCEFC7, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCF050, &res_x43);
		CPatch::SetPointer(0x400000 + 0xCFA67, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD1357, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD1F36, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD209B, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD2168, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD2E98, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD38C5, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD4055, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD4342, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD4775, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD4845, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD4898, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD4935, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD4A2A, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD4AF6, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD4B8E, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD4CAB, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD4CF5, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD4DEA, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD5588, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD570E, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD582E, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD59BF, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD5AFC, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD5EBF, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD6202, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD65F4, &res_x43);
		CPatch::SetPointer(0x400000 + 0xD748C, &res_x43);
		CPatch::SetPointer(0x400000 + 0xDA8EE, &res_x43);
		CPatch::SetPointer(0x400000 + 0xDA913, &res_x43);
		CPatch::SetPointer(0x400000 + 0xDABAC, &res_x43);
		CPatch::SetPointer(0x400000 + 0xDABD1, &res_x43);
		CPatch::SetPointer(0x400000 + 0xDAEDF, &res_x43);
		CPatch::SetPointer(0x400000 + 0xE16FF, &res_x43);
		CPatch::SetPointer(0x400000 + 0xEBCE7, &res_x43);
		CPatch::SetPointer(0x400000 + 0xEF53B, &res_x43);
		CPatch::SetPointer(0x400000 + 0xEF78B, &res_x43);
		CPatch::SetPointer(0x400000 + 0xEF9D7, &res_x43);
		CPatch::SetPointer(0x400000 + 0xEFBDD, &res_x43);
		CPatch::SetPointer(0x400000 + 0xEFDE7, &res_x43);
		CPatch::SetPointer(0x400000 + 0xF004A, &res_x43);
		CPatch::SetPointer(0x400000 + 0xF02DC, &res_x43);
		CPatch::SetPointer(0x400000 + 0xF153D, &res_x43);
		CPatch::SetPointer(0x400000 + 0xF175F, &res_x43);
		CPatch::SetPointer(0x400000 + 0xF196B, &res_x43);
		CPatch::SetPointer(0x400000 + 0xF1B93, &res_x43);
		CPatch::SetPointer(0x400000 + 0xF2DA5, &res_x43);
		CPatch::SetPointer(0x400000 + 0xF62CB, &res_x43);
		CPatch::SetPointer(0x400000 + 0xF8070, &res_x43);
		CPatch::SetPointer(0x400000 + 0xF8C84, &res_x43);
		CPatch::SetPointer(0x400000 + 0xFD6A8, &res_x43);
		CPatch::SetPointer(0x400000 + 0xFE7C1, &res_x43);
		CPatch::SetPointer(0x400000 + 0xFE836, &res_x43);
		CPatch::SetPointer(0x400000 + 0xFED75, &res_x43);
		CPatch::SetPointer(0x400000 + 0xFEE4C, &res_x43);
		//CPatch::SetPointer(0x400000 + 0x102167, &res_x43); Scope and black tint
		CPatch::SetPointer(0x400000 + 0x1063DC, &res_x43);
		CPatch::SetPointer(0x400000 + 0x106C96, &res_x43);
		CPatch::SetPointer(0x400000 + 0x106ED5, &res_x43);
		CPatch::SetPointer(0x400000 + 0x108F6E, &res_x43);
		CPatch::SetPointer(0x400000 + 0x10AEEB, &res_x43);
		CPatch::SetPointer(0x400000 + 0x10B2C8, &res_x43);
		CPatch::SetPointer(0x400000 + 0x10C2ED, &res_x43);
		CPatch::SetPointer(0x400000 + 0x16360C, &res_x43);
		CPatch::SetPointer(0x400000 + 0x1671D9, &res_x43);
		CPatch::SetPointer(0x400000 + 0x1672B9, &res_x43);
		CPatch::SetPointer(0x400000 + 0x167407, &res_x43);
		CPatch::SetPointer(0x400000 + 0x1674DF, &res_x43);
		CPatch::SetPointer(0x400000 + 0x17600B, &res_x43);
		CPatch::SetPointer(0x400000 + 0x1806CC, &res_x43);
		CPatch::SetPointer(0x400000 + 0x1DB9F3, &res_x43);
		CPatch::SetPointer(0x400000 + 0x1E87AC, &res_x43);
		CPatch::SetPointer(0x400000 + 0x200586, &res_x43);
		CPatch::SetPointer(0x400000 + 0x220B27, &res_x43);
		CPatch::SetPointer(0x400000 + 0x220D8E, &res_x43);
		CPatch::SetPointer(0x400000 + 0x222B23, &res_x43);
		CPatch::SetPointer(0x400000 + 0x226971, &res_x43);
		CPatch::SetPointer(0x400000 + 0x22699D, &res_x43);
		CPatch::SetPointer(0x400000 + 0x226A55, &res_x43);
		CPatch::SetPointer(0x400000 + 0x226AE8, &res_x43);
		CPatch::SetPointer(0x400000 + 0x2282C3, &res_x43);
		CPatch::SetPointer(0x400000 + 0x22A6D3, &res_x43);

	}
	return 0;
}
Ejemplo n.º 7
0
void Camera::setPerspective(const float fov,const float aspect,const float near,const float far){
	float fovr = (float)DEGREE_TO_RADIAN( fov );
	float right = tanf(fovr/2.f) * near, top = tanf(fovr/2.f) * near/aspect;
  	setPerspectiveProj( -right, -top, right, top, near, far);
}
Ejemplo n.º 8
0
//---------------------------------------------------------
//
//  Public:
//  Read
//
//
//---------------------------------------------------------
//      MIC file format
//
// line 1: a0, the fundamental lattice constant for the triangular mesh
//
// others:
//
// columns 1 -3: xyz location of left vertex of a triangle
// column 4: 1/2 for triangle type -- 1 for upward pointing or 2 for downward
// pointing
// column 5: generation number -- triangle side length = a0/(2^generation),
// generation = 0,1,2,...
// column 6: 0/1 for phase -- 0 mean it wasn't (or hasn't yet) fitted to an
// orientation, 1 means it was
// columns 7 -9: Eulers in degrees
// column 10: confidence parameter: fraction of simulated Bragg peaks that hit
// experimental peaks
//---------------------------------------------------------
bool CMic::ReadEffient( const string &filename )
{
 
  vector< vector<string> > vsTokens;

  if( !ReadFileToBuf(filename))
  {
    return false;
  }

  std::ifstream InputStream;
  if( !InputStream.open( filename ) )
    return false;


  std::string Tokens = " \t\n";
  //  GeneralLib::Tokenize( vsTokens, string( pBuffer, nBufferSize ), " \t\n");
  // we expect side length for the first line
	
  if(vsTokens[0].size() > 1){
    cerr << "[CMic::ReadMicFile] Incorrect Mic File Format " << filename << endl;
    exit(0);
  }
	
  //  fInitialSideLength = atof(vsTokens[0][0].c_str());
  //  for( Size_Type i = 1; i < vsTokens.size(); i ++){

  while()
  {
    if(vsTokens[i].size() < 9 )
    {
      cerr << "[CMic::ReadMicFile] Error: Incorrect number of columns, line: "
           << i  << filename << endl;
    }
    else
    {
      DEBUG_ALERT( vsTokens[i].size() >= 10, "CMic::Read:  Warning!  Old format MIC file with only 9 columns\n" );
      SVoxel v;

      v.nGeneration = atoi( vsTokens[i][4].c_str() );
      v.fSideLength = fInitialSideLength / pow( 2,  v.nGeneration ) ;
      v.nPhase = atoi( vsTokens[i][5].c_str() );

      Float fX, fY, fZ;

      fX = atof( vsTokens[i][0].c_str() );
      fY = atof( vsTokens[i][1].c_str() );
      fZ = atof( vsTokens[i][2].c_str() );

      if ( atoi( vsTokens[i][3].c_str() ) == UP  ) 
      {
        // Winding order, counter clockwise
        v.pVertex[0].Set( fX,                 fY, fZ );
        v.pVertex[1].Set( fX + v.fSideLength, fY, fZ );
        v.pVertex[2].Set( fX + v.fSideLength / (Float) 2.0 , fY + v.fSideLength / (Float) 2.0 * sqrt( (Float) 3.0 ) , fZ);
        v.bVoxelPointsUp = true;
      }
      else
      {
        // Winding order, counter clockwise
        v.pVertex[0].Set( fX,                 fY, fZ );
        v.pVertex[1].Set( fX + v.fSideLength / (Float) 2.0 , fY - v.fSideLength / (Float) 2.0 * sqrt( (Float) 3.0 ) , fZ);
        v.pVertex[2].Set( fX + v.fSideLength, fY, fZ );
        v.bVoxelPointsUp = false;
      }

      SVector3 oOrientation;
      oOrientation.Set(  DEGREE_TO_RADIAN( atof(vsTokens[i][6].c_str()) ),
                         DEGREE_TO_RADIAN( atof(vsTokens[i][7].c_str()) ),
                         DEGREE_TO_RADIAN( atof(vsTokens[i][8].c_str()) ) );
      
      // note that orientation matrix assigned here - the choice of active vs. passive
      // transform is made by the file format

      v.oOrientMatrix.BuildActiveEulerMatrix( oOrientation.m_fX,
                                              oOrientation.m_fY,
                                              oOrientation.m_fZ );
      
      if( vsTokens[i].size() > 9 )
        v.fConfidence = atof( vsTokens[i][9].c_str() );
      else
        v.fConfidence = 0;
      
      if( vsTokens[i].size() == 19 )   //  Defining our strain tensor to be ( I)
      {
        v.fCost                = atof( vsTokens[i][10].c_str() );
        v.fPixelOverlapRatio   = atof( vsTokens[i][11].c_str() );
        v.oDeformation.m[0][0] = atof( vsTokens[i][13].c_str() );
        v.oDeformation.m[1][1] = atof( vsTokens[i][14].c_str() );
        v.oDeformation.m[2][2] = atof( vsTokens[i][15].c_str() );
        
        v.oDeformation.m[0][1] = v.oDeformation.m[1][0] = atof( vsTokens[i][16].c_str() );
        v.oDeformation.m[1][2] = v.oDeformation.m[2][1] = atof( vsTokens[i][17].c_str() );
        v.oDeformation.m[0][2] = v.oDeformation.m[2][0] = atof( vsTokens[i][18].c_str() );
      }
      else
      {
        v.oDeformation.SetIdentity();
      }
      
      oVoxelList.push_back(v);
    }	

  }

  ClearBuffer();  // clear buffer after use
  return true;
}
Ejemplo n.º 9
0
int GzBeginRender(GzRender	*render)
{
	/*
	- set up for start of each frame - init frame buffer
	*/
	if (NULL == render)
		return GZ_FAILURE;
	GzInitDisplay(render->display);


	//render->flatcolor[RED] = 0;
	//render->flatcolor[GREEN] = 0;
	//render->flatcolor[BLUE] = 0;

	/* perspective projection xform  camera --> NDC*/
	/*GzMatrix Xpi = {
	1.0, 0.0, 0.0, 0.0,
	0.0, 1.0, 0.0, 0.0,
	0.0, 0.0, 1.0 / d, 0.0,
	0.0, 0.0, 1.0 / d, 1.0
	};*/

	InitGzMatrix(render->camera.Xpi);
	render->camera.Xpi[2][2] = 1.0 / (1.0 / tan(DEGREE_TO_RADIAN(render->camera.FOV / 2.0)));  //  1 /d
	render->camera.Xpi[3][2] = 1.0 / (1.0 / tan(DEGREE_TO_RADIAN(render->camera.FOV / 2.0)));  //  1 /d


	/*GzMatrix Xiw = {
	Xx    Xy     Xz      -X * C
	Yx    Yy     Yz      -Y * C
	Zx    Zy     Zz      -Z * C
	0     0      0        1       */
	InitGzMatrix(render->camera.Xiw);

	float norm;
	GzCoord Camera_X, Camera_Y, Camera_Z;

	//Camera_Z
	Camera_Z[X] = render->camera.lookat[X] - render->camera.position[X];
	Camera_Z[Y] = render->camera.lookat[Y] - render->camera.position[Y];
	Camera_Z[Z] = render->camera.lookat[Z] - render->camera.position[Z];

	NormalizeVector(Camera_Z);
	NormalizeVector(render->camera.worldup);

	//Camera_Y  
	// UP' = UP - (UP * Z) Z
	float sum_zaxis = (render->camera.worldup[X]) * Camera_Z[X] + (render->camera.worldup[Y]) * Camera_Z[Y] + (render->camera.worldup[Z]) * Camera_Z[Z];
	Camera_Y[X] = render->camera.worldup[X] - sum_zaxis * Camera_Z[X];
	Camera_Y[Y] = render->camera.worldup[Y] - sum_zaxis * Camera_Z[Y];
	Camera_Y[Z] = render->camera.worldup[Z] - sum_zaxis * Camera_Z[Z];

	NormalizeVector(Camera_Y);


	//Camera_X
	Camera_X[X] = Camera_Y[Y] * Camera_Z[Z] - Camera_Y[Z] * Camera_Z[Y];
	Camera_X[Y] = Camera_Y[Z] * Camera_Z[X] - Camera_Y[X] * Camera_Z[Z];
	Camera_X[Z] = Camera_Y[X] * Camera_Z[Y] - Camera_Y[Y] * Camera_Z[X];

	render->camera.Xiw[0][0] = Camera_X[X];
	render->camera.Xiw[0][1] = Camera_X[Y];
	render->camera.Xiw[0][2] = Camera_X[Z];
	render->camera.Xiw[0][3] = -(Camera_X[X] * render->camera.position[X] + Camera_X[Y] * render->camera.position[Y] + Camera_X[Z] * render->camera.position[Z]);
	render->camera.Xiw[1][0] = Camera_Y[X];
	render->camera.Xiw[1][1] = Camera_Y[Y];
	render->camera.Xiw[1][2] = Camera_Y[Z];
	render->camera.Xiw[1][3] = -(Camera_Y[X] * render->camera.position[X] + Camera_Y[Y] * render->camera.position[Y] + Camera_Y[Z] * render->camera.position[Z]);
	render->camera.Xiw[2][0] = Camera_Z[X];
	render->camera.Xiw[2][1] = Camera_Z[Y];
	render->camera.Xiw[2][2] = Camera_Z[Z];
	render->camera.Xiw[2][3] = -(Camera_Z[X] * render->camera.position[X] + Camera_Z[Y] * render->camera.position[Y] + Camera_Z[Z] * render->camera.position[Z]);

	GzPushMatrix(render, render->Xsp);            //render->matlevel[1]
	GzPushMatrix(render, render->camera.Xpi);	  //render->matlevel[2]
	GzPushMatrix(render, render->camera.Xiw);	  //render->matlevel[3]


	return GZ_SUCCESS;
}