void Weapon::SetLocation( Position& NewLocation ) { //Take a location and then offset the weapon a bit forward //of that. Yeah, its sort of inaccurate, but it seems to work. Vector3D Offset; Vector3D Offset2; if(RightHanded) { Offset.z = 0.0f; Offset.Rotatey( -NewLocation.Yaw - RADIAN(20)); Offset2.z =0.0f; Offset2.Rotatey( -NewLocation.Yaw + RADIAN(20)); } else { Offset.z = 0.0f; Offset.Rotatey( -NewLocation.Yaw + RADIAN(20)); Offset2.z = 0.0f; Offset2.Rotatey( -NewLocation.Yaw - RADIAN(20)); } Location = NewLocation ; Location.x += Offset.x; Location.z += Offset.z; SecondaryWeaponLocation = NewLocation; SecondaryWeaponLocation.x += Offset2.x; SecondaryWeaponLocation.z += Offset2.z; }
void Character::MoveByDelta ( Real ForwardDelta, Real SideDelta) { if(Health <= 0) { EquipItem(9); return; } Position NewLocation = Location; if(ForwardDelta != 0) { NewLocation.x += ( -ForwardDelta ) * (float)(*m_cos)(Location.Yaw + RADIAN(90)); NewLocation.z += ( ForwardDelta ) * (float)(*m_sin)(Location.Yaw + RADIAN(90)); } if(SideDelta != 0) { NewLocation.x += ( SideDelta ) * (float)(*m_cos)(Location.Yaw ); NewLocation.z += ( -SideDelta ) * (float)(*m_sin)(Location.Yaw ); } if(ForwardDelta !=0 || SideDelta != 0) { TargetVelocity.x = NewLocation.x - Location.x; TargetVelocity.z = NewLocation.z - Location.z; } }
void Mat4F::rotate( float p_x, float p_y, float p_z ) { float radX = (float)RADIAN(p_x); float radXSin = sinf(radX); float radXCos = cosf(radX); float radY = (float)RADIAN(p_y); float radYSin = sinf(radY); float radYCos = cosf(radY); float radZ = (float)RADIAN(p_z); float radZSin = sinf(radZ); float radZCos = cosf(radZ); Mat4F rX, rY, rZ; rX._[0][0] = 1.0f; rX._[0][1] = 0.0f; rX._[0][2] = 0.0f; rX._[0][3] = 0.0f; rX._[1][0] = 0.0f; rX._[1][1] = radXCos; rX._[1][2] = -radXSin; rX._[1][3] = 0.0f; rX._[2][0] = 0.0f; rX._[2][1] = radXSin; rX._[2][2] = radXCos; rX._[2][3] = 0.0f; rX._[3][0] = 0.0f; rX._[3][1] = 0.0f; rX._[3][2] = 0.0f; rX._[3][3] = 1.0f; rY._[0][0] = radYCos; rY._[0][1] = 0.0f; rY._[0][2] = -radYSin; rY._[0][3] = 0.0f; rY._[1][0] = 0.0f; rY._[1][1] = 1.0f; rY._[1][2] = 0.0f; rY._[1][3] = 0.0f; rY._[2][0] = radYSin; rY._[2][1] = 0.0f; rY._[2][2] = radYCos; rY._[2][3] = 0.0f; rY._[3][0] = 0.0f; rY._[3][1] = 0.0f; rY._[3][2] = 0.0f; rY._[3][3] = 1.0f; rZ._[0][0] = radZCos; rZ._[0][1] = -radZSin; rZ._[0][2] = 0.0f; rZ._[0][3] = 0.0f; rZ._[1][0] = radZSin; rZ._[1][1] = radZCos; rZ._[1][2] = 0.0f; rZ._[1][3] = 0.0f; rZ._[2][0] = 0.0f; rZ._[2][1] = 0.0f; rZ._[2][2] = 1.0f; rZ._[2][3] = 0.0f; rZ._[3][0] = 0.0f; rZ._[3][1] = 0.0f; rZ._[3][2] = 0.0f; rZ._[3][3] = 1.0f; *this = rZ * rY * rX; }
vec_t vec_rotate(vec_t a, float angle){ float sina = sinf(RADIAN(angle)); float cosa = cosf(RADIAN(angle)); return vec_new( a.x*cosa - a.y*sina , a.x*sina + a.y*cosa ); }
void SSAO::RenderSSAOPass() { mDepthTex.BindForRead(GL_TEXTURE1); mAOTex.BindForDraw(); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glUseProgram(mSSAOProg); GLint gSampler = glGetUniformLocation(mSSAOProg, "gSampler"); glUniform1i(gSampler, mDepthTex.GetTex()); GLint gSampleRad = glGetUniformLocation(mSSAOProg, "gSampleRad"); GLint gKernel = glGetUniformLocation(mSSAOProg, "gKernel"); glUniform1f(gSampleRad, mSampleRad); glUniform3fv(gKernel, MAX_KERNEL_SIZE, glm::value_ptr(mSamplePos[0])); GLint gAspect = glGetUniformLocation(mSSAOProg, "gAspect"); GLint gHalfFov = glGetUniformLocation(mSSAOProg, "gHalfFov"); GLint gProjMat = glGetUniformLocation(mSSAOProg, "gProjMat"); glUniform1f(gAspect, (GLfloat)mWidth/mHeight); glUniform1f(gHalfFov, tanf(RADIAN(45)/2)); glUniformMatrix4fv(gProjMat, 1, GL_FALSE, glm::value_ptr(gPipeline.GetProjMat())); glFrontFace(GL_CW); mQuad.Render(); glFrontFace(GL_CCW); glUseProgram(0); }
void mk23::set_stand(const fmesh::transform3d& tf) { this->_stand = tf; this->_fire_1_tf.rotate = tf.rotate * glm::angleAxis((float)RADIAN(-30), vec3(1,0,0)); }
static void compute_uvw_vectors(struct Camera *cam) { double halfu, halfv; int i; /* assumes dir and up are normalized */ VEC3_COPY(cam->wvec, cam->dir); VEC3_NORMALIZE(cam->wvec); VEC3_CROSS(cam->uvec, cam->wvec, cam->up); VEC3_NORMALIZE(cam->uvec); VEC3_CROSS(cam->vvec, cam->uvec, cam->wvec); VEC3_NORMALIZE(cam->vvec); halfv = tan(RADIAN(cam->fov/2)); halfu = halfv * cam->aspect; for (i = 0; i < 3; i++) { cam->scrn_bottom_left[i] = cam->center[i] + cam->wvec[i] - halfu * cam->uvec[i] - halfv * cam->vvec[i]; } VEC3_MUL_ASGN(cam->uvec, 2 * halfu); VEC3_MUL_ASGN(cam->vvec, 2 * halfv); }
void Screen3D::SetFieldOfView( int newFOV ) { FOV = newFOV; D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH( &matProj, RADIAN(FOV),( (float)GetWidth()/(float)GetHeight()), 0.2f, ScreenViewDepth ); D3DDevice->SetTransform( D3DTS_PROJECTION, &matProj ); }
bool Screen3D::ChangeViewDepth(Real ViewDepth) { ScreenViewDepth = ViewDepth; D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH( &matProj, RADIAN(FOV),((float)GetWidth()/(float)GetHeight()), 0.2f, ViewDepth ); D3DDevice->SetTransform( D3DTS_PROJECTION, &matProj ); return true; }
void Vec3F::rotate(float p_angle, const Vec3F& p_axis) { const float sinHalfAngle = sinf((float)RADIAN(p_angle / 2)); const float cosHalfAngle = cosf((float)RADIAN(p_angle / 2)); const float rX = p_axis.x * sinHalfAngle; const float rY = p_axis.y * sinHalfAngle; const float rZ = p_axis.z * sinHalfAngle; const float rW = cosHalfAngle; Quaternion rotationQ(rX, rY, rZ, rW); Quaternion conjugateQ = rotationQ.conjugate(); Quaternion w = rotationQ * (*this) * conjugateQ; x = w.x; y = w.y; z = w.z; }
HRESULT Dx::init() { HRESULT hr = S_FALSE; m_cogD3d = new CogD3d(*m_win); hr = m_cogD3d->init(); D3d d3d = m_cogD3d->getD3d(); if(SUCCEEDED(hr)) { ID3D11Texture2D* backbufferTex; HRESULT hr = d3d.swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backbufferTex); if(SUCCEEDED(hr)) { hr = d3d.device->CreateUnorderedAccessView(backbufferTex, NULL, &m_uavBackbuffer); } if(SUCCEEDED(hr)) { hr = d3d.device->CreateRenderTargetView(backbufferTex, NULL, &m_rtvBackbuffer); } ASSERT_RELEASE(backbufferTex); } if(SUCCEEDED(hr)) { Singleton<Ant>::get().init(d3d.device, m_win->getWidth(), m_win->getHeight()); } if(SUCCEEDED(hr)) { m_cogFx = new CogFx(); hr = m_cogFx->init(d3d.device); } if(SUCCEEDED(hr)) { m_cogCb = new CogCb(); hr = m_cogCb->init(d3d.device); CbPerInstance cbPerInstance; cbPerInstance.screenWidth = m_win->getWidth(); cbPerInstance.screenHeight = m_win->getHeight(); m_cogCb->mapCbPerInstance(d3d.devcon, cbPerInstance); } if(SUCCEEDED(hr)) { m_cogSS = new CogSS(); hr = m_cogSS->init(d3d.device); } if(SUCCEEDED(hr)) { m_cogTex = new CogTex(); hr = m_cogTex->init(d3d.device); } if(SUCCEEDED(hr)) { m_cogGeo = new CogGeo(); hr = m_cogGeo->init(d3d.device, d3d.devcon); } if(SUCCEEDED(hr)) { m_cogFov = new CogFov(m_win->getWidth(), m_win->getHeight(), (float)RADIAN(45.0f)); hr = m_cogFov->init(d3d.device, d3d.devcon); } return hr; }
int* accum_matrix_from_image_with_length(const GdkPixbuf *image, int *matrix_width, int *matrix_height) { int *matrix, width, height; int rowstride, channels, diag; guchar *pixels; int max_distance, min_distance; int max_angle, min_angle, index; int matrix_size, matr_width, matr_height; width = gdk_pixbuf_get_width(image); height = gdk_pixbuf_get_height(image); rowstride = gdk_pixbuf_get_rowstride(image); channels = gdk_pixbuf_get_n_channels(image); pixels = gdk_pixbuf_get_pixels(image); diag = round(sqrt(SQUARE(width - 1) + SQUARE(height - 1))); // diag2 = DIAG_LENGTH(width, height); // if(diag != diag2) // g_print("bad"); max_distance = MAX_DISTANCE(diag); min_distance = -max_distance; max_angle = MAX_ANGLE; min_angle = -max_angle; matr_width = max_distance * 2 + 1; //matr_height = (max_angle * 2) / ANGLE_STEP + 1; matr_height = (max_angle * 2) / ANGLE_STEP; matrix_size = matr_width * matr_height; matrix = calloc(matrix_size, sizeof (int)); for(int i = 0; i < height; ++i) for(int j = 0; j < width; ++j) { index = i * rowstride + j * channels; if(pixels[index] != 0) continue; for(int angle = min_angle; angle < max_angle/*angle <= max_angle*/; angle+= ANGLE_STEP) { float phi = RADIAN(angle, M_PI); float distance = i * sin(phi) + j * cos(phi); if(distance >= min_distance && distance <= max_distance) { index = (angle + max_angle) / ANGLE_STEP * matr_width + (distance + max_distance); matrix[index]++; } } } *matrix_width = matr_width; *matrix_height = matr_height; return matrix; }
virtual void draw() { fl_color(FL_BLACK); // draw face short centerX, centerY; float radius; centerX = w()/2; centerY = h()/2; radius = MIN(w(), h())/4; fl_pie(centerX - radius, centerY-radius, radius*2, radius*2, 0, 360); // draw hands int hourX, hourY, minuteX, minuteY, secondX, secondY; hourX = centerX + 0.35 * radius * cos(RADIAN(hourHand)); hourY = centerY + 0.35 * radius * sin(RADIAN(hourHand)); minuteX = centerX + 0.65 * radius * cos(RADIAN(minuteHand)); minuteY = centerY + 0.65 * radius * sin(RADIAN(minuteHand)); secondX = centerX + 0.85 * radius * cos(RADIAN(secondHand)); secondY = centerY + 0.85 * radius * sin(RADIAN(secondHand)); fl_color(FL_GREEN); fl_line_style(FL_SOLID, 3); fl_line(centerX, centerY, hourX, hourY); fl_line(centerX, centerY, minuteX, minuteY); fl_color(FL_RED); fl_line_style(FL_SOLID, 1); fl_line(centerX, centerY, secondX, secondY); }
double grib_nearest_distance(double radius,double lon1, double lat1, double lon2, double lat2) { double rlat1=RADIAN(lat1); double rlat2=RADIAN(lat2); double rlon1=lon1; double rlon2=lon2; double a; if (lat1 == lat2 && lon1 == lon2) { return 0.0; /* the two points are identical */ } if (rlon1 >=360) rlon1-=360.0; rlon1=RADIAN(rlon1); if (rlon2 >=360) rlon2-=360.0; rlon2=RADIAN(rlon2); a = sin(rlat1)*sin(rlat2)+ cos(rlat1)*cos(rlat2)*cos(rlon2-rlon1); if (a > 1 || a < -1 ) a=(int)a; return radius*acos(a); }
void rotate2D(t_mat2 *m, double deg) { t_mat2 rot; double rad; double s; double c; rot = mat2(); rad = RADIAN(deg); s = sin(rad); c = cos(rad); rot.m00 = c; rot.m10 = s; rot.m01 = -s; rot.m11 = c; multMat2(&rot, m); }
static void rotateZ(t_mat3 *m, double deg) { t_mat3 rot; double rad; double s; double c; rot = mat3(); rad = RADIAN(deg); s = sin(rad); c = cos(rad); rot.m00 = c; rot.m10 = s; rot.m01 = -s; rot.m11 = c; multMat3(&rot, m); }
void AvatarConstruction::OnAccelerate ( Real Force, Real SideForce, Real UpForce ) { if(!OnGround) return; if(UpForce > 0 ) { if( (timeGetTime()-LastJumpTime) < 1000 ) UpForce = 0; else LastJumpTime = timeGetTime(); } const dReal* currentSpeed = dBodyGetLinearVel( ObjectList[0].Body ); Vector3D v, v2; v.x = currentSpeed[0]; v.y = 0; v.z = currentSpeed[2]; if( UpForce != 0 ) dBodySetLinearVel( ObjectList[0].Body, v.x, UpForce, v.z ); if(Force >0 || SideForce>0 || UpForce > 0) ForceEnable= true; float m=(float)sqrt(Force*Force+SideForce*SideForce); Vector3D r ( SideForce, 0, Force ); r.Rotatey( RADIAN(-90 )); dBodySetAngularVel( ObjectList[0].Body, r.x, 0, r.z ); if( SideForce != 0 || Force != 0) Moving = true; }
void SSAO::RunLoop() { srandom(static_cast<long>(time(NULL)+getpid())); mSampleRad = 1.0; for (int i = 0; i < MAX_KERNEL_SIZE; ++i) { float scale = (float)i/ MAX_KERNEL_SIZE; float x = 2 * random() / (float)RAND_MAX - 1.0; float y = 2 * random() / (float)RAND_MAX - 1.0; float z = 2 * random() / (float)RAND_MAX - 1.0; mSamplePos[i] = glm::vec3(x, y, z); mSamplePos[i] *= (0.1 + 0.9 * scale *scale); } glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); mLight.SetLightPos(glm::vec3(-30, 150, 120)); mLight.SetCastPos(glm::vec3(10, 0, -50)); mLight.SetLightColor(glm::vec4(1, 1, 1, 1)); mLight.SetLightIntensity(1); mLight.SetAmbientColor(glm::vec4(1, 1, 1, 1)); mLight.SetAmbientIntensity(0.8); mModelMat = glm::scale(glm::mat4(1), glm::vec3(10, 10, 10)); mModelMat = glm::rotate(mModelMat, RADIAN(180), glm::vec3(0, 1, 0)); while ( !glfwWindowShouldClose(mpWindow) ) { OnRender(); glfwPollEvents(); glfwSwapBuffers(mpWindow); } glfwTerminate(); }
void BuildTreeYShape(Node *node[], Tree &tree) { const KDL::Vector unitx(1,0,0); const KDL::Vector unity(0,1,0); const KDL::Vector unitz(0,0,1); const KDL::Vector unit1(sqrt(14.0)/8.0, 1.0/8.0, 7.0/8.0); const KDL::Vector zero = KDL::Vector::Zero(); //node[0] = new Node(KDL::Vector(0.0f, -0.5f, 0.0f), unit1, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); node[0] = new Node(KDL::Vector(0.0f, -0.5f, 0.0f), unitz, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertRoot(node[0]); node[1] = new Node(KDL::Vector(0.0f, 0.4f, 0.0f), unitz, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[0], node[1]); node[2] = new Node(KDL::Vector(0.0f, 0.4f, 0.0f), unitz, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertRightSibling(node[1], node[2]); node[3] = new Node(KDL::Vector(0.5f, 1.0f, 0.0f), unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[1], node[3]); node[4] = new Node(KDL::Vector(-0.5f, 1.0f, 0.0f), unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[2], node[4]); node[5] = new Node(KDL::Vector(0.7f, 1.3f, 0.0f), unit1, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[3], node[5]); node[6] = new Node(KDL::Vector(-0.8f, 1.5f, 0.0f), unit1, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[4], node[6]); node[7] = new Node(KDL::Vector(0.7f, 2.0f, 0.0f), zero, 0.08, EFFECTOR); tree.InsertLeftChild(node[5], node[7]); node[8] = new Node(KDL::Vector(-0.8f, 1.9f, 0.0f), zero, 0.08, EFFECTOR); tree.InsertLeftChild(node[6], node[8]); }
static void compute_uv_size(struct Camera *cam) { cam->uv_size[1] = 2 * tan(RADIAN(cam->fov/2)); cam->uv_size[0] = cam->uv_size[1] * cam->aspect; }
mat4 Transform::rotateMat() { mat4 rx(1, 0, 0, 0, 0, cos(RADIAN(rotation.x)), -sin(RADIAN(rotation.x)), 0, 0, sin(RADIAN(rotation.x)), cos(RADIAN(rotation.x)), 0, 0, 0, 0, 1); mat4 ry(cos(RADIAN(rotation.y)), 0, sin(RADIAN(rotation.y)), 0, 0, 1, 0, 0, -sin(RADIAN(rotation.y)), 0, cos(RADIAN(rotation.y)), 0, 0, 0, 0, 1); mat4 rz(cos(RADIAN(rotation.z)), -sin(RADIAN(rotation.z)), 0, 0, sin(RADIAN(rotation.z)), cos(RADIAN(rotation.z)), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); return rz*ry*rx; }
bool Screen3D::Create(HWND hwnd, DisplayModeInfo& m, float viewdistance) { if( NULL == ( D3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) return false; D3DDISPLAYMODE d3ddm; if( FAILED( D3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) ) return false; hWnd = hwnd; //Get the client rectangle dimensions of the window. RECT WindowRect; GetClientRect(hwnd, &WindowRect); if( m.Width == -1 || m.Height == -1) { DisplayMode.Width = WindowRect.right - WindowRect.left; DisplayMode.Height = WindowRect.bottom - WindowRect.top; } else { DisplayMode.Width = m.Width; DisplayMode.Height = m.Height; } OutputMessage( "Attempting Resolution: %dx%d\n", DisplayMode.Width, DisplayMode.Height); // Set up the structure used to create the D3DDevice. ZeroMemory( &d3dpp, sizeof(d3dpp) ); if ( DisplayMode.Fullscreen ) { d3dpp.Windowed = FALSE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; //D3DSWAPEFFECT_COPY ; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;//D3DPRESENT_INTERVAL_ONE ; d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT ; } else { d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; } d3dpp.BackBufferWidth = DisplayMode.Width ; d3dpp.BackBufferHeight = DisplayMode.Height; d3dpp.BackBufferFormat = d3ddm.Format; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; OutputMessage( "BackBuffer: %d\n", d3ddm.Format ); //Get the depth/stencil caps //check for 32bit depth buffer if( SUCCEEDED ( D3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D32) )) { d3dpp.AutoDepthStencilFormat = D3DFMT_D32; } //second choice is 24bit buffer with 8 bit stencil else if( SUCCEEDED ( D3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24S8) )) { d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; } //third choice is 24bit buffer with 4 bit stencil else if( SUCCEEDED ( D3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X4S4) )) { d3dpp.AutoDepthStencilFormat = D3DFMT_D24X4S4; } //fourth choice is 24bit buffer with 8 bits wasted else if( SUCCEEDED ( D3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X8) )) { d3dpp.AutoDepthStencilFormat = D3DFMT_D24X8; } //fifth choice is 16bit buffer else if( SUCCEEDED ( D3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16) ) ) { d3dpp.AutoDepthStencilFormat = D3DFMT_D16; } //last choice is 15bit depth buffer with 1 bit stencil else if( SUCCEEDED ( D3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D15S1) ) ) { d3dpp.AutoDepthStencilFormat = D3DFMT_D15S1; } OutputMessage( "DepthStencil: %d\n", d3dpp.AutoDepthStencilFormat ); // Create the D3DDevice HRESULT hr; DWORD VertexFlags=0; if(true) VertexFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING; else VertexFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING; // Set default settings //UINT AdapterToUse=D3DADAPTER_DEFAULT; //D3D->GetAdapterCount()-1 //D3DDEVTYPE DeviceType=D3DDEVTYPE_HAL; //D3DDEVTYPE_REF #ifdef NVPERFHUD UINT AdapterToUse=D3D->GetAdapterCount()-1; D3DDEVTYPE DeviceType=D3DDEVTYPE_REF; #else UINT AdapterToUse=D3DADAPTER_DEFAULT; //D3D->GetAdapterCount()-1 D3DDEVTYPE DeviceType=D3DDEVTYPE_HAL; //D3DDEVTYPE_REF #endif // Look for 'NVIDIA NVPerfHUD' adapter // If it is present, override default settings for (UINT Adapter=0;Adapter<D3D->GetAdapterCount();Adapter++) { D3DADAPTER_IDENTIFIER9 Identifier; HRESULT Res; Res = D3D->GetAdapterIdentifier(Adapter,0,&Identifier); if (strcmp(Identifier.Description,"NVIDIA NVPerfHUD") == 0) { AdapterToUse=Adapter; DeviceType=D3DDEVTYPE_REF; break; } } if( FAILED( hr = D3D->CreateDevice( AdapterToUse,//D3DADAPTER_DEFAULT, DeviceType,//D3DDEVTYPE_HAL, hwnd, VertexFlags , &d3dpp, &D3DDevice ) ) ) { OutputDXError( hr, "D3D Device Init Failed "); return false; } else { //We have a mixed device, so figure out the level of T&L support D3DCAPS9 tlcaps; D3DDevice->GetDeviceCaps(&tlcaps); // initialize m_pd3dDevice before using //check the shader version if( D3DSHADER_VERSION_MAJOR( tlcaps.VertexShaderVersion ) < 1 ) TLSupport = S3D_STANDARD; //Major version is 1, so check minor versions else if(D3DSHADER_VERSION_MINOR( tlcaps.VertexShaderVersion ) < 1 ) TLSupport = S3D_VS_1_0; //Vertex shader 1.0 else TLSupport = S3D_VS_1_1; //Vertex shader 1.1 or above } //set up the projection matrix D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH( &matProj, RADIAN(60), (float)DisplayMode.Width/(float)DisplayMode.Height, 1.0f, viewdistance ); D3DDevice->SetTransform( D3DTS_PROJECTION, &matProj ); //figure out the field of view CalculateFOV(); // initial render state D3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); D3DDevice->SetRenderState( D3DRS_LIGHTING, TRUE ); D3DDevice->SetRenderState( D3DRS_ZENABLE, TRUE ); D3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); D3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); D3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); D3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); D3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); D3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); SetLinearTextureFiltering(); //init the texture manager TM.Init(this); TM.RestoreTextures(); InitialAvailableMem = D3DDevice->GetAvailableTextureMem(); //Init the font manager FM.Init( *this ); //return OK return true; }
inline void get_theta_phi(q3c_coord_t ra, q3c_coord_t dec, q3c_coord_t *theta, q3c_coord_t *phi) { *theta = M_PI_2 - RADIAN(dec); /* should be between 0 and M_PI */ *phi = RADIAN(ra); /* in theory between 0 and 2*M_PI but could wrap more than that*/ }
void BuildTreeDoubleYShape(Node *node[], Tree &tree) { const KDL::Vector unitx(1,0,0); const KDL::Vector unity(0,1,0); const KDL::Vector unitz(0,0,1); const KDL::Vector unit1(sqrt(14.0)/8.0, 1.0/8.0, 7.0/8.0); const KDL::Vector zero = KDL::Vector::Zero(); KDL::Vector p0(0.0f, -1.5f, 0.0f); KDL::Vector p1(0.0f, -1.0f, 0.0f); KDL::Vector p2(0.0f, -0.5f, 0.0f); KDL::Vector p3(0.5f*Root2Inv, -0.5+0.5*Root2Inv, 0.0f); KDL::Vector p4(0.5f*Root2Inv+0.5f*HalfRoot3, -0.5+0.5*Root2Inv+0.5f*0.5, 0.0f); KDL::Vector p5(0.5f*Root2Inv+1.0f*HalfRoot3, -0.5+0.5*Root2Inv+1.0f*0.5, 0.0f); KDL::Vector p6(0.5f*Root2Inv+1.5f*HalfRoot3, -0.5+0.5*Root2Inv+1.5f*0.5, 0.0f); KDL::Vector p7(0.5f*Root2Inv+0.5f*HalfRoot3, -0.5+0.5*Root2Inv+0.5f*HalfRoot3, 0.0f); KDL::Vector p8(0.5f*Root2Inv+1.0f*HalfRoot3, -0.5+0.5*Root2Inv+1.0f*HalfRoot3, 0.0f); KDL::Vector p9(0.5f*Root2Inv+1.5f*HalfRoot3, -0.5+0.5*Root2Inv+1.5f*HalfRoot3, 0.0f); KDL::Vector p10(-0.5f*Root2Inv, -0.5+0.5*Root2Inv, 0.0f); KDL::Vector p11(-0.5f*Root2Inv-0.5f*HalfRoot3, -0.5+0.5*Root2Inv+0.5f*HalfRoot3, 0.0f); KDL::Vector p12(-0.5f*Root2Inv-1.0f*HalfRoot3, -0.5+0.5*Root2Inv+1.0f*HalfRoot3, 0.0f); KDL::Vector p13(-0.5f*Root2Inv-1.5f*HalfRoot3, -0.5+0.5*Root2Inv+1.5f*HalfRoot3, 0.0f); KDL::Vector p14(-0.5f*Root2Inv-0.5f*HalfRoot3, -0.5+0.5*Root2Inv+0.5f*0.5, 0.0f); KDL::Vector p15(-0.5f*Root2Inv-1.0f*HalfRoot3, -0.5+0.5*Root2Inv+1.0f*0.5, 0.0f); KDL::Vector p16(-0.5f*Root2Inv-1.5f*HalfRoot3, -0.5+0.5*Root2Inv+1.5f*0.5, 0.0f); node[0] = new Node(p0, unit1, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertRoot(node[0]); node[1] = new Node(p1, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[0], node[1]); node[2] = new Node(p1, unitz, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[1], node[2]); node[3] = new Node(p2, unitz, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[2], node[3]); node[4] = new Node(p2, unitz, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertRightSibling(node[3], node[4]); node[5] = new Node(p3, unity, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[3], node[5]); node[6] = new Node(p3, unity, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertRightSibling(node[5], node[6]); node[7] = new Node(p3, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[5], node[7]); node[8] = new Node(p4, unitz, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[7], node[8]); node[9] = new Node(p5, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[8], node[9]); node[10] = new Node(p5, unity, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[9], node[10]); node[11] = new Node(p6, zero, 0.08, EFFECTOR); tree.InsertLeftChild(node[10], node[11]); node[12] = new Node(p3, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[6], node[12]); node[13] = new Node(p7, unitz, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[12], node[13]); node[14] = new Node(p8, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[13], node[14]); node[15] = new Node(p8, unity, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[14], node[15]); node[16] = new Node(p9, zero, 0.08, EFFECTOR); tree.InsertLeftChild(node[15], node[16]); node[17] = new Node(p10, unity, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[4], node[17]); node[18] = new Node(p10, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[17], node[18]); node[19] = new Node(p10, unity, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertRightSibling(node[17], node[19]); node[20] = new Node(p11, unitz, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[18], node[20]); node[21] = new Node(p12, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[20], node[21]); node[22] = new Node(p12, unity, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[21], node[22]); node[23] = new Node(p13, zero, 0.08, EFFECTOR); tree.InsertLeftChild(node[22], node[23]); node[24] = new Node(p10, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[19], node[24]); node[25] = new Node(p14, unitz, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[24], node[25]); node[26] = new Node(p15, unitx, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[25], node[26]); node[27] = new Node(p15, unity, 0.08, JOINT, RADIAN(-180.), RADIAN(180.), RADIAN(30.)); tree.InsertLeftChild(node[26], node[27]); node[28] = new Node(p16, zero, 0.08, EFFECTOR); tree.InsertLeftChild(node[27], node[28]); }
void rotate(u8** image, BMP_HEADER* p_header, u8* color_buf, int width, int height) { char char_test; int i, j, flag_rotate; float angle, x, y; printf("Give a rotate angle (whatever >0 or <0)\n"); scanf("%f", &angle); while ((char_test = getchar()) != '\n' && char_test != EOF) ; printf("Choose one algorithm\n" "[a] -> adjacent pixel\n" "[b] -> bilinear interposition\n"); __asm__ __volatile__("5:"); while ((char_test = getchar()) != '\n' && char_test != EOF) { flag_rotate = char_test; /* not *++bp, bp is a global-var */ *bp = '\n'; } switch (flag_rotate) { case 'b': flag_rotate = 1; break; case 'a': flag_rotate = 0; break; default: printf("Hey bro, type 'a' or 'b'\n"); __asm__ __volatile__("jmp 5b"); break; } float radian = RADIAN(angle); float sina = sin(radian); float cosa = cos(radian); /* * y Original Image -- regard (x1, y1) as (0, 0) * * ^ * | * | * | * | * |(x2, y2) (x4, y4) * .................................. * . . * . . * . . * . . * . . * .(x1, y1) -- axis . (x3, y3) * ..................................----------> x */ /* after anti-clock-wise rotation */ float x1 = 0; float x2 = 0 - height * sina; float x3 = 0 + width * cosa; float x4 = 0 + width * cosa - height * sina; float y1 = 0; float y2 = 0 + height * cosa; float y3 = 0 + width * sina; float y4 = 0 + width * sina + height * cosa; /* * make sure that the image always locate * in active-x-axis'n active-y-axis * so we need to know how far they get away */ float x_offset = MAX(MAX(-x2, -x3), -x4); float y_offset = MAX(MAX(-y2, -y3), -y4); x_offset = x_offset > 0 ? x_offset : 0; y_offset = y_offset > 0 ? y_offset : 0; int width_new = ceil(MAX(fabs(x1 - x4), fabs(x2 - x3))); int height_new = ceil(MAX(fabs(y1 - y4), fabs(y2 - y3))); u8* image_new[height_new]; /* fill up */ width_pad(&width_new); /* everything for making a new image has done, now calloc */ calloc_buf(image_new, width_new, height_new); /* control every pixels in image new, not image original */ for (i = 0; i < height_new; i++) { for (j = 0; j < width_new; j++) { /* it's image new here, so clock-wise */ x = ( (j - x_offset) * cosa + (i - y_offset) * sina); y = (- (j - x_offset) * sina + (i - y_offset) * cosa); /* * if the pixel in image new has the corresponding pixel in * image original, we evaluate it, other wise, next one */ /* no equals */ if (y >= 0 && y < height && x >= 0 && x < width) { image_new[i][j] = flag_rotate ? \ bilinear_interposition(image, x, y, width, height) : \ image[(int)y][(int)x]; } } } if (write_bmp_calloc(image_new, color_buf, width_new, height_new, p_header)) { printf("Sorry, Failure!\n"); exit(EXIT_FAILURE); } free_buf(image_new, width_new, height_new); printf("\nRotate Done!\tWhat's more?\n"); }