double traceBullet(double initSpeed, double airFriction, double angle, double angleTarget, double distance) { double velX, velY, posX, posY, lastPosX, lastPosY, posTargetX, posTargetY, velMag; velX = cos(RADIANS(angle)) * initSpeed; velY = sin(RADIANS(angle)) * initSpeed; posX = 0; posY = 0; posTargetX = cos(RADIANS(angleTarget)) * distance; posTargetY = sin(RADIANS(angleTarget)) * distance; double simulationStep = 0.05; int i = 0; while (i < MAXITERATIONS) { lastPosX = posX; lastPosY = posY; velMag = sqrt(pow(velX, 2) + pow(velY, 2)); posX += velX * simulationStep * 0.5; posY += velY * simulationStep * 0.5; velX += simulationStep * (velX * velMag * airFriction); velY += simulationStep * (velY * velMag * airFriction - 9.80665); posX += velX * simulationStep * 0.5; posY += velY * simulationStep * 0.5; if (posX >= posTargetX) { break; } i++; } double coef = (posTargetX - lastPosX) / (posX - lastPosX); return (lastPosY + (posY - lastPosY) * coef) - posTargetY; }
int albers_conic_equal_area_ellipsoid(mapx_class *current, double lat, double lon, double *x, double *y) { double phi, lam, sin_phi, rho, theta, q; phi = RADIANS(lat); lam = RADIANS(lon - current->lon0); sin_phi = sin(phi); if (0 == current->eccentricity) q = 2 * sin_phi; else q = (1-current->e2) * ( ( sin_phi / (1 - (current->e2 * sin_phi * sin_phi)) ) - ( log( (1 - (current->eccentricity*sin_phi)) / (1 + (current->eccentricity*sin_phi)) ) / (2*current->eccentricity) ) ); rho = (current->Rg / current->n) * sqrt(current->C - (current->n*q)); theta = current->n * lam; *x = rho * sin(theta); *y = current->rho0 - (rho * cos(theta)); *x += current->false_easting; *y += current->false_northing; return 0; }
Observer::Observer(const char *nm, double lat, double lng, double hgt) { this->name = nm ; LA = RADIANS(lat) ; LO = RADIANS(lng) ; HT = hgt / 1000 ; U[0] = cos(LA)*cos(LO) ; U[1] = cos(LA)*sin(LO) ; U[2] = sin(LA) ; E[0] = -sin(LO) ; E[1] = cos(LO) ; E[2] = 0. ; N[0] = -sin(LA)*cos(LO) ; N[1] = -sin(LA)*sin(LO) ; N[2] = cos(LA) ; double RP = RE * (1 - FL) ; double XX = RE * RE ; double ZZ = RP * RP ; double D = sqrt(XX*cos(LA)*cos(LA) + ZZ*sin(LA)*sin(LA)) ; double Rx = XX / D + HT ; double Rz = ZZ / D + HT ; O[0] = Rx * U[0] ; O[1] = Rx * U[1] ; O[2] = Rz * U[2] ; V[0] = -O[1] * W0 ; V[1] = O[0] * W0 ; V[2] = 0 ; }
int mollweide(mapx_class *current, double lat, double lon, double *x, double *y) { double dlon; double phi, lam, theta, delta; double sin_theta, cos_theta, psi, epsilon=1e-6; int it, maxit=10; dlon = lon - current->lon0; NORMALIZE(dlon); phi = RADIANS (lat); lam = RADIANS (dlon); delta = 0.0; theta = phi; sin_theta = sin(theta); cos_theta = cos(theta); if (fabs(cos_theta) > epsilon) { psi = PI*sin(phi); it = 0; repeat { delta = -(theta + sin_theta - psi) / (1 + cos_theta); theta += delta; sin_theta = sin(theta); cos_theta = cos(theta); if (++it >= maxit) break; } until (fabs(delta) <= epsilon); theta /= 2.0; sin_theta = sin(theta); cos_theta = cos(theta); }
int main(int argc, char *argv[]) { char **av, *in_fname, *out_fname ; int ac, nargs ; MRI_SURFACE *mris ; float alpha, beta, gamma ; /* rkt: check for and handle version tag */ nargs = handle_version_option (argc, argv, "$Id: mris_rotate.c,v 1.6 2011/03/02 00:04:33 nicks Exp $", "$Name: stable5 $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; Progname = argv[0] ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; ac = argc ; av = argv ; for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++) { nargs = get_option(argc, argv) ; argc -= nargs ; argv += nargs ; } if (argc < 6) usage_exit() ; in_fname = argv[1] ; if (sscanf(argv[2], "%f", &alpha) != 1) ErrorExit(ERROR_BADPARM, "%s: could not scan alpha from %s", Progname, argv[2]) ; if (sscanf(argv[3], "%f", &beta) != 1) ErrorExit(ERROR_BADPARM, "%s: could not scan beta from %s", Progname, argv[3]) ; if (sscanf(argv[4], "%f", &gamma) != 1) ErrorExit(ERROR_BADPARM, "%s: could not scan gamma from %s", Progname, argv[4]) ; out_fname = argv[5] ; mris = MRISfastRead(in_fname) ; if (!mris) ErrorExit(ERROR_NOFILE, "%s: could not read surface file %s", Progname, in_fname) ; alpha = RADIANS(alpha) ; beta = RADIANS(beta) ; gamma = RADIANS(gamma) ; MRIScenter(mris, mris) ; MRISrotate(mris, mris, alpha, beta, gamma) ; if (!mris) ErrorExit(ERROR_NOFILE, "%s: could not rotate surface", Progname) ; if (Gdiag & DIAG_SHOW) fprintf(stderr, "writing rotated surface to %s\n", out_fname) ; MRISwrite(mris, out_fname) ; exit(0) ; return(0) ; /* for ansi */ }
// Démarrage de la scène void SceneSimple::Reset() { // On peut par exemple remettre la caméra à une position donnée : Camera& cam = Camera::getInstance(); cam.setEye(vec3(10.0f, 0.0f, 10.0f)); cam.setAngle(RADIANS(225.f), RADIANS(90.f)); }
int init_albers_conic_equal_area_ellipsoid(mapx_class *current) { current->Rg = current->equatorial_radius / current->scale; current->sin_phi0 = sin(RADIANS(current->center_lat)); current->sin_phi1 = sin(RADIANS(current->lat0)); current->sin_phi2 = sin(RADIANS(current->lat1)); current->cos_phi1 = cos(RADIANS(current->lat0)); current->cos_phi2 = cos(RADIANS(current->lat1)); current->m1 = current->cos_phi1 / sqrt(1 - (current->e2 * current->sin_phi1 * current->sin_phi1)); current->m2 = current->cos_phi2 / sqrt(1 - (current->e2 * current->sin_phi2 * current->sin_phi2)); if (0 == current->eccentricity) { current->q0 = 2 * current->sin_phi0; current->q1 = 2 * current->sin_phi1; current->q2 = 2 * current->sin_phi2; } else { current->q0 = (1-current->e2) * ( ( current->sin_phi0 / (1 - (current->e2 * current->sin_phi0 * current->sin_phi0)) ) - ( log( (1 - (current->eccentricity*current->sin_phi0)) / (1 + (current->eccentricity*current->sin_phi0)) ) / (2*current->eccentricity) ) ); current->q1 = (1-current->e2) * ( ( current->sin_phi1 / (1 - (current->e2 * current->sin_phi1 * current->sin_phi1)) ) - ( log( (1 - (current->eccentricity*current->sin_phi1)) / (1 + (current->eccentricity*current->sin_phi1)) ) / (2*current->eccentricity) ) ); current->q2 = (1-current->e2) * ( ( current->sin_phi2 / (1 - (current->e2 * current->sin_phi2 * current->sin_phi2)) ) - ( log( (1 - (current->eccentricity*current->sin_phi2)) / (1 + (current->eccentricity*current->sin_phi2)) ) / (2*current->eccentricity) ) ); } if (999 == current->lat1 || current->lat0 == current->lat1) current->n = current->sin_phi1; else current->n = ( (current->m1*current->m1) - (current->m2*current->m2) ) / (current->q2 - current->q1); current->C = (current->m1*current->m1) + (current->n*current->q1); current->rho0 = (current->Rg / current->n) * sqrt(current->C - (current->n*current->q0)); return 0; }
void ExtObject::UpdateInfoBox() { info.angle=DEGREES(atan2(end.y-start.y,end.x-start.x)); info.x = start.x+((line_width/2)*cos(RADIANS(info.angle-90))); info.y = start.y+((line_width/2)*sin(RADIANS(info.angle-90))); info.w = sqrt(pow(end.x-start.x,2)+pow(end.y-start.y,2)); info.h = line_width; UpdateBoundingBox(); }
void CGeometry::Motion(D3DVECTOR &Position,D3DVECTOR &Angle,float Speed) { D3DVECTOR RadAngle; RadAngle.x=RADIANS(Angle.x); RadAngle.y=RADIANS(Angle.y); RadAngle.z=RADIANS(Angle.z); Position.z+=( ((float)cos(RadAngle.y)) * ((float)cos(RadAngle.x)) ) * Speed; Position.x+=( ((float)sin(RadAngle.y)) * ((float)cos(RadAngle.x)) ) * Speed; Position.y+=-((float)sin(RadAngle.x)) * Speed; }
int init_cylindrical_equidistant(mapx_class *current) { if (current->lat1 == 999) current->lat1 = 0.00; current->cos_phi1 = cos (RADIANS (current->lat1)); return 0; }
void make_plant( float *data, float ao, float light, float px, float py, float pz, float n, int w, float rotation) { static const float positions[4][4][3] = { {{ 0, -1, -1}, { 0, -1, +1}, { 0, +1, -1}, { 0, +1, +1}}, {{ 0, -1, -1}, { 0, -1, +1}, { 0, +1, -1}, { 0, +1, +1}}, {{-1, -1, 0}, {-1, +1, 0}, {+1, -1, 0}, {+1, +1, 0}}, {{-1, -1, 0}, {-1, +1, 0}, {+1, -1, 0}, {+1, +1, 0}} }; static const float normals[4][3] = { {-1, 0, 0}, {+1, 0, 0}, {0, 0, -1}, {0, 0, +1} }; static const float uvs[4][4][2] = { {{0, 0}, {1, 0}, {0, 1}, {1, 1}}, {{1, 0}, {0, 0}, {1, 1}, {0, 1}}, {{0, 0}, {0, 1}, {1, 0}, {1, 1}}, {{1, 0}, {1, 1}, {0, 0}, {0, 1}} }; static const float indices[4][6] = { {0, 3, 2, 0, 1, 3}, {0, 3, 1, 0, 2, 3}, {0, 3, 2, 0, 1, 3}, {0, 3, 1, 0, 2, 3} }; float *d = data; float s = 0.0625; float a = 0; float b = s; struct item_list *plant = get_item_by_id(ABS(w)); float du = (plant->tile->sprite % 16) * s; float dv = (plant->tile->sprite / 16) * s; for (int i = 0; i < 4; i++) { for (int v = 0; v < 6; v++) { int j = indices[i][v]; *(d++) = n * positions[i][j][0]; *(d++) = n * positions[i][j][1]; *(d++) = n * positions[i][j][2]; *(d++) = normals[i][0]; *(d++) = normals[i][1]; *(d++) = normals[i][2]; *(d++) = du + (uvs[i][j][0] ? b : a); *(d++) = dv + (uvs[i][j][1] ? b : a); *(d++) = ao; *(d++) = light; } } float ma[16]; float mb[16]; mat_identity(ma); mat_rotate(mb, 0, 1, 0, RADIANS(rotation)); mat_multiply(ma, mb, ma); mat_apply(data, ma, 24, 3, 10); mat_translate(mb, px, py, pz); mat_multiply(ma, mb, ma); mat_apply(data, ma, 24, 0, 10); }
void display() { float fov = RADIANS(70.0); float aspect = (float)W_WIDTH / (float)W_HEIGHT; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); projection = glm::perspective(fov, aspect, 0.1f, 100.0f); camera.viewMatrix(view); lightPos = glm::vec4(1, 0, 1, 0); lightDiff = glm::vec4(0.8, 0.8, 0.8, 1); lightSpec = glm::vec4(1, 1, 1, 0); glUniformMatrix4fv(uProjection, 1, GL_FALSE, &projection[0][0]); glUniformMatrix4fv(uView, 1, GL_FALSE, &view[0][0]); glUniform4fv(uLightPos, 1, &lightPos[0]); glUniform4fv(uLightDiff, 1, &lightDiff[0]); glUniform4fv(uLightSpec, 1, &lightSpec[0]); glUniform3fv(uCameraPosition, 1, &(camera.position)[0]); obj.rotation[2] = (float)timer / 5000.0; obj.draw(programID, projection * view, uModel); glutSwapBuffers(); }
int main( int argc, char *argv[] ) { gdouble max_area = 0.0001; gdouble min_angle = RADIANS(15.0); guint niter = 10; Polygon *p = polygon_create_box( 0.0, 0.0, 1.0, 1.0 ); /* Polygon *p = polygon_create_island(); */ /* Polygon *p = polygon_create_A(); */ /* ELEMENT QUALITY SMOOTHING */ Mesh * mesh = mesh_triangulate_polygon( p ); mesh_make_cdt_by_edge_flipping( mesh ); polygon_free( p ); mesh_refine( mesh, RUPPERT_REFINEMENT, max_area, min_angle ); mesh_relax( mesh ); mesh_smooth( mesh, ELEMENT_QUALITY_SMOOTHING, niter, max_area ); mesh_relax( mesh ); mesh_smooth( mesh, ELEMENT_QUALITY_SMOOTHING, niter, max_area ); mesh_save_to_eps( "mesh.eps", mesh ); mesh_save_to_obj( "mesh.obj", mesh ); mesh_free( mesh ); return EXIT_SUCCESS; }
Vector3f Vector3f::rotate(float angle, Vector3f axis) { float sinHalfAngle = sinf(RADIANS(angle / 2.0f)); float cosHalfAngle = cosf(RADIANS(angle / 2.0f)); float rX = axis.x * sinHalfAngle; float rY = axis.y * sinHalfAngle; float rZ = axis.z * sinHalfAngle; float rW = cosHalfAngle; Quaternion rotation = Quaternion(rX, rY, rZ, rW); Quaternion conjugate = rotation.conjugated(); Quaternion r = rotation * (*this) * conjugate; return Vector3f(r.x, r.y, r.z); }
void SceneTerrain::Init() { ResourceManager& res = ResourceManager::getInstance(); VarManager& var = VarManager::getInstance(); m_vSunAngle = vec2(0.0f, RADIANS(45.0f)); m_pSkybox = (TextureCubemap*)res.LoadResource(ResourceManager::TEXTURECUBEMAP, "sand_up.jpg sand_dn.jpg sand_tp.jpg sand_bm.jpg sand_lt.jpg sand_rt.jpg"); m_pShaderLighting = (Shader*)res.LoadResource(ResourceManager::SHADER, "lighting"); m_pShaderTerrain = (Shader*)res.LoadResource(ResourceManager::SHADER, "terrain_ground"); m_pShaderWater = (Shader*)res.LoadResource(ResourceManager::SHADER, "terrain_water"); m_pShaderGrass = (Shader*)res.LoadResource(ResourceManager::SHADER, "terrain_grass"); m_pShaderTree = (Shader*)res.LoadResource(ResourceManager::SHADER, "terrain_tree"); res.LoadResource(ResourceManager::MESH, "terrain_house.obj"); res.LoadResource(ResourceManager::TEXTURE2D, "wall_diffuse.jpg"); res.LoadResource(ResourceManager::TEXTURE2D, "wall_NM_height.tga"); m_tTextures.push_back( (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "terrain_detail_NM.tga") ); m_tTextures.push_back( (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "sandfloor009a.jpg") ); m_tTextures.push_back( (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "terrain_rocky_map_1024.png") ); m_tTextures.push_back( (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "terrain_grass_map_1024.png") ); m_tTextures.push_back( (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "terrain_water_caustics.jpg") ); res.LoadResource(ResourceManager::TEXTURE2D, "grass_billboards.tga"); res.LoadResource(ResourceManager::TEXTURE2D, "palm_texture.tga"); m_pTexWaterNoiseNM = (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "terrain_water_NM.jpg"); m_pTerrainDiffuseMap = (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "test_heightmap512_2_diffusemap.jpg"); var.set("water_height", 4.2f); m_pTerrain = new Terrain(); assert(m_pTerrain != NULL); //BoundingBox bbox( vec3(-300.0f, 0.0f, -300.0f), vec3(300.0f, 50.0f, 300.0f) ); BoundingBox bbox( vec3(-300.0f, 0.0f, -300.0f), vec3(300.0f, 40.0f, 300.0f) ); // m_pTerrain->Load("test_heightmap1024_2.jpg", bbox, 32); m_pTerrain->Load("test_heightmap512_2.jpg", bbox, 16); ImageTools::ImageData img; ImageTools::OpenImage("test_heightmap512_2_diffusemap.jpg", img); m_pTerrain->GenerateGrass(img, 200000); m_pTerrain->GenerateVegetation(img, 100); m_pTerrain->ComputeBoundingBox(); img.Destroy(); Reload(); // set shader constants m_fboWaterReflection.Create(FrameBufferObject::FBO_2D_COLOR, 512, 512); m_fboDepthMapFromLight[0].Create(FrameBufferObject::FBO_2D_DEPTH, 2048, 2048); m_fboDepthMapFromLight[1].Create(FrameBufferObject::FBO_2D_DEPTH, 2048, 2048); LoadCameraTrajFromFile("terrain.txt"); }
static void _turrets(SDLData* d, XShip* s) { unsigned u; for (u = 0; u < 8; ++u) { s->turret_anim[u] = SDLazy_AnimCreate(d->srf_ship[SRF_SHIP_TURRET], 7, 7, ANIM_PAUSE); SDLazy_SetCenter(s->turret_anim[u], v2f_(10.5, 34)); } SDLazy_SetScaleX (s->turret_anim[1], -1); SDLazy_SetRot (s->turret_anim[2], RADIANS(+90)); SDLazy_SetRot (s->turret_anim[3], RADIANS(+90)); SDLazy_SetScaleX (s->turret_anim[3], -1); SDLazy_SetScale (s->turret_anim[4], v2f_(-1, -1)); SDLazy_SetScaleY (s->turret_anim[5], -1); SDLazy_SetRot (s->turret_anim[6], RADIANS(-90)); SDLazy_SetRot (s->turret_anim[7], RADIANS(-90)); SDLazy_SetScaleX (s->turret_anim[7], -1); }
int init_albers_conic_equal_area(mapx_class *current) { current->sin_phi0 = sin(RADIANS(current->center_lat)); current->sin_phi1 = sin(RADIANS(current->lat0)); current->cos_phi1 = cos(RADIANS (current->lat0)); if (999 == current->lat1 || current->lat0 == current->lat1) current->n = current->sin_phi1; else current->n = (current->sin_phi1 + sin(RADIANS(current->lat1)))/2; current->C = (current->cos_phi1*current->cos_phi1 + 2*current->n*current->sin_phi1); current->rho0 = current->Rg*sqrt(current->C - 2*current->n*current->sin_phi0)/current->n; return 0; }
float RotateTowards(float start, float end, float step) { float cs = cos(RADIANS(start)); float ce = cos(RADIANS(end)); float ss = sin(RADIANS(start)); float se = sin(RADIANS(end)); float z = cs*se - ss*ce; float dot = cs*ce + ss*se; float angle = DEGREES(acos(dot)); if(angle > step) if(z > 0) return start + step; else return start - step; else return end; }
/*------------------------------------------------------------------------ Parameters: Description: Return Values: nothing. ------------------------------------------------------------------------*/ int QuadEqual(double a1, double a2) { a1 = normAngle(a1) ; a2 = normAngle(a2) ; if (fabs(a1 - a2) < RADIANS(90.0)) return(1) ; else return(0) ; }
Character *Character::SyncDummy() { Dummy->setWorldTransform(RigidBody->getGhostObject()->getWorldTransform()); btTransform armTranslation; armTranslation.setIdentity(); armTranslation.setOrigin(btVector3(0,-0.08f,0)); btTransform armRotation; armRotation.setIdentity(); armRotation.setRotation(btQuaternion(BVEC3F(0,1,0),RADIANS(180))); Arms->RigidBody->setWorldTransform(armTranslation * RigidBody->getGhostObject()->getWorldTransform() * armRotation); return this; }
int albers_conic_equal_area(mapx_class *current, double lat, double lon, double *x, double *y) { double phi, lam, sin_phi, rho, theta; phi = RADIANS(lat); lam = RADIANS(lon - current->lon0); sin_phi = sin(phi); rho = current->Rg*sqrt(current->C - 2*current->n*sin_phi)/current->n; theta = current->n*lam; *x = rho*sin(theta); *y = current->rho0 - rho*cos(theta); *x += current->false_easting; *y += current->false_northing; return 0; }
int cylindrical_equidistant (mapx_class *current, double lat, double lon, double *x, double *y) { double dlon; double phi, lam; dlon = lon - current->lon0; NORMALIZE(dlon); phi = RADIANS (lat); lam = RADIANS (dlon); *x = current->Rg * lam * current->cos_phi1; *y = current->Rg * phi; *x += current->false_easting; *y += current->false_northing; return 0; }
void Satellite::tle(const char *nm, const char *l1, const char *l2) { name = nm ; // direct quantities from the orbital elements N = getlong(l2, 2, 7) ; YE = getlong(l1, 18, 20) ; if (YE < 58) YE += 2000 ; else YE += 1900 ; TE = getdouble(l1, 20, 32) ; M2 = RADIANS(getdouble(l1, 33, 43)) ; IN = RADIANS(getdouble(l2, 8, 16)) ; RA = RADIANS(getdouble(l2, 17, 25)) ; EC = getdouble(l2, 26, 33)/1e7f ; WP = RADIANS(getdouble(l2, 34, 42)) ; MA = RADIANS(getdouble(l2, 43, 51)) ; MM = 2.0f * M_PI * getdouble(l2, 52, 63) ; RV = getlong(l2, 63, 68) ; // derived quantities from the orbital elements // convert TE to DE and TE DE = fnday(YE, 1, 0) + (long) TE ; TE -= (long) TE ; N0 = MM/86400 ; A_0 = pow(GM/(N0*N0), 1./3.) ; B_0 = A_0*sqrt(1.-EC*EC) ; PC = RE*A_0/(B_0*B_0) ; PC = 1.5f*J2*PC*PC*MM ; double CI = cos(IN) ; QD = -PC*CI ; WD = PC*(5*CI*CI-1)/2 ; DC = -2*M2/(3*MM) ; }
/** * Morgan SCARA Forward Kinematics. Results in cartes[]. * Maths and first version by QHARLEY. * Integrated into Marlin and slightly restructured by Joachim Cerny. */ void forward_kinematics_SCARA(const float &a, const float &b) { const float a_sin = sin(RADIANS(a)) * L1, a_cos = cos(RADIANS(a)) * L1, b_sin = sin(RADIANS(b)) * L2, b_cos = cos(RADIANS(b)) * L2; cartes[X_AXIS] = a_cos + b_cos + SCARA_OFFSET_X; //theta cartes[Y_AXIS] = a_sin + b_sin + SCARA_OFFSET_Y; //theta+phi /* SERIAL_ECHOLNPAIR( "SCARA FK Angle a=", a, " b=", b, " a_sin=", a_sin, " a_cos=", a_cos, " b_sin=", b_sin, " b_cos=", b_cos ); SERIAL_ECHOLNPAIR(" cartes (X,Y) = "(cartes[X_AXIS], ", ", cartes[Y_AXIS], ")"); //*/ }
Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips"; #endif /* Authors: Charlie Gunn, Pat Hanrahan, Stuart Levy, Tamara Munzner, Mark Phillips */ #include <stdio.h> #include <math.h> #include "radians.h" #include "transform3.h" #include "ooglutil.h" /* For OOGLError() */ /* * * ( cot(fov/2)/aspect 0 0 0 ) * ( 0 cot(fov/2) 0 0 ) * T = ( 0 0 -(f+n)/(f-n) -1 ) * ( 0 0 -2*f*n/(f-n) 0 ) * * Transform to the unit cube. Also flip from rh to lh. */ void Tm3PerspectiveFOV( Transform3 T, float fov, float aspect, float n, float f ) { float cotfov; Tm3Identity( T ); if( n == f ) { OOGLError(1/*UserError*/, "Tm3Perspective: n and f must be different" ); return; } if( fov == 0. ) { OOGLError(1/*UserError*/, "Tm3Perspective: fov must not equal 0" ); return; } cotfov = tan( RADIANS(fov)/2.0 ); if( cotfov != 0. ) cotfov = 1. / cotfov; T[TMX][TMX] = cotfov/aspect; T[TMY][TMY] = cotfov; T[TMZ][TMZ] = -2*(f+n)/(f-n); T[TMW][TMZ] = -2*f*n/(f-n); T[TMX][TMW] = -1.; T[TMW][TMW] = 0.; }
long ExtObject::aJump(LPVAL theParams) { float ga = RADIANS(grav_dir * 90); int cosga = cos(ga)*1.5f; int singa = sin(ga)*1.5f; if(singa) dy = -jump_strength * singa; if(cosga) dx = -jump_strength * cosga; return 0; }
double getSolution(double initSpeed, double airFriction, double angleTarget, double distance) { double posTargetX, posTargetY; posTargetX = cos(RADIANS(angleTarget)) * distance; posTargetY = sin(RADIANS(angleTarget)) * distance; if (traceBullet(initSpeed, airFriction, MAXELEVATION, angleTarget, distance) < 0) { return MAXELEVATION - angleTarget; } double a1 = angleTarget; double a2 = MAXELEVATION; double f1, f2, tmp; f1 = traceBullet(initSpeed, airFriction, a1, angleTarget, distance); if (fabs(f1) <= PRECISION) { return 0; } while (fabs(f1) > PRECISION) { f2 = traceBullet(initSpeed, airFriction, a2, angleTarget, distance); tmp = a2 - f2 * (a2 - a1) / (f2 - f1); a1 = a2; a2 = tmp; f1 = f2; } return a2 - angleTarget; }
void Sun::predict(const DateTime &dt) { long DN = dt.DN ; double TN = dt.TN ; double T = (double) (DN - fnday(YG, 1, 0)) + TN ; double GHAE = RADIANS(G0) + T * WE ; double MRSE = RADIANS(G0) + T * WW + M_PI ; double MASE = RADIANS(MAS0 + T * MASD) ; double TAS = MRSE + EQC1*sin(MASE) + EQC2*sin(2.*MASE) ; double C, S ; C = cos(TAS) ; S = sin(TAS) ; SUN[0]=C ; SUN[1]=S*CNS ; SUN[2]=S*SNS ; C = cos(-GHAE) ; S = sin(-GHAE) ; H[0]=SUN[0]*C - SUN[1]*S ; H[1]=SUN[0]*S + SUN[1]*C ; H[2]=SUN[2] ; }
float CGeometry::Orbit(D3DVECTOR &Position,D3DVECTOR &Rotation,D3DVECTOR &Center,float Angle,float Radius,float Step) { float Rads = RADIANS(Angle); Position.x = -sin(Rads) * Radius; Position.z = -cos(Rads) * Radius; Position.x += Center.x; Position.z += Center.z; LookAt(Center,Position,Rotation); Angle += Step; return Angle; }
void Hemicube::renderToSurface( HemiSides surfaceSide, Scene *scene, const Vector& eye, const Vector& lookDir, const Vector &upDir ) { surfaces[ surfaceSide ]->rtBind() ; // Clear WHITE. This is the "no patch" color surfaces[ surfaceSide ]->clear( ByteColor( 255,255,255,255 ) ) ; if( !win->beginDrawing() ) { error( "Hemicube could not begin drawing" ) ; return ; } // Set matrices in shader (globals) Matrix proj = Matrix::ProjPerspectiveRH( RADIANS( HEMI_FOV ), 1.0, HEMI_NEAR, HEMI_FAR ) ; // always use 1.0 aspect, even on sides Matrix view = Matrix::LookAt( eye, lookDir, upDir ) ; win->setModelviewProjection( view*proj ) ; //win->cullMode( CullMode::CullNone ) ; win->setFillMode( FillMode::Solid ) ; // activate the id shader: win->alphaBlend( false ) ; #pragma region right render code // To calculate form factors, // I need the scene rendered // with patch ids (Hence use the "shaderID" shader.) win->shaderID->unsetTexture( 0 ) ; // DO NOT draw with a texture! (if there was bound previously) win->shaderID->activate() ; win->render( scene ) ; #pragma endregion // TESTING AND DEBUGGING /////win->shaderPhongLit->activate() ;//! DEBUG /////window->rasterize() ;//! DEBUG win->endDrawing() ; win->present() ; surfaces[ surfaceSide ]->rtUnbind() ; }