/************* * DESCRIPTION: Generate an axis from a matrix * INPUT: ox,oy,oz returned orientation * p returned position * OUTPUT: - *************/ void MATRIX::GenerateAxis(VECTOR *ox, VECTOR *oy, VECTOR *oz, VECTOR *p) { SetVector(p, m[1], m[ 2], m[ 3]); SetVector(ox, m[5], m[ 9], m[13]); SetVector(oy, m[6], m[10], m[14]); SetVector(oz, m[7], m[11], m[15]); }
void hgemitter::SetDirectionFromAngle( int flag, VECTOR *res, VECTOR *ang ) { float spd; VECTOR v; spd = speed; if ( spd != 0.0f ) spd += ((float)(rand()&4095) * FRND_4096 ) * speedopt; if ( flag == HGMODEL_FLAG_2DSPRITE ) { SetVector( res, sin(ang->z) * spd, cos(ang->z) * spd, 0.0f, 0.0f ); return; } SetVector( &v, 0.0f, 0.0f, spd, 0.0f ); InitMatrix(); switch( rotorder ) { case HGMODEL_ROTORDER_ZYX: RotZ( ang->z ); RotY( ang->y ); RotX( ang->x ); break; case HGMODEL_ROTORDER_XYZ: RotX( ang->x ); RotY( ang->y ); RotZ( ang->z ); break; case HGMODEL_ROTORDER_YXZ: RotY( ang->y ); RotX( ang->x ); RotZ( ang->z ); break; } ApplyMatrix( res, &v ); }
/************* * DESCRIPTION: sets the new object specs * INPUT: disp pointer to display structure * pos translate factor * ox,oy,oz rotate factor * size scale factor * OUTPUT: none *************/ void CAMERA::SetObject(DISPLAY *disp, VECTOR *pos, VECTOR *ox, VECTOR *oy, VECTOR *oz, VECTOR *size) { MATRIX m; if(disp) { if(disp->view->viewmode == VIEW_CAMERA) { VecAdd(pos,&this->pos,&disp->view->pos); if(!track) { InvOrient(ox, oy, oz, &disp->view->axis_x, &disp->view->axis_y, &disp->view->axis_z); m.SetOMatrix(&orient_x,&orient_y,&orient_z); m.MultVectMat(&disp->view->axis_x); m.MultVectMat(&disp->view->axis_y); m.MultVectMat(&disp->view->axis_z); } else { UpdateTracking(&disp->view->pos); InvOrient(&orient_x, &orient_y, &orient_z, &disp->view->axis_x, &disp->view->axis_y, &disp->view->axis_z); } } } SetVector(&bboxmin, -this->size.z*.5f, -this->size.z*.5f, -this->size.z); SetVector(&bboxmax, this->size.z*.5f, this->size.z*1.3f, this->size.z*1.5f); }
/************* * DESCRIPTION: Init camera with defaults * INPUT: none * OUTPUT: none *************/ void CAMERA::ToDefaults() { // camera-position SetVector(&pos, 0.f, 0.f, -10.f); // lookpoint SetVector(&lookp, 0.f, 0.f, 0.f); // view-up-vector SetVector(&vup, 0.f, 1.f, 0.f); // horizontal and vertical field of view hfov = 45.f; vfov = 45.f; // Screen x and y resolution xres = 128; yres = 128; left = top = 0; right = bottom = 127; // depth of field focaldist = 1.f; aperture = 0.f; flags = 0; // animation parameters time = 0; posactor = NULL; viewactor = NULL; }
void init(void) { // GL inits glClearColor(0.2,0.2,0.5,0); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); printError("GL inits"); projectionMatrix = frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 200.0); p = SetVector(10, 10, 10); l = SetVector(2, 10, 2); v = SetVector(0, 1, 0); // Load and compile shader program = loadShaders("terrain1.vert", "terrain1.frag"); glUseProgram(program); printError("init shader"); glUniformMatrix4fv(glGetUniformLocation(program, "projMatrix"), 1, GL_TRUE, projectionMatrix.m); glUniform1i(glGetUniformLocation(program, "tex"), 0); // Texture unit 0 LoadTGATextureSimple("maskros512.tga", &tex1); // Load terrain data LoadTGATextureData("fft-terrain.tga", &ttex); tm = GenerateTerrain(&ttex); printError("init terrain"); }
void FoveatedRenderingApp::DefaultRender(izanagi::graph::CGraphicsDevice* device) { izanagi::sample::CSampleCamera& camera = GetCamera(); device->SetTexture(0, m_Img->GetTexture(m_Idx)); device->SetTexture(1, m_mask); auto shd = m_shdDrawCube.m_shd; device->SetShaderProgram(shd); auto hL2W = shd->GetHandleByName("g_mL2W"); shd->SetMatrix(device, hL2W, m_L2W); auto mtxW2C = camera.GetParam().mtxW2C; auto hW2C = shd->GetHandleByName("g_mW2C"); shd->SetMatrix(device, hW2C, mtxW2C); auto hEye = shd->GetHandleByName("g_vEye"); shd->SetVector(device, hEye, camera.GetParam().pos); auto hInvScr = shd->GetHandleByName("invScreen"); izanagi::math::CVector4 invScr(1.0f / SCREEN_WIDTH, 1.0f / SCREEN_HEIGHT, 0, 0); shd->SetVector(device, hInvScr, invScr); auto hCanFoveated = shd->GetHandleByName("canFoveated"); shd->SetBool(device, hCanFoveated, false); m_Cube->Render(device); }
// Orthonormalization of Matrix4D. Assumes rotation only, translation/projection ignored void OrthoNormalizeMatrix(GLfloat *R) { Point3D x, y, z; SetVector(R[0], R[1], R[2], &x); SetVector(R[4], R[5], R[6], &y); // SetVector(R[8], R[9], R[10], &z); // Kryssa fram ur varandra // Normera CrossProduct(&x, &y, &z); Normalize(&z); Normalize(&x); CrossProduct(&z, &x, &y); R[0] = x.x; R[1] = x.y; R[2] = x.z; R[4] = y.x; R[5] = y.y; R[6] = y.z; R[8] = z.x; R[9] = z.y; R[10] = z.z; R[3] = 0.0; R[7] = 0.0; R[11] = 0.0; R[12] = 0.0; R[13] = 0.0; R[14] = 0.0; R[15] = 1.0; }
/************* * DESCRIPTION: Constructor of box (sets the default values) * INPUT: none * OUTPUT: none *************/ BOX::BOX() { SetVector(&lowbounds, -1.f, -1.f, -1.f); SetVector(&highbounds, 1.f, 1.f, 1.f); SetVector(&orient_x, 1.f, 0.f, 0.f); SetVector(&orient_y, 0.f, 1.f, 0.f); SetVector(&orient_z, 0.f, 0.f, 1.f); }
/************* * DESCRIPTION: transfer camera data to RayStorm Interface * INPUT: stack matrix stack * object pointer to created rsi object * OUTPUT: rsiERR_NONE if ok else error number *************/ rsiResult CAMERA::ToRSI(rsiCONTEXT *rc, MATRIX_STACK *stack, void **object) { VECTOR up, look, orient_x, orient_y, orient_z, pos; MATRIX m, m1; int rsiflags; rsiResult err; stack->GenerateAxis(&orient_x, &orient_y, &orient_z, &pos); m.SetOMatrix(&orient_x, &orient_y, &orient_z); if(track) { track->GetObjectMatrix(&m1); m1.GenerateAxis(&orient_x, &orient_x, &orient_x, &look); } else { SetVector(&look, 0.f, 0.f, 1000.f); m.MultVectMat(&look); VecAdd(&look, &pos, &look); } SetVector(&up, 0.f, 1.f, 0.f); m.MultVectMat(&up); err = PPC_STUB(rsiSetCamera)(CTXT, rsiTCameraPos, &pos, rsiTCameraViewUp, &up, rsiTCameraLook, &look, rsiTDone); if(err) return err; if(flags & OBJECT_CAMERA_VFOV) vfov = hfov*global.yres/global.xres; if(flags & OBJECT_CAMERA_FOCUSTRACK) { VecSub(&look, &pos, &look); focaldist = VecNormalize(&look); } rsiflags = 0; if (flags & OBJECT_CAMERA_FASTDOF) rsiflags |= rsiFCameraFastDOF; return PPC_STUB(rsiSetCamera)(CTXT, rsiTCameraPos, &pos, rsiTCameraHFov, atan(hfov) * 2 * INV_PI_180, rsiTCameraVFov, atan(vfov) * 2 * INV_PI_180, rsiTCameraFocalDist, focaldist, rsiTCameraAperture, aperture, rsiTCameraFlags, rsiflags, rsiTDone); }
/************* * DESCRIPTION: Multiplicate matrix with axis * INPUT: ox,oy,oz axis * OUTPUT: - *************/ void MATRIX::MultMatOrient(VECTOR *ox, VECTOR *oy, VECTOR *oz) { MATRIX matrix,m; m.SetOMatrix(ox, oy, oz); matrix.MultMat(this, &m); SetVector(ox, matrix.m[5], matrix.m[9], matrix.m[13]); SetVector(oy, matrix.m[6], matrix.m[10], matrix.m[14]); SetVector(oz, matrix.m[7], matrix.m[11], matrix.m[15]); }
SURF_DATA::SURF_DATA() { nobound = TRUE; SetVector(&lowbound, INFINITY, INFINITY, INFINITY); SetVector(&highbound, -INFINITY, -INFINITY, -INFINITY); facecount = 0; edgecount = 0; name = NULL; object_count = 0; objects = NULL; }
mat4 lookAt(GLfloat px, GLfloat py, GLfloat pz, GLfloat lx, GLfloat ly, GLfloat lz, GLfloat vx, GLfloat vy, GLfloat vz) { vec3 p, l, v; p = SetVector(px, py, pz); l = SetVector(lx, ly, lz); v = SetVector(vx, vy, vz); return lookAtv(p, l, v); }
/************* * DESCRIPTION: Multiplicate matrix with axis * INPUT: pos,ox,oy,oz axis * OUTPUT: - *************/ void MATRIX::MultMatAxis(VECTOR *pos, VECTOR *ox, VECTOR *oy, VECTOR *oz) { MATRIX matrix,m; m.SetOTMatrix(ox, oy, oz, pos); matrix.MultMat(this, &m); SetVector(pos, matrix.m[1], matrix.m[2], matrix.m[3]); SetVector(ox, matrix.m[5], matrix.m[9], matrix.m[13]); SetVector(oy, matrix.m[6], matrix.m[10], matrix.m[14]); SetVector(oz, matrix.m[7], matrix.m[11], matrix.m[15]); }
/************* * DESCRIPTION: Draw a brush * INPUT: disp display class * stack matrix stack * OUTPUT: none *************/ void BRUSH_OBJECT::Draw(DISPLAY *disp,MATRIX_STACK *stack) { VECTOR size, trans; MATRIX m; switch(disp->display) { case DISPLAY_BBOX: case DISPLAY_WIRE: switch(brush->wrap) { case BRUSH_WRAP_FLAT: // draw a bounding box around pos disp->DrawBox(stack,&bboxmin,&bboxmax); break; case BRUSH_WRAP_X: SetVector(&size, (bboxmax.y - bboxmin.y) * .5f, bboxmax.x - bboxmin.x, (bboxmax.z - bboxmin.z) * .5f); m.SetRotZMatrix(90.f); stack->Push(&m); SetVector(&trans, 0.f, - size.y * .5f, 0.f); m.SetTransMatrix(&trans); stack->Push(&m); disp->DrawCylinder(stack, &size, flags); stack->Pop(&m); stack->Pop(&m); break; case BRUSH_WRAP_Y: SetVector(&size, (bboxmax.x - bboxmin.x) * .5f, bboxmax.y - bboxmin.y, (bboxmax.z - bboxmin.z) * .5f); SetVector(&trans, 0.f, - size.y * .5f, 0.f); m.SetTransMatrix(&trans); stack->Push(&m); disp->DrawCylinder(stack, &size, flags); stack->Pop(&m); break; case BRUSH_WRAP_XY: disp->DrawSphere(stack, (bboxmax.x-bboxmin.x)*.5f); break; } break; } }
/* QuakeEd only writes a single float for angles (bad idea), so up and down are just constant angles. */ void SetMovedir() { if ( VectorCompareF( self->s.v.angles, 0, -1, 0 ) ) SetVector( self->s.v.movedir, 0, 0, 1 ); else if ( VectorCompareF( self->s.v.angles, 0, -2, 0 ) ) SetVector( self->s.v.movedir, 0, 0, -1 ); else { makevectors( self->s.v.angles ); VectorCopy( g_globalvars.v_forward, self->s.v.movedir ); } SetVector( self->s.v.angles, 0, 0, 0 ); }
/* * Creates a sun and appends it to planetsList. */ void CreateSun(GLfloat radius, enum planetShape shape) { struct PlanetStruct planet; planet.center = SetVector(0, 0, 0); planet.startingPosition = planet.center; planet.radius = radius; planet.orbitalSpeed = 0; planet.orbitalAxis = SetVector(0,1,0); planet.rotationalSpeed = 0.0002; planet.rotationalAxis = SetVector(1,1,0); planet.type = shape; planet.textureScale = 1; CreatePlanet(planet, NO_SOUND); }
void OpenGLDrawCylinder(VECTOR *size, ULONG flags) { VECTOR bottom, norm; int i; if(!(flags & (OBJECT_OPENTOP | OBJECT_OPENBOTTOM))) glEnable(GL_CULL_FACE); if(!(flags & OBJECT_OPENBOTTOM)) { glBegin(GL_TRIANGLE_FAN); glNormal3f(0.f, -1.f, 0.f); glVertex3f(0.f, 0.f, 0.f); for(i = 0; i <= 360; i += OGL_CYLINDER_DIVS) glVertex3f(sin(i*PI_180)*size->x, 0.f, cos(i*PI_180)*size->z); glEnd(); } glBegin(GL_TRIANGLE_STRIP); for(i = 0; i <= 360; i += OGL_CYLINDER_DIVS) { SetVector(&norm, sin(i*PI_180), 0.f, cos(i*PI_180)); SetVector(&bottom, norm.x*size->x, 0.f, norm.z*size->z); glNormal3fv((GLfloat*)&norm); glVertex3fv((GLfloat*)&bottom); glVertex3f(bottom.x, size->y, bottom.z); } glEnd(); if(!(flags & OBJECT_OPENTOP)) { glBegin(GL_TRIANGLE_FAN); glNormal3f(0.f, 1.f, 0.f); glVertex3f(0.f, size->y, 0.f); for(i = 360; i >= 0; i -= OGL_CYLINDER_DIVS) glVertex3f(sin(i*PI_180)*size->x, size->y, cos(i*PI_180)*size->z); glEnd(); } if(!(flags & (OBJECT_OPENTOP | OBJECT_OPENBOTTOM))) glDisable(GL_CULL_FACE); }
void OpenGLDrawCone(VECTOR *size, ULONG flags) { VECTOR bottom,bottom1, centertop; int i; VECTOR norm, e0,e1; if(!(flags & OBJECT_OPENBOTTOM)) { glEnable(GL_CULL_FACE); glBegin(GL_TRIANGLE_FAN); glNormal3f(0.f, -1.f, 0.f); glVertex3f(0.f, 0.f, 0.f); for(i = 0; i <= 360; i += OGL_CONE_DIVS) glVertex3f(sin(i*PI_180)*size->x, 0.f, cos(i*PI_180)*size->z); glEnd(); } glBegin(GL_TRIANGLE_FAN); glNormal3f(0.f, 1.f, 0.f); SetVector(¢ertop, 0.f, size->y, 0.f); glVertex3fv((GLfloat*)¢ertop); SetVector(&bottom, 0.f, 0.f, size->z); SetVector(&bottom1, sin((360-OGL_CONE_DIVS)*PI_180)*size->x, 0.f, cos((360-OGL_CONE_DIVS)*PI_180)*size->z); VecSub(¢ertop, &bottom, &e0); VecSub(¢ertop, &bottom1, &e1); VecNormCross(&e0, &e1, &norm); glNormal3fv((GLfloat*)&norm); glVertex3fv((GLfloat*)&bottom); for(i = 360-OGL_CONE_DIVS; i >= -OGL_CONE_DIVS; i -= OGL_CONE_DIVS) { bottom = bottom1; SetVector(&bottom1, sin(i*PI_180)*size->x, 0.f, cos(i*PI_180)*size->z); VecSub(¢ertop, &bottom, &e0); VecSub(¢ertop, &bottom1, &e1); VecNormCross(&e0, &e1, &norm); glNormal3fv((GLfloat*)&norm); glVertex3fv((GLfloat*)&bottom); } glEnd(); if(!(flags & OBJECT_OPENBOTTOM)) glDisable(GL_CULL_FACE); }
static void updateCameraMatrix(mat4 *matrix) { if (matrix != NULL) { camera = MultVec3(*matrix, camera); lookAtPoint = MultVec3(*matrix, lookAtPoint); } *_cameraMatrix = lookAt(camera.x, camera.y, camera.z, lookAtPoint.x, lookAtPoint.y, lookAtPoint.y, up.x, up.y, up.z); right = SetVector(_cameraMatrix->m[0], _cameraMatrix->m[1], _cameraMatrix->m[2]); up = SetVector(_cameraMatrix->m[4], _cameraMatrix->m[5], _cameraMatrix->m[6]); fwd = SetVector(_cameraMatrix->m[8], _cameraMatrix->m[9], _cameraMatrix->m[10]); // glUniformMatrix4fv(glGetUniformLocation(shader, viewMatName), 1, GL_TRUE, _cameraMatrix.m); }
/* ================ SpawnMeatSpray ================ */ void SpawnMeatSpray( vec3_t org, vec3_t vel ) { gedict_t *missile; //vec3_t org; missile = spawn(); missile->s.v.owner = EDICT_TO_PROG( self ); missile->s.v.movetype = MOVETYPE_BOUNCE; missile->s.v.solid = SOLID_NOT; makevectors( self->s.v.angles ); VectorCopy( vel, missile->s.v.velocity ); // missile->s.v.velocity = vel; missile->s.v.velocity[2] = missile->s.v.velocity[2] + 250 + 50 * g_random(); SetVector( missile->s.v.avelocity, 3000, 1000, 2000 ); // missile.avelocity = '3000 1000 2000'; // set missile duration missile->s.v.nextthink = g_globalvars.time + 1; missile->s.v.think = ( func_t ) SUB_Remove; setmodel( missile, "progs/zom_gib.mdl" ); setsize( missile, 0, 0, 0, 0, 0, 0 ); setorigin( missile, PASSVEC3( org ) ); }
void AnimaRenderer::ApplyEffectFromTextureToGBuffer(AnimaShaderProgram* filterProgram, AnimaTexture* src, AnimaGBuffer* dst) { if (dst != nullptr) dst->BindAsRenderTarget(); else { AnimaVertex2f size = GetVector2f("ScreenSize"); glViewport(0, 0, (AUint)size.x, (AUint)size.y); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); } if (_filterMesh->NeedsBuffersUpdate()) _filterMesh->UpdateBuffers(); SetTexture("FilterMap", src, false); SetVector("TextureSize", AnimaVertex2f((AFloat)src->GetWidth(), (AFloat)src->GetHeight())); glClear(GL_DEPTH_BUFFER_BIT); filterProgram->Use(); filterProgram->UpdateCameraProperies(_filterCamera); filterProgram->UpdateRenderingManagerProperies(this); _filterMesh->Draw(this, filterProgram, false); SetTexture("FilterMap", nullptr, false); }
// would love to know what a ctf wall is :O! void SP_func_ctf_wall() { SetVector( self->s.v.angles, 0, 0, 0 ); self->s.v.movetype = MOVETYPE_PUSH; self->s.v.solid = SOLID_BSP; setmodel( self, self->s.v.model ); }
/* * Takes care of orbit and rotation */ void UpdatePlanetMovement(GLint t) { GLuint i; mat4 ModelToWorld; for(i = 0; i < numberOfPlanets; i++) { t = glutGet(GLUT_ELAPSED_TIME) - planetsList[i].timeOfCreation; vec3 arbAxis = {0,1,0}; ModelToWorld = ArbRotate(planetsList[i].rotationalAxis, planetsList[i].rotationalSpeed*(GLfloat)t); //IdentityMatrix(); //Rotation around own axis ModelToWorld = Mult(T(planetsList[i].startingPosition.x, planetsList[i].startingPosition.y, planetsList[i].startingPosition.z), ModelToWorld); //Offset if(!(planetsList[i].startingPosition.x == planetsList[0].startingPosition.x && planetsList[i].startingPosition.y == planetsList[0].startingPosition.y && planetsList[i].startingPosition.z == planetsList[0].startingPosition.z )) //Dont try to orbit when already at 0 { if(fabs(planetsList[i].startingPosition.x) - arbAxis.x + fabs(planetsList[i].startingPosition.y) - arbAxis.y + fabs(planetsList[i].startingPosition.z) - arbAxis.z == 0) arbAxis = SetVector(1,0,0); arbAxis = Normalize(CrossProduct(VectorSub(planetsList[i].startingPosition, planetsList[0].startingPosition), arbAxis)); ModelToWorld = Mult(T(planetsList[0].center.x, planetsList[0].center.y, planetsList[0].center.z), ModelToWorld); ModelToWorld = Mult(ArbRotate(arbAxis, planetsList[i].orbitalSpeed*(GLfloat)t), ModelToWorld); //Orbit ModelToWorld = Mult(T(-planetsList[0].center.x, -planetsList[0].center.y, -planetsList[0].center.z), ModelToWorld); } planetsList[i].ModelToWorldMatrix = ModelToWorld; } }
/************* * DESCRIPTION: sets the new object specs * INPUT: disp pointer to display structure * pos translate factor * ox,oy,oz rotate factor * size scale factor * OUTPUT: none *************/ void SPHERE::SetObject(DISPLAY *disp, VECTOR *pos, VECTOR *ox, VECTOR *oy, VECTOR *oz, VECTOR *size) { this->size.y = this->size.x; this->size.z = this->size.x; SetVector(&bboxmin, -this->size.x, -this->size.y, -this->size.z); bboxmax = this->size; }
// --------------------------------------------------------------------------- // CMMCScBkupIndexDataOwners::StoreL() // // // --------------------------------------------------------------------------- void CMMCScBkupIndexDataOwners::StoreL(MMMCScBkupDriver& aDriver) { MMMCScBkupArchiveDataInterface& archiveDataInterface = aDriver.DrvADI(); RWriteStream& stream = archiveDataInterface.ADIWriteStreamUncompressedLC(); // stream.WriteInt32L( EStreamFormatVersion1 ); stream.WriteInt32L( 0 ); // spare1 stream.WriteInt32L( 0 ); // spare2 stream.WriteInt32L( 0 ); // spare3 // const TInt count = iEntries.Count(); stream.WriteInt32L(count); // for(TInt i=0; i<count; i++) { const TMMCScBkupArchiveVector& entry = iEntries[i]; stream << entry; // stream.WriteInt32L( 0 ); // spare1 stream.WriteInt32L( 0 ); // spare2 } // stream.CommitL(); CleanupStack::PopAndDestroy(); // stream // Update our base class info with the offset to the index const TMMCScBkupArchiveVector& writeInfo = archiveDataInterface.ADICurrentArchiveVectorInfo(); SetVector( writeInfo ); }
void spawn_item_flag() { if ( k_ctf_custom_models ) setmodel( self, "progs/flag.mdl" ); self->s.v.noise = "misc/flagtk.wav"; self->s.v.noise1 = "doors/runetry.wav"; setsize( self, -16, -16, 0, 16, 16, 74); self->mdl = self->s.v.model; self->s.v.flags = FL_ITEM; self->s.v.solid = SOLID_TRIGGER; self->s.v.movetype = MOVETYPE_TOSS; SetVector( self->s.v.velocity, 0, 0, 0 ); self->s.v.origin[2] += 6; self->s.v.think = (func_t) FlagThink; self->s.v.touch = (func_t) FlagTouch; self->s.v.nextthink = g_globalvars.time + 0.1; self->cnt = FLAG_AT_BASE; self->cnt2 = 0.0; VectorCopy( self->s.v.angles, self->mangle ); self->s.v.effects = (int) self->s.v.effects | EF_DIMLIGHT; if ( !droptofloor( self ) ) ent_remove( self ); else VectorCopy( self->s.v.origin, self->s.v.oldorigin ); if ( !isCTF() ) { setmodel( self, "" ); self->s.v.touch = (func_t) SUB_Null; } }
/************* * DESCRIPTION: Calculate direction of refracted ray using Heckbert's formula. * Returns TRUE if a total internal reflection occurs. * INPUT: dir direction vector * index index of refraction * norm surface normal * OUTPUT: TRUE if TIR occurs, else FALSE *************/ static BOOL Refract(VECTOR *newdir, float index, VECTOR *norm, float cos1) { float cos2, k; VECTOR nrm, dir; if (cos1 < 0.f) { // Hit the 'backside' of a surface -- flip the normal. nrm.x = -norm->x; nrm.y = -norm->y; nrm.z = -norm->z; cos1 = -cos1; } else { nrm = *norm; } cos2 = 1.f - index*index*(1. - cos1*cos1); if (cos2 < 0.f) return TRUE; // Total internal reflection k = - sqrt((double)cos2) + index * cos1; SetVector(&dir, 0.f, 0.f, 1.f); VecComb(index, &dir, k, &nrm, newdir); return FALSE; }
void DeathBubblesSpawn() { gedict_t *bubble; if ( PROG_TO_EDICT( self->s.v.owner )->s.v.waterlevel != 3 ) return; bubble = spawn(); setmodel( bubble, "progs/s_bubble.spr" ); setorigin( bubble, PROG_TO_EDICT( self->s.v.owner )->s.v.origin[0], PROG_TO_EDICT( self->s.v.owner )->s.v.origin[1], PROG_TO_EDICT( self->s.v.owner )->s.v.origin[2] + 24 ); bubble->s.v.movetype = MOVETYPE_NOCLIP; bubble->s.v.solid = SOLID_NOT; SetVector( bubble->s.v.velocity, 0, 0, 15 ); bubble->s.v.nextthink = g_globalvars.time + 0.5; bubble->think = ( func_t ) bubble_bob; bubble->classname = "bubble"; bubble->s.v.frame = 0; bubble->cnt = 0; setsize( bubble, -8, -8, -8, 8, 8, 8 ); self->s.v.nextthink = g_globalvars.time + 0.1; self->think = ( func_t ) DeathBubblesSpawn; self->air_finished = self->air_finished + 1; if ( self->air_finished >= self->bubble_count ) ent_remove( self ); }
void fire_fly( ) { gedict_t *fireball; fireball = spawn( ); newmis = fireball; g_globalvars.newmis = EDICT_TO_PROG( newmis ); fireball->s.v.solid = SOLID_TRIGGER; fireball->s.v.movetype = MOVETYPE_TOSS; SetVector( fireball->s.v.velocity, ( g_random( ) * 100 ) - 50, ( g_random( ) * 100 ) - 50, self->speed + ( g_random( ) * 200 ) ); fireball->s.v.classname = "fireball"; setmodel( fireball, "progs/lavaball.mdl" ); setsize( fireball, 0, 0, 0, 0, 0, 0 ); setorigin( fireball, PASSVEC3( self->s.v.origin ) ); fireball->s.v.nextthink = g_globalvars.time + 5; fireball->s.v.think = ( func_t ) SUB_Remove; fireball->s.v.touch = ( func_t ) fire_touch; self->s.v.nextthink = g_globalvars.time + ( g_random( ) * 5 ) + 3; self->s.v.think = ( func_t ) fire_fly; }
//========================================================================= // Touch Function for EMP Grenade void EMPGrenadeTouch( ) { // If the EMP Grenade hits a player, it just bounces off sound( self, 1, "weapons/bounce.wav", 1, 1 ); if ( VectorCompareF( self->s.v.velocity, 0, 0, 0 ) ) SetVector( self->s.v.avelocity, 0, 0, 0 ); }