コード例 #1
0
ファイル: RENDER.C プロジェクト: IvanIoganson/sum2014
/* Camera move by Right-Axes function.
 * ARGUMENTS:
 *   - Distance to move:
 *       DBL Coef;  
 * RETURNS: None.
 */
VOID II2_RndCameraMoveRight( ii2CAMERA *Cam, DBL Coef )
{
  Cam->Dir = VecSubVec(Cam->At, Cam->Loc);
  Cam->Right = VecCrossVec(Cam->Dir, Cam->Up);
  Cam->Loc = VecAddVec(Cam->Loc, VecMulNum(VecNormalize(Cam->Right), Coef));
  Cam->At = VecAddVec(Cam->At, VecMulNum(VecNormalize(Cam->Right), Coef));
}  /* End of 'II2_RndCameraMoveByDir' funciton */
コード例 #2
0
ファイル: GOST.C プロジェクト: IvanNoskov/SUM2014
/* GOST unit
 * response function
 * base unit response arguments */
static VOID GOSTUnitResponse( in1UNIT_GOST *Unit, in1ANIM *Ani )
{
  MATRIXd R;
  VEC M;                         
  if((Ani->KeysClick[VK_NUMPAD9] || Ani->JsButClick[4]) && !Ani->IsPause)
  {
    Unit->Head.Dir = VecNormalize( VecNeg( Unit->Head.Loc ) );
    Unit->Head.Right = VecNormalize( VecCrossVec( Unit->Head.Dir, VecSet( 0, 1, 0 ) ) );
    Unit->Head.Up = VecCrossVec( Unit->Head.Right, Unit->Head.Dir );
  }
  R = MatrMulMatr( MatrMulMatr( MatrRotateVec( Ani->DeltaTime * Ani->JsR * 30, Unit->Head.Dir.X,  Unit->Head.Dir.Y,  Unit->Head.Dir.Z ),
                                MatrRotateVec( Ani->DeltaTime * Ani->JsY * 30, Unit->Head.Right.X,  Unit->Head.Right.Y,  Unit->Head.Right.Z ) ), 
                   MatrRotateVec( Ani->DeltaTime * Ani->JsX * 30, Unit->Head.Up.X,  Unit->Head.Up.Y,  Unit->Head.Up.Z ) );
  M = VecSet( Unit->Head.Dir.X * Ani->JsZ * 3 * Ani->DeltaTime, 
              Unit->Head.Dir.Y * Ani->JsZ * 3 * Ani->DeltaTime, 
              Unit->Head.Dir.Z * Ani->JsZ * 3 * Ani->DeltaTime );
  if (Ani->JsPOV == 1 || Ani->JsPOV == 2 || Ani->JsPOV == 8)
    M = VecAddVec( M, VecMulNum( Unit->Head.Dir,  Ani->DeltaTime * 3 ) );
  if (Ani->JsPOV == 4 || Ani->JsPOV == 5 || Ani->JsPOV == 6)
    M = VecAddVec( M, VecMulNum( Unit->Head.Dir, -Ani->DeltaTime * 3 ) );
  if (Ani->JsPOV == 2 || Ani->JsPOV == 3 || Ani->JsPOV == 4)
    M = VecAddVec( M, VecMulNum( Unit->Head.Right,  Ani->DeltaTime * 3 ) );  
  if (Ani->JsPOV == 6 || Ani->JsPOV == 7 || Ani->JsPOV == 8)
    M = VecAddVec( M, VecMulNum( Unit->Head.Right, -Ani->DeltaTime * 3 ) );  
  Unit->Head.Dir = VectorTransformer( Unit->Head.Dir, R );
  Unit->Head.Right = VectorTransformer( Unit->Head.Right, R );
  Unit->Head.Up = VectorTransformer( Unit->Head.Up, R );
  Unit->Head.Loc = VecAddVec( Unit->Head.Loc, M );

} 
コード例 #3
0
ファイル: RENDER.C プロジェクト: IvanIoganson/sum2014
/* Cameras normalizing vectors function.
* ARGUMENTS: None.
* RETURNS: None.
*/
static VOID II2_RndCameraNormalize( ii2CAMERA *Cam )
{
  Cam->At = VecNormalize(Cam->At);
  Cam->Dir = VecNormalize(Cam->Dir);
  Cam->Up = VecNormalize(Cam->Up);
  Cam->Right = VecNormalize(Cam->Right);
} /* End of 'II2_RndCameraGetMatrix' funciton */
コード例 #4
0
ファイル: l1text.c プロジェクト: ABratovic/open-watcom-v2
static void GetVectors( struct xycoord * base, struct xycoord * up )
/*==================================================================

    Normalize the character up and base vectors to the character height
    and width respectively. The character up vector is made visually
    perpendicular to the character base vector. The character up vector
    is corrected by the screen aspect ratio so that it looks perpendicular
    to the character base vector on all devices. Assume that the
    width : height ratio of the physical dimensions of the screen is 4 : 3. */

{
    float           aspectratio;
    float           basex;
    float           basey;
    float           upx;
    float           upy;

    aspectratio = (float)( _CurrState->vc.numypixels << 2 ) /
                     (float)( _CurrState->vc.numxpixels * 3 );
    basex = (float) _TextSettings.basevectorx;
    basey = (float) _TextSettings.basevectory * aspectratio;
    upx = - (float) _TextSettings.basevectory;
    upy = basex * aspectratio;
    VecNormalize( _TextSettings.height, upx, upy, up );
    VecNormalize( _TextSettings.width, basex, basey, base );
}
コード例 #5
0
ファイル: MWMath_Quat.cpp プロジェクト: ak4hige/myway3d
void Math::QuatFromDir(Quat & qOut, const Vec3 & dir1, const Vec3 & dir2, const Vec3 & fallbackAxis, bool normalize)
{
    Vec3 d1 = dir1;
    Vec3 d2 = dir2;

    if (normalize)
    {
        VecNormalize(d1, d1);
        VecNormalize(d2, d2);
    }

    float d = VecDot(d1, d2);

    if (d >= 1.0f)
    {
        qOut = Quat::Identity;
    }
    else if (d < (1e-6f - 1.0f))
    {
        if (fallbackAxis != Vec3::Zero)
        {
            // rotate 180 degrees about the fallback axis
            Math::QuatFromAxis(qOut, fallbackAxis, Math::PI_1);
        }
        else
        {
            // Generate an axis
            Vec3 axis;
            Math::VecCross(axis, Vec3::UnitX, d1);

            if (Math::VecLengthSq(axis) < DEFAULT_EPSILON) // pick another if colinear
                Math::VecCross(axis, Vec3::UnitY, d1);

            VecNormalize(axis, axis);
            Math::QuatFromAxis(qOut, axis, Math::PI_1);
        }
    }
    else
    {
        float s = Math::Sqrt((1 + d) * 2);
        float invs = 1 / s;

        Vec3 c;
        Math::VecCross(c, d1, d2);

        qOut.x = c.x * invs;
        qOut.y = c.y * invs;
        qOut.z = c.z * invs;
        qOut.w = s * 0.5f;

        Math::QuatNormalize(qOut, qOut);
    }
}
コード例 #6
0
ファイル: mapping.cpp プロジェクト: refnum/quesa
Mapping *
SphereMappingCreate(
        Vector          *center,
        Vector          *norm,
        Vector          *uaxis)
{
	Mapping *res;

	res = (Mapping *)Malloc(sizeof(Mapping));
	res->flags = OBJSPACE;
	res->method = SphereMapping;
	if (center)
		res->center = *center;
	else
		res->center.x = res->center.y = res->center.z = 0.;
	if (norm && uaxis) {
		res->norm = *norm;
		if (VecNormalize(&res->norm) == 0.) {
			RLerror(RL_ABORT, "Degenerate mapping vector.\n");
			return (Mapping *)NULL;
		}
		if (VecNormCross(norm, uaxis, &res->vaxis) == 0.) {
			RLerror(RL_ABORT, "Degenerate mapping vector.\n");
			return (Mapping *)NULL;
		}
		(void)VecNormCross(&res->vaxis, norm, &res->uaxis);
	} else {
		res->norm.x = res->norm.y = res->uaxis.y = res->uaxis.z =
			res->vaxis.x = res->vaxis.z = 0.;
		res->norm.z = res->uaxis.x = res->vaxis.y = 1.;
	}
	return res;
}
コード例 #7
0
ファイル: vertex_util.cpp プロジェクト: stephanmg/ugcore
////////////////////////////////////////////////////////////////////////
//	CalculateVertexNormals
bool CalculateVertexNormals(Grid& grid,
                            Grid::AttachmentAccessor<Vertex, APosition>& aaPos,
                            Grid::AttachmentAccessor<Vertex, ANormal>& aaNorm)
{
//	set all normals to zero
    {
        for(VertexIterator iter = grid.begin<Vertex>();
                iter != grid.end<Vertex>(); iter++)
            aaNorm[*iter] = vector3(0, 0, 0);
    }
//	loop through all the faces, calculate their normal and add them to their connected points
    {
        for(FaceIterator iter = grid.begin<Face>(); iter != grid.end<Face>(); iter++)
        {
            Face* f = *iter;
            vector3 vN;

            CalculateNormal(vN, f, aaPos);

            for(size_t i = 0; i < f->num_vertices(); ++i)
                VecAdd(aaNorm[f->vertex(i)], aaNorm[f->vertex(i)], vN);
        }
    }
//	loop through all the points and normalize their normals
    {
        for(VertexIterator iter = grid.begin<Vertex>();
                iter != grid.end<Vertex>(); iter++)
            VecNormalize(aaNorm[*iter], aaNorm[*iter]);
    }
//	done
    return true;
}
コード例 #8
0
ファイル: vecmath.cpp プロジェクト: privatosan/RayStorm
/*************
 * DESCRIPTION:   Given a vector, find two additional vectors such that all three
 *                are mutually perpendicular and uaxis X vaxis = vector.  The given
 *                vector need not be normalized. uaxis and vaxis are normalized.
 * INPUT:         vector         vector to find two vectors for
 *                uaxis          first found vector
 *                vaxis          second found vector
 * OUTPUT:        none
 *************/
void VecCoordSys(VECTOR *vector, VECTOR *uaxis, VECTOR *vaxis)
{
    uaxis->x = -vector->y;
    uaxis->y = vector->x;
    uaxis->z = 0.f;
    if (VecNormalize(uaxis) == 0.f)
    {
        uaxis->x = vector->z;
        uaxis->y = 0.f;
        uaxis->z = -vector->x;
        if (VecNormalize(uaxis) == 0.f)
            // Degenerate vector
            return;
    }
    VecNormCross(vector, uaxis, vaxis);
}
コード例 #9
0
ファイル: mapping.cpp プロジェクト: refnum/quesa
Mapping *
LinearMappingCreate(
        Vector          *center,
        Vector          *vaxis,
        Vector          *uaxis)
{
	Mapping *res;
	RSMatrix m;
	Vector n;

	res = (Mapping *)Malloc(sizeof(Mapping));
	res->flags = OBJSPACE;
	res->method= LinearMapping;

	if (center)
		res->center = *center;
	else
		res->center.x = res->center.y = res->center.z = 0.;

	if (uaxis && vaxis) {
		VecCross(uaxis, vaxis, &n);
		/* this is wrong, since uaxis and vaxis
		 * give U and V in world space, and we
		 * need the inverse.
		 */
		ArbitraryMatrix(
			uaxis->x, uaxis->y, uaxis->z,
			vaxis->x, vaxis->y, vaxis->z,
			n.x, n.y, n.z,
			res->center.x, res->center.y, res->center.z,
			&m);
		MatrixInvert(&m, &res->m);
		res->uaxis = *uaxis;
		res->vaxis = *vaxis;
		VecNormalize(&res->uaxis);
		VecNormalize(&res->vaxis);
	} else {
		VecScale(-1., res->center, &n);
		TranslationMatrix(n.x, n.y, n.z, &res->m);
		res->uaxis.x = res->vaxis.y = 1.;
		res->uaxis.y = res->uaxis.z = res->vaxis.x =
			res->vaxis.z = 0.;
	}
	return res;
}
コード例 #10
0
ファイル: VEC.C プロジェクト: Killaz/SUM2014
MATR MatrViewLookAt( VEC Loc, VEC At, VEC UpApprox )
{
  VEC Right, Up, Dir;
  MATR r;
  		
  Dir = VecNormalize(VecSubVec(At, Loc));
  Right = VecNormalize(VecCrossVec(Dir, UpApprox));
  Up = VecCrossVec(Right, Dir);

  r.A[0][0] = Right.x; r.A[0][1] = Up.x; r.A[0][2] = -Dir.x; r.A[0][3] = 0;
  r.A[1][0] = Right.y; r.A[1][1] = Up.y; r.A[1][2] = -Dir.y; r.A[1][3] = 0;
  r.A[2][0] = Right.z; r.A[2][1] = Up.z; r.A[2][2] = -Dir.z; r.A[2][3] = 0;
  r.A[3][0] = -VecDotVec(Loc, Right);
  r.A[3][1] = -VecDotVec(Loc, Up);
  r.A[3][2] = VecDotVec(Loc, Dir);
  r.A[3][3] = 1;
  return r;
}
コード例 #11
0
ファイル: CONTROL.c プロジェクト: markporoshin/SUM2016
static VOID MP2_UnitResponse( mp2CONTROL *Uni, mp2ANIM *Ani )
{
  DBL r;
  VEC Dir = VecNormalize(VecSubVec(View, Uni->Pos)),
      Right = VecNormalize(VecCrossVec(Dir, VecSet(0, 1, 0)));
  if (Ani->Keys['T'])
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  if (Ani->Keys['Y'])
    glPolygonMode(GL_FRONT, GL_LINE);
  if (Ani->Keys['U'])
    glPolygonMode(GL_BACK, GL_LINE);
  /*if (Ani->Keys[VK_SPACE])
    MP2_AnimAddUnit(MP2_UnitCreateBall()); */
  if (Ani->KeysClick['C'])
    MP2_AnimAddUnit(MP2_UnitCreateCube(/*Rnd1() * 4, Rnd1() * 4, Rnd1() * 4*/0, 0, 0));
  if (Ani->KeysClick['V'])
    MP2_AnimAddUnit(MP2_UnitCreateSTATICMODEL(/*Rnd1() * 4, Rnd1() * 4, Rnd1() * 4*/0, 0, 0));
  if (Ani->KeysClick[VK_RETURN] && Ani->Keys[VK_MENU])
    MP2_FlipFullScreen(MP2_Anim.hWnd);
  /*if (Ani->KeysClick[VK_ESCAPE])
    MP2_AnimDoExit();*/
  if (Ani->KeysClick['P'])
    Ani->IsPause = !Ani->IsPause;

  /* Uni->Pos.Y += Ani->JY * Ani->GlobalDeltaTime; */
  Uni->Pos = PointTransform(Uni->Pos, MatrRotate((50 * Ani->JY * Ani->GlobalDeltaTime), Right));
  Uni->Pos = PointTransform(Uni->Pos, MatrRotateY(10 * Ani->JX * Ani->GlobalDeltaTime));
   

  if (Ani->Keys[VK_LBUTTON])
  {
    Uni->Pos = PointTransform(Uni->Pos, MatrRotateY(10 * Ani->Mdx * Ani->GlobalDeltaTime));
    Uni->Pos = PointTransform(Uni->Pos, MatrRotateX(10 * Ani->Mdy * Ani->GlobalDeltaTime));
  }
  View.X += Ani->JZ / 10;
  View.Z += Ani->JR / 10;
  Uni->Pos = PointTransform(Uni->Pos, MatrRotateY(10 * Ani->Keys[VK_RIGHT] * Ani->GlobalDeltaTime));
  Uni->Pos = PointTransform(Uni->Pos, MatrRotateY(-10 * Ani->Keys[VK_LEFT] * Ani->GlobalDeltaTime));

  r = VecLen(Uni->Pos);
  Uni->Pos = VecMulNum(Uni->Pos, (r + (-Ani->Mdz) * Ani->DeltaTime * 1.0) / r);
  
  MP2_RndMatrView = MatrView(VecAddVec(Uni->Pos, View), View, VecSet(0, 1, 0));
}
コード例 #12
0
ファイル: camera.cpp プロジェクト: Kalamatee/RayStorm
/*************
 * 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);
}
コード例 #13
0
ファイル: mapping.cpp プロジェクト: refnum/quesa
void
SphereMapping(
        Mapping             *map, 
        Geom                * /*obj*/,
        Vector              *pos, 
        Vector              * /*norm*/, 
        Vec2d               *uv,
        Vector              * /*dpdu*/,
        Vector              * /*dpdv*/)
{
	Vector vtmp;
	Float nx, ny, nz, phi, theta;

	VecSub(*pos, map->center, &vtmp);
	if (VecNormalize(&vtmp) == 0.) {
		/*
		 * Point is coincident with origin of sphere.  Punt.
		 */
		uv->u = uv->v = 0.;
		return;
	}

	/*
	 * Find location of point projected onto unit sphere
	 * in the sphere's coordinate system.
	 */
	nx = dotp(&map->uaxis, &vtmp);
	ny = dotp(&map->vaxis, &vtmp);
	nz = dotp(&map->norm, &vtmp);

	if (nz > 1.)	/* roundoff */
		phi = PI;
	else if (nz < -1.)
		phi = 0;
	else
		phi = acos(-nz);

	uv->v = phi / PI;

	if (fabs(uv->v) < EPSILON || equal(uv->v, 1.))
		uv->u = 0.;
	else {
		theta = nx / sin(phi);
		if (theta > 1.)
			theta = 0.;
		else if (theta < -1.)
			theta = 0.5;
		else
			theta = acos(theta) / TWOPI;

		if (ny > 0)
			uv->u = theta;
		else
			uv->u = 1 - theta;
	}
}
コード例 #14
0
D3DMATRIX* MatrixLookAtLH( 
    D3DMATRIX *pOut, 
    const D3DVECTOR *pEye, 
    const D3DVECTOR *pAt,
    const D3DVECTOR *pUp 
    )
{

    D3DVECTOR vecX, vecY, vecZ;

    // Compute direction of gaze. (+Z)

    VecSubtract(&vecZ, pAt, pEye);
    VecNormalize(&vecZ, &vecZ);

    // Compute orthogonal axes from cross product of gaze and pUp vector.
    VecCross(&vecX, pUp, &vecZ);
    VecNormalize(&vecX, &vecX);
    VecCross(&vecY, &vecZ, &vecX);

    // Set rotation and translate by pEye
    pOut->_11 = vecX.x;
    pOut->_21 = vecX.y;
    pOut->_31 = vecX.z;
    pOut->_41 = -VecDot(&vecX, pEye);

    pOut->_12 = vecY.x;
    pOut->_22 = vecY.y;
    pOut->_32 = vecY.z;
    pOut->_42 = -VecDot(&vecY, pEye);

    pOut->_13 = vecZ.x;
    pOut->_23 = vecZ.y;
    pOut->_33 = vecZ.z;
    pOut->_43 = -VecDot(&vecZ, pEye);

    pOut->_14 = 0.0f;
    pOut->_24 = 0.0f;
    pOut->_34 = 0.0f;
    pOut->_44 = 1.0f;

    return pOut;
}
コード例 #15
0
static PetscErrorCode KSPSolve_AGMRES(KSP ksp)
{
  PetscErrorCode ierr;
  PetscInt       its;
  KSP_AGMRES     *agmres    = (KSP_AGMRES*)ksp->data;
  PetscBool      guess_zero = ksp->guess_zero;
  PetscReal      res_old, res;
  PetscInt       test;

  PetscFunctionBegin;
  ierr     = PetscObjectSAWsTakeAccess((PetscObject)ksp);CHKERRQ(ierr);
  ksp->its = 0;
  ierr     = PetscObjectSAWsGrantAccess((PetscObject)ksp);CHKERRQ(ierr);

  ksp->reason = KSP_CONVERGED_ITERATING;
  if (!agmres->HasShifts) { /* Compute Shifts for the Newton basis */
    ierr = KSPComputeShifts_DGMRES(ksp);CHKERRQ(ierr);
  }
  /* NOTE: At this step, the initial guess is not equal to zero since one cycle of the classical GMRES is performed to compute the shifts */
  ierr = (*ksp->converged)(ksp,0,ksp->rnorm,&ksp->reason,ksp->cnvP);CHKERRQ(ierr);
  while (!ksp->reason) {
    ierr = KSPInitialResidual(ksp,ksp->vec_sol,VEC_TMP,VEC_TMP_MATOP,VEC_V(0),ksp->vec_rhs);CHKERRQ(ierr);
    if ((ksp->pc_side == PC_LEFT) && agmres->r && agmres->DeflPrecond) {
      ierr = KSPDGMRESApplyDeflation_DGMRES(ksp, VEC_V(0), VEC_TMP);CHKERRQ(ierr);
      ierr = VecCopy(VEC_TMP, VEC_V(0));CHKERRQ(ierr);

      agmres->matvecs += 1;
    }
    ierr    = VecNormalize(VEC_V(0),&(ksp->rnorm));CHKERRQ(ierr);
    KSPCheckNorm(ksp,ksp->rnorm);
    res_old = ksp->rnorm; /* Record the residual norm to test if deflation is needed */

    ksp->ops->buildsolution = KSPBuildSolution_AGMRES;

    ierr     = KSPAGMRESCycle(&its,ksp);CHKERRQ(ierr);
    if (ksp->its >= ksp->max_it) {
      if (!ksp->reason) ksp->reason = KSP_DIVERGED_ITS;
      break;
    }
    /* compute the eigenvectors to augment the subspace : use an adaptive strategy */
    res = ksp->rnorm;
    if (!ksp->reason && agmres->neig > 0) {
      test = agmres->max_k * PetscLogReal(ksp->rtol/res) / PetscLogReal(res/res_old); /* estimate the remaining number of steps */
      if ((test > agmres->smv*(ksp->max_it-ksp->its)) || agmres->force) {
        if (!agmres->force && ((test > agmres->bgv*(ksp->max_it-ksp->its)) && ((agmres->r + 1) < agmres->max_neig))) {
          agmres->neig += 1; /* Augment the number of eigenvalues to deflate if the convergence is too slow */
        }
        ierr = KSPDGMRESComputeDeflationData_DGMRES(ksp,&agmres->neig);CHKERRQ(ierr);
      }
    }
    ksp->guess_zero = PETSC_FALSE; /* every future call to KSPInitialResidual() will have nonzero guess */
  }
  ksp->guess_zero = guess_zero; /* restore if user has provided nonzero initial guess */
  PetscFunctionReturn(0);
}
コード例 #16
0
ファイル: extended.cpp プロジェクト: refnum/quesa
static void
ExtendedDirection(LightRef lr, Vector *pos,Vector* dir,Float* dist)
{
    Extended *lp = (Extended*)lr;
	/*
	 * Calculate dir from position to center of
	 * light source.
	 */
	VecSub(lp->pos, *pos, dir);
	*dist = VecNormalize(dir);
}
コード例 #17
0
ファイル: Preview.cpp プロジェクト: Kalamatee/RayStorm
/**********
 * DESCRIPTION:   constructor
 * INPUT:         -
 * OUTPUT:        -
 **********/
PREVIEW::PREVIEW()
{
	line = NULL;

	// light is the vector from O to light
	light.x = 10.f;
	light.y = -10.f;
	light.z = 20.f;
	VecNormalize(&light);

	texture_root = NULL;
}
コード例 #18
0
PetscErrorCode PEPComputeVectors_Schur(PEP pep)
{
  PetscErrorCode ierr;
  PetscInt       n,i;
  Mat            Z;
  Vec            v;
#if !defined(PETSC_USE_COMPLEX)
  Vec            v1;
  PetscScalar    tmp;
  PetscReal      norm,normi;
#endif

  PetscFunctionBegin;
  ierr = DSGetDimensions(pep->ds,&n,NULL,NULL,NULL,NULL);CHKERRQ(ierr);
  ierr = DSVectors(pep->ds,DS_MAT_X,NULL,NULL);CHKERRQ(ierr);
  ierr = DSGetMat(pep->ds,DS_MAT_X,&Z);CHKERRQ(ierr);
  ierr = BVSetActiveColumns(pep->V,0,n);CHKERRQ(ierr);
  ierr = BVMultInPlace(pep->V,Z,0,n);CHKERRQ(ierr);
  ierr = MatDestroy(&Z);CHKERRQ(ierr);

  /* Fix eigenvectors if balancing was used */
  if ((pep->scale==PEP_SCALE_DIAGONAL || pep->scale==PEP_SCALE_BOTH) && pep->Dr && (pep->refine!=PEP_REFINE_MULTIPLE)) {
    for (i=0;i<n;i++) {
      ierr = BVGetColumn(pep->V,i,&v);CHKERRQ(ierr);
      ierr = VecPointwiseMult(v,v,pep->Dr);CHKERRQ(ierr);
      ierr = BVRestoreColumn(pep->V,i,&v);CHKERRQ(ierr);
    }
  }

  /* normalization */
  for (i=0;i<n;i++) {
#if !defined(PETSC_USE_COMPLEX)
    if (pep->eigi[i] != 0.0) {
      ierr = BVGetColumn(pep->V,i,&v);CHKERRQ(ierr);
      ierr = BVGetColumn(pep->V,i+1,&v1);CHKERRQ(ierr);
      ierr = VecNorm(v,NORM_2,&norm);CHKERRQ(ierr);
      ierr = VecNorm(v1,NORM_2,&normi);CHKERRQ(ierr);
      tmp = 1.0 / SlepcAbsEigenvalue(norm,normi);
      ierr = VecScale(v,tmp);CHKERRQ(ierr);
      ierr = VecScale(v1,tmp);CHKERRQ(ierr);
      ierr = BVRestoreColumn(pep->V,i,&v);CHKERRQ(ierr);
      ierr = BVRestoreColumn(pep->V,i+1,&v1);CHKERRQ(ierr);
      i++;
    } else
#endif
    {
      ierr = BVGetColumn(pep->V,i,&v);CHKERRQ(ierr);
      ierr = VecNormalize(v,NULL);CHKERRQ(ierr);
      ierr = BVRestoreColumn(pep->V,i,&v);CHKERRQ(ierr);
    }
  }
  PetscFunctionReturn(0);
}
コード例 #19
0
ファイル: RENDER.C プロジェクト: IvanIoganson/sum2014
/* ‘ункци¤ преобразовани¤ из мировой системы коорлинат в кадр.
 * ј–√”ћ≈Ќ“џ:
 *   - исходна¤ точка:
 *       VEC Loc, VEC At, VEC Upaprox;
 * ¬ќ«¬–јўј≈ћќ≈ «Ќј„≈Ќ»≈:
 *   (MATR) ћатрица преоброзаваний камеры.
 */
MATR II2_VieverCamera( VEC Loc, VEC At, VEC Upaprox )
{
  VEC Right, Up, Dir;
  MATR r;

  Dir = VecNormalize(VecSubVec(At, Loc));
  Right = VecNormalize(VecCrossVec(Dir, Upaprox));
  Up = VecCrossVec(Right, Dir);

  r.A[0][0] = Right.X; r.A[0][1] = Up.X; r.A[0][2] = -Dir.X; r.A[0][3] = 0;
  r.A[1][0] = Right.Y; r.A[1][1] = Up.Y; r.A[1][2] = -Dir.Y; r.A[1][3] = 0;
  r.A[2][0] = Right.Z; r.A[2][1] = Up.Z; r.A[2][2] = -Dir.Z; r.A[2][3] = 0;
  r.A[3][0] = -VecDotVec(Loc, Right);
  r.A[3][1] = -VecDotVec(Loc, Up);
  r.A[3][2] = VecDotVec(Loc, Dir);
  r.A[3][3] = 1;


  /*r.A[0][0] = Right.X;
  r.A[1][0] = Up.X;
  r.A[2][0] = -Dir.X;
  r.A[3][0] = 0;
     
  r.A[0][1] = Right.Y;
  r.A[1][1] = Up.Y;
  r.A[2][1] = -Dir.Y;
  r.A[3][1] = 0;
     
  r.A[0][2] = Right.Z;
  r.A[1][2] = Up.Z;
  r.A[2][2] = -Dir.Z;
  r.A[3][2] = 0;
     
  r.A[0][3] = -VecDotVec(Loc, Right);
  r.A[1][3] = -VecDotVec(Loc, Up);
  r.A[2][3] = -VecDotVec(Loc, Dir);
  r.A[3][3] = 1;*/

  return r;
} /* End of 'Ani->WorldToScreen' function */
コード例 #20
0
ファイル: RENDER.C プロジェクト: IvanIoganson/sum2014
/* Camera rotation by camera-axes-dir function.
* ARGUMENTS:
*   - Angle:
*       DBL Angle;
* RETURNS: None.
*/
VOID II2_RndCameraRotateDir( ii2CAMERA *Cam, DBL Angle )
{
  MATR RotMat;

  Cam->Dir = VecSubVec(Cam->At, Cam->Loc);
  Cam->Right = VecCrossVec(VecNormalize(Cam->Dir), Cam->Up);
  II2_RndCameraNormalize(Cam);

  RotMat = II2_RndCameraGetMatrix(Cam);
  RotMat = MatrMulMatr(MatrRotateX(Angle), RotMat);

  Cam->At = VecAddVec(Cam->Loc, VecSet(RotMat.A[0][0], RotMat.A[0][1], RotMat.A[0][2]));
}  /* End of 'II2_RndCameraRotateDir' funciton */
コード例 #21
0
ファイル: iguess.c プロジェクト: fengyuqi/petsc
PetscErrorCode  KSPFischerGuessUpdate_Method1(KSPFischerGuess_Method1 *itg,Vec x)
{
  PetscReal      norm;
  PetscErrorCode ierr;
  int            curl = itg->curl,i;

  PetscFunctionBegin;
  PetscValidHeaderSpecific(x,VEC_CLASSID,2);
  PetscValidPointer(itg,3);
  if (curl == itg->maxl) {
    ierr      = KSP_MatMult(itg->ksp,itg->mat,x,itg->btilde[0]);CHKERRQ(ierr);
    ierr      = VecNormalize(itg->btilde[0],&norm);CHKERRQ(ierr);
    ierr      = VecCopy(x,itg->xtilde[0]);CHKERRQ(ierr);
    ierr      = VecScale(itg->xtilde[0],1.0/norm);CHKERRQ(ierr);
    itg->curl = 1;
  } else {
    if (!curl) {
      ierr = VecCopy(x,itg->xtilde[curl]);CHKERRQ(ierr);
    } else {
      ierr = VecWAXPY(itg->xtilde[curl],-1.0,itg->guess,x);CHKERRQ(ierr);
    }

    ierr = KSP_MatMult(itg->ksp,itg->mat,itg->xtilde[curl],itg->btilde[curl]);CHKERRQ(ierr);
    ierr = VecMDot(itg->btilde[curl],curl,itg->btilde,itg->alpha);CHKERRQ(ierr);
    for (i=0; i<curl; i++) itg->alpha[i] = -itg->alpha[i];
    ierr = VecMAXPY(itg->btilde[curl],curl,itg->alpha,itg->btilde);CHKERRQ(ierr);
    ierr = VecMAXPY(itg->xtilde[curl],curl,itg->alpha,itg->xtilde);CHKERRQ(ierr);

    ierr = VecNormalize(itg->btilde[curl],&norm);CHKERRQ(ierr);
    if (norm) {
      ierr = VecScale(itg->xtilde[curl],1.0/norm);CHKERRQ(ierr);
      itg->curl++;
    } else {
      ierr = PetscInfo(itg->ksp,"Not increasing dimension of Fischer space because new direction is identical to previous\n");CHKERRQ(ierr);
    }
  }
  PetscFunctionReturn(0);
}
コード例 #22
0
ファイル: ex62.c プロジェクト: hsahasra/petsc-magma-dense-mat
PetscErrorCode CreatePressureNullSpace(DM dm, AppCtx *user, MatNullSpace *nullSpace)
{
  Vec            vec, localVec;
  PetscErrorCode ierr;

  PetscFunctionBeginUser;
  ierr = DMGetGlobalVector(dm, &vec);CHKERRQ(ierr);
  ierr = DMGetLocalVector(dm, &localVec);CHKERRQ(ierr);
  ierr = VecSet(vec,  0.0);CHKERRQ(ierr);
  /* Put a constant in for all pressures
     Could change this to project the constant function onto the pressure space (when that is finished) */
  {
    PetscSection section;
    PetscInt     pStart, pEnd, p;
    PetscScalar  *a;

    ierr = DMGetDefaultSection(dm, &section);CHKERRQ(ierr);
    ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr);
    ierr = VecGetArray(localVec, &a);CHKERRQ(ierr);
    for (p = pStart; p < pEnd; ++p) {
      PetscInt fDim, off, d;

      ierr = PetscSectionGetFieldDof(section, p, 1, &fDim);CHKERRQ(ierr);
      ierr = PetscSectionGetFieldOffset(section, p, 1, &off);CHKERRQ(ierr);
      for (d = 0; d < fDim; ++d) a[off+d] = 1.0;
    }
    ierr = VecRestoreArray(localVec, &a);CHKERRQ(ierr);
  }
  ierr = DMLocalToGlobalBegin(dm, localVec, INSERT_VALUES, vec);CHKERRQ(ierr);
  ierr = DMLocalToGlobalEnd(dm, localVec, INSERT_VALUES, vec);CHKERRQ(ierr);
  ierr = DMRestoreLocalVector(dm, &localVec);CHKERRQ(ierr);
  ierr = VecNormalize(vec, NULL);CHKERRQ(ierr);
  if (user->debug) {
    ierr = PetscPrintf(PetscObjectComm((PetscObject)dm), "Pressure Null Space\n");CHKERRQ(ierr);
    ierr = VecView(vec, PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
  }
  ierr = MatNullSpaceCreate(PetscObjectComm((PetscObject)dm), PETSC_FALSE, 1, &vec, nullSpace);CHKERRQ(ierr);
  ierr = DMRestoreGlobalVector(dm, &vec);CHKERRQ(ierr);
  /* New style for field null spaces */
  {
    PetscObject  pressure;
    MatNullSpace nullSpacePres;

    ierr = DMGetField(dm, 1, &pressure);CHKERRQ(ierr);
    ierr = MatNullSpaceCreate(PetscObjectComm(pressure), PETSC_TRUE, 0, NULL, &nullSpacePres);CHKERRQ(ierr);
    ierr = PetscObjectCompose(pressure, "nullspace", (PetscObject) nullSpacePres);CHKERRQ(ierr);
    ierr = MatNullSpaceDestroy(&nullSpacePres);CHKERRQ(ierr);
  }
  PetscFunctionReturn(0);
}
コード例 #23
0
ファイル: RENDER.C プロジェクト: svyatoslav777/sum2014
/* Camera rotation by camera-axes-dir function.
* ARGUMENTS:
*   - Angle:
*       DBL Angle;
* RETURNS: None.
*/
VOID RK2_RndCameraRotateDir( rk2CAMERA *Cam, DBL Angle )
{
  rk2MATR4x4 RotMat;

  Cam->Dir = VecSubVec(Cam->At, Cam->Loc);
  Cam->Right = VecCrossVec(VecNormalize(Cam->Dir), Cam->Up);
  RK2_RndCameraNormalize(Cam);

  RotMat = RK2_RndCameraGetMatrix(Cam);
  RotMat = MatrMultMatr(MatrRotateX(MatrDefault(), Angle), RotMat);

  RK2_RndCameraSet(Cam, Cam->Loc,                                               /* Location */
    VecSumVec(Cam->Loc,
    VecSet(RotMat.A[0][0], RotMat.A[0][1], RotMat.A[0][2])),                    /* At */
    Cam->Up);                                                                   /* Up */
}  /* End of 'RK2_RndCameraRotateDir' funciton */
コード例 #24
0
ファイル: extended.cpp プロジェクト: refnum/quesa
/*
 * Compute intensity ('color') of extended light source 'lp' from 'pos'.
 */
static int
ExtendedIntens(
        LightRef        lr, 
        Color           *lcolor, 
        ShadowCache     *cache,
        Ray             *ray,
        Float           /*dist*/, 
        int             noshadow,
        Color           *color)
{
    Extended        *lp = (Extended*)lr;
	Float jit, vpos, upos, lightdist;
	Ray newray;
	Vector Uaxis, Vaxis, ldir;

	if (noshadow) {
		*color = *lcolor;
		return TRUE;
	}

	newray = *ray;
	/*
	 * Determinte two orthoganal vectors that lay in the plane
	 * whose normal is defined by the vector from the center
	 * of the light source to the point of intersection and
	 * passes through the center of the light source.
 	 */
	VecSub(lp->pos, ray->pos, &ldir);
	VecCoordSys(&ldir, &Uaxis, &Vaxis);

	jit = 2. * lp->radius * Sampling.spacing;

	/*
	 * Sample a single point, determined by SampleNumber,
	 * on the extended source.
	 */
	vpos = -lp->radius + (ray->sample % Sampling.sidesamples)*jit;
	upos = -lp->radius + (ray->sample / Sampling.sidesamples)*jit;
	vpos += nrand() * jit;
	upos += nrand() * jit;
	VecComb(upos, Uaxis, vpos, Vaxis, &newray.dir);
	VecAdd(ldir, newray.dir, &newray.dir);
	lightdist = VecNormalize(&newray.dir);

	return !Shadowed(color, lcolor, cache, &newray,
		lightdist, noshadow);
}
コード例 #25
0
ファイル: vertex_util_impl.hpp プロジェクト: bsumirak/ugcore
void CalculateVertexNormal(vector3& nOut, Grid& grid, Vertex* vrt, TAAPosVRT& aaPos)
{
//	set all normal to zero
	nOut = vector3(0, 0, 0);

//	loop through all associated faces, calculate their normal and add them to thee normal
	Grid::AssociatedFaceIterator iterEnd = grid.associated_faces_end(vrt);
	for(Grid::AssociatedFaceIterator iter = grid.associated_faces_begin(vrt);
		iter != iterEnd; iter++)
	{
		vector3 vN;
		CalculateNormal(vN, *iter, aaPos);
		VecAdd(nOut, nOut, vN);
	}

	VecNormalize(nOut, nOut);
}
コード例 #26
0
ファイル: plane.cpp プロジェクト: refnum/quesa
/*
 * create plane primitive
 */
Plane *
PlaneCreate(Vector *pos,Vector *norm)
{
	Plane *plane;
	Vector tmpnrm;

	tmpnrm = *norm;
	if (VecNormalize(&tmpnrm) == 0.) {
		RLerror(RL_WARN, "Degenerate plane normal.\n");
		return (Plane *)NULL;
	}
	plane = (Plane *)share_malloc(sizeof(Plane));
	plane->norm = tmpnrm;
	plane->pos = *pos;
	plane->d = dotp(&plane->norm, pos);

	return plane;
}
コード例 #27
0
PetscErrorCode PEPComputeVectors_Indefinite(PEP pep)
{
  PetscErrorCode ierr;
  PetscInt       n,i;
  Mat            Z;
  Vec            v;
#if !defined(PETSC_USE_COMPLEX)
  Vec            v1;
  PetscScalar    tmp;
  PetscReal      norm,normi;
#endif

  PetscFunctionBegin;
  ierr = DSGetDimensions(pep->ds,&n,NULL,NULL,NULL,NULL);CHKERRQ(ierr);
  ierr = DSVectors(pep->ds,DS_MAT_X,NULL,NULL);CHKERRQ(ierr);
  ierr = DSGetMat(pep->ds,DS_MAT_X,&Z);CHKERRQ(ierr);
  ierr = BVSetActiveColumns(pep->V,0,n);CHKERRQ(ierr);
  ierr = BVMultInPlace(pep->V,Z,0,n);CHKERRQ(ierr);
  ierr = MatDestroy(&Z);CHKERRQ(ierr);

  /* normalization */
  for (i=0;i<n;i++) {
#if !defined(PETSC_USE_COMPLEX)
    if (pep->eigi[i] != 0.0) {
      ierr = BVGetColumn(pep->V,i,&v);CHKERRQ(ierr);
      ierr = BVGetColumn(pep->V,i+1,&v1);CHKERRQ(ierr);
      ierr = VecNorm(v,NORM_2,&norm);CHKERRQ(ierr);
      ierr = VecNorm(v1,NORM_2,&normi);CHKERRQ(ierr);
      tmp = 1.0 / SlepcAbsEigenvalue(norm,normi);
      ierr = VecScale(v,tmp);CHKERRQ(ierr);
      ierr = VecScale(v1,tmp);CHKERRQ(ierr);
      ierr = BVRestoreColumn(pep->V,i,&v);CHKERRQ(ierr);
      ierr = BVRestoreColumn(pep->V,i+1,&v1);CHKERRQ(ierr);
      i++;
    } else
#endif
    {
      ierr = BVGetColumn(pep->V,i,&v);CHKERRQ(ierr);
      ierr = VecNormalize(v,NULL);CHKERRQ(ierr);
      ierr = BVRestoreColumn(pep->V,i,&v);CHKERRQ(ierr);
    }
  }
  PetscFunctionReturn(0);
}
コード例 #28
0
ファイル: CAMERA.CPP プロジェクト: Kalamatee/RayStorm
/*************
 * DESCRIPTION:   Initialize Camera (MUST be called if parameters changed)
 * INPUT:         none
 * OUTPUT:        none
 *************/
void CAMERA::InitCamera()
{
	float lookdist, magnitude;
	VECTOR dir;

	VecSub(&lookp, &pos, &dir);
	firstray = dir;

	lookdist = VecNormalize(&dir);
	VecNormCross(&dir, &vup, &scrni);
	VecNormCross(&scrni, &dir, &scrnj);

	magnitude = -2.f*lookdist * (float)tan(0.5f*hfov*PI_180)/xres;

	VecScale(magnitude, &scrni, &scrnx);
	magnitude = 2.f*lookdist * (float)tan(0.5f*vfov*PI_180)/yres;

	VecScale(magnitude, &scrnj, &scrny);

	firstray.x -= 0.5f*yres*scrny.x + 0.5f*xres*scrnx.x;
	firstray.y -= 0.5f*yres*scrny.y + 0.5f*xres*scrnx.y;
	firstray.z -= 0.5f*yres*scrny.z + 0.5f*xres*scrnx.z;

	DoFData.xres = xres;
	DoFData.yres = yres;
	DoFData.left = left;
	DoFData.top = top;
	DoFData.right = right;
	DoFData.bottom = bottom;
	DoFData.focaldist = focaldist;
	DoFData.hfov = hfov*PI/180.0f;
	DoFData.vfov = vfov*PI/180.0f;
	DoFData.aperture = 2*aperture;
	DoFData.samples = 7;

	DoFData.flags = 0;
	if ((flags & HIDDENAREA) == HIDDENAREA)
		DoFData.flags = DoFHidden;
	if ((flags & ACCELERATE) == ACCELERATE)
		DoFData.flags |= DoFAccelerate;

	DoF.Init(&DoFData);
}
コード例 #29
0
ファイル: rotate.c プロジェクト: AleksandraSimonova/SUM2016
/* Rotate vector function.
 * ARGUMENTS:
 *   - vector to be rotated:
 *       VEC P;
 *   - vector rotated around:
 *       VEC A;
 *   - rotation angle in degree:
 *       DBL Angle;
 * RETURNS:
 *   (VEC) rotated vector value.
 */
VEC Rotate( VEC P, VEC A, DBL Angle )
{
  DBL si, co;

  A = VecNormalize(A);

  Angle *= PI / 180;
  si = sin(Angle);
  co = cos(Angle);

  return VecSet(P.X * (co + A.X * A.X * (1 - co)) +
                P.Y * (A.Y * A.X * (1 - co) + A.Z * si) +
                P.Z * (A.Z * A.X * (1 - co) - A.Y * si),
                P.X * (A.X * A.Y * (1 - co) - A.Z * si) +
                P.Y * (co + A.Y * A.Y * (1 - co)) + 
                P.Z * (A.Z * A.Y * (1 - co) + A.X * si),
                P.X * (A.X * A.Z * (1 - co) + A.Y * si) +
                P.Y * (A.Y * A.Z * (1 - co) - A.X * si) + 
                P.Z * (co + A.Z * A.Z * (1 - co)));
} /* End of 'Rotate' function */
コード例 #30
0
/*@
   EPSGetInvariantSubspace - Gets an orthonormal basis of the computed invariant
   subspace.

   Not Collective, but vectors are shared by all processors that share the EPS

   Input Parameter:
.  eps - the eigensolver context

   Output Parameter:
.  v - an array of vectors

   Notes:
   This function should be called after EPSSolve() has finished.

   The user should provide in v an array of nconv vectors, where nconv is
   the value returned by EPSGetConverged().

   The first k vectors returned in v span an invariant subspace associated
   with the first k computed eigenvalues (note that this is not true if the
   k-th eigenvalue is complex and matrix A is real; in this case the first
   k+1 vectors should be used). An invariant subspace X of A satisfies Ax
   in X for all x in X (a similar definition applies for generalized
   eigenproblems).

   Level: intermediate

.seealso: EPSGetEigenpair(), EPSGetConverged(), EPSSolve()
@*/
PetscErrorCode EPSGetInvariantSubspace(EPS eps,Vec *v)
{
  PetscErrorCode ierr;
  PetscInt       i;

  PetscFunctionBegin;
  PetscValidHeaderSpecific(eps,EPS_CLASSID,1);
  PetscValidPointer(v,2);
  PetscValidHeaderSpecific(*v,VEC_CLASSID,2);
  EPSCheckSolved(eps,1);
  if (!eps->ishermitian && eps->state==EPS_STATE_EIGENVECTORS) SETERRQ(PetscObjectComm((PetscObject)eps),PETSC_ERR_ARG_WRONGSTATE,"EPSGetInvariantSubspace must be called before EPSGetEigenpair,EPSGetEigenvector,EPSComputeRelativeError or EPSComputeResidualNorm");
  for (i=0;i<eps->nconv;i++) {
    ierr = BVCopyVec(eps->V,i,v[i]);CHKERRQ(ierr);
    if (eps->balance!=EPS_BALANCE_NONE && eps->D) {
      ierr = VecPointwiseDivide(v[i],v[i],eps->D);CHKERRQ(ierr);
      ierr = VecNormalize(v[i],NULL);CHKERRQ(ierr);
    }
  }
  PetscFunctionReturn(0);
}