当前位置: 首页>>代码示例>>C++>>正文


C++ Hit函数代码示例

本文整理汇总了C++中Hit函数的典型用法代码示例。如果您正苦于以下问题:C++ Hit函数的具体用法?C++ Hit怎么用?C++ Hit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Hit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: intersect

    Hit intersect(const Ray& ray)
    {
        float3 diff = ray.origin - center;
        double a = ray.dir.dot(ray.dir);
        double b = diff.dot(ray.dir) * 2.0;
        double c = diff.dot(diff) - radius * radius;
 
        double discr = b * b - 4.0 * a * c;
        if ( discr < 0 ) 
            return Hit();
        double sqrt_discr = sqrt( discr );
        double t1 = (-b + sqrt_discr)/2.0/a;
        double t2 = (-b - sqrt_discr)/2.0/a;
 
		float t = (t1<t2)?t1:t2;
		if(t < 0)
			t = (t1<t2)?t2:t1;
		if (t < 0)
            return Hit();

		Hit h;
		h.t = t;
		h.material = material;
		h.position = ray.origin + ray.dir * t;
		h.normal = h.position - center;
		h.normal.normalize();

		return h;

    }
开发者ID:emeersman,项目名称:raytracing,代码行数:30,代码来源:main.cpp

示例2: Hit

Hit RayTracer::rayIntersectTriangles(const Vec3f& orig, const Vec3f& dir, int startPrim, int endPrim) const
{
	float umin = 0.0f, vmin = 0.0f, tmin = 1.0f;
	int imin = -1;

	// naive loop over all triangles
	for ( int i = startPrim; i <= endPrim; ++i )
	{
		float t = std::numeric_limits<float>::max(), u, v;
		if ( intersect_triangle1( &orig.x,
								  &dir.x,
								  &(*m_triangles)[i].m_vertices[0]->x,
								  &(*m_triangles)[i].m_vertices[1]->x,
								  &(*m_triangles)[i].m_vertices[2]->x,
								  t, u, v ) )
		{
			if ( t > 0.0f && t < tmin )
			{
				imin = i;
				tmin = t;
				umin = u;
				vmin = v;
			}
		}
	}

	if ( imin != -1 )
		return Hit(&(*m_triangles)[imin], orig + tmin*dir, tmin, umin, vmin);
	else
		return Hit(NULL);
}
开发者ID:Zerphed,项目名称:advanced-computer-graphics-course,代码行数:31,代码来源:RayTracer.cpp

示例3: PrintHandBeginsMessage

// Main function that executes the blackjack game with a new player
void CBlackJack::StartGameWithNewPlayer()
{
  bool playAgain = true;
  PrintHandBeginsMessage(Player.GetName(), Player.GetChips());

  while(playAgain)
    {
      // Ask player for a wager. It returns true if valid wager is returned
      if(GetSetPlayerWager())
	{
	  // Hit the player twice 
	  Hit(Player);
	  Hit(Player);
	  DEBUG_LOG (4, "Hit Player twice");
	  if(Player.IsBlackjack())
	    PrintResult(PLAYER_BLACKJACK, Player.GetName(), 0);

	  // Hit dealer twice
	  Hit(Dealer);
	  Hit(Dealer);
	  DEBUG_LOG (4, "Hit Dealer twice");
	  if(Dealer.IsBlackjack())
	    PrintResult(DEALER_BLACKJACK, Dealer.GetName(), 0);

	  // If dealer or player got blackjack or busted, then game can end here. 
	  // Else, continue playing
	
	  if(!Player.IsBlackjack() && !Player.IsBusted()
	     && !Dealer.IsBlackjack() && !Dealer.IsBusted())
	    {
	      // Display scores
	      Player.PrintScore();
	      Dealer.PrintScore();

	      // Give playing options to player and play
	      PlayerOptionsAndPlay();
	      // Unless player is busted, continue hitting the dealer
	      if(!Player.IsBusted())
		DealerOptionsAndPlay();				
	    }
			
	  // At the end, check for winner, and calculate payout
	  CheckWinnerCalculatePayout();
	}

      // Ask player for another game
      playAgain = EndOption();

    } // end while playAgain

  // Add player's score to high scores
  DEBUG_LOG(1, "Remaining chips " << Player.GetChips());
  HighScoreHandler.AddNewScore(Player.GetName(), Player.GetChips());

  // Reset remaining chips with player
  Player.Reset();

  PrintHandQuitMessage();
}
开发者ID:fenichawla,项目名称:BlackjackGame,代码行数:60,代码来源:Blackjack.cpp

示例4: rayVsTriangle

Hit RenderDevice::rayTraceNode(const Ray &ray, u32 nodeIndex)
{
    // Handle Leaf
    if(nodes[nodeIndex].isLeaf())
    {
        f32 hit;
        f32 closestHit = MAXFLOAT;
        u32 triangleIndex=0;
        vec3 hitBaryCoords;
        vec3 baryCoords;

        for(u32 i=nodes[nodeIndex].getIndex(); i < nodes[nodeIndex].getIndex()+nodes[nodeIndex].getSize(); ++i)
        {
            if(i != ray.originID) {
                hit = rayVsTriangle(ray,faces[i],hitBaryCoords);
                if(hit > 0.0 && hit < closestHit)
                {
                    closestHit = hit;
                    triangleIndex = i;
                    baryCoords = hitBaryCoords;
                }
            }
        }
        if(closestHit < MAXFLOAT)
        {
            return Hit(closestHit, triangleIndex, baryCoords);
        }
    }
    else
    {
        Hit leaf_left_hit(MAXFLOAT,0);
        Hit leaf_right_hit(MAXFLOAT,0);

		if(rayVsAABB(ray,nodes[nodes[nodeIndex].getLeft()].aabb) < MAXFLOAT) {
            leaf_left_hit = rayTraceNode(ray,nodes[nodeIndex].getLeft());
		}
		if(rayVsAABB(ray,nodes[nodes[nodeIndex].getRight()].aabb) < MAXFLOAT) {
            leaf_right_hit = rayTraceNode(ray,nodes[nodeIndex].getRight());
		}

		if(leaf_left_hit < leaf_right_hit) {
			return leaf_left_hit;
		} else if (leaf_right_hit.distance < MAXFLOAT) {
			return leaf_right_hit;
		}
    }
    return Hit(MAXFLOAT,0);
}
开发者ID:eriha891,项目名称:RTFW,代码行数:48,代码来源:RenderDevice.cpp

示例5: ToBasePlayer

//-----------------------------------------------------------------------------
// Animation event handlers
//-----------------------------------------------------------------------------
void CWeaponZMFists::HandleAnimEventMeleeHit( CBaseCombatCharacter *pOperator )
{
	//do the trace stuff here so we can pass it to the Hit() function
	trace_t traceHit;

	// Try a ray
	CBasePlayer *pOwner = ToBasePlayer(pOperator);
	if ( !pOwner )
		return;

	Vector swingStart = pOwner->Weapon_ShootPosition( );
	Vector forward;

	pOwner->EyeVectors( &forward, NULL, NULL );

	Vector swingEnd = swingStart + forward * GetRange();

#ifndef CLIENT_DLL
	CHL2MP_Player *pPlayer = ToHL2MPPlayer( GetPlayerOwner() );
	// Move other players back to history positions based on local player's lag
	lagcompensation->StartLagCompensation( pPlayer, pPlayer->GetCurrentCommand() );
#endif
	UTIL_TraceLine( swingStart, swingEnd, MASK_SHOT_HULL, pOwner, COLLISION_GROUP_NONE, &traceHit );
	Hit( traceHit, ACT_VM_HITCENTER);
#ifndef CLIENT_DLL
	// Move other players back to history positions based on local player's lag
	lagcompensation->FinishLagCompensation( pPlayer );
#endif
}
开发者ID:TotallyMehis,项目名称:ZM-Updated,代码行数:32,代码来源:weapon_zm_fists.cpp

示例6: TraceParams

AActor* USCarryObjectComponent::GetActorInView()
{
	APawn* PawnOwner = Cast<APawn>(GetOwner());
	AController* Controller = PawnOwner->Controller;
	if (Controller == nullptr)
	{
		return nullptr;
	}

	FVector CamLoc;
	FRotator CamRot;
	Controller->GetPlayerViewPoint(CamLoc, CamRot);

	const FVector TraceStart = CamLoc;
	const FVector Direction = CamRot.Vector();
	const FVector TraceEnd = TraceStart + (Direction * MaxPickupDistance);

	FCollisionQueryParams TraceParams(TEXT("TraceActor"), true, PawnOwner);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = false;
	TraceParams.bTraceComplex = false;

	FHitResult Hit(ForceInit);
	GetWorld()->LineTraceSingle(Hit, TraceStart, TraceEnd, ECC_Visibility, TraceParams);

	//DrawDebugLine(GetWorld(), TraceStart, TraceEnd, FColor::Red, false, 1.0f);

	return Hit.GetActor();
}
开发者ID:Magicmay,项目名称:EpicSurvivalGameSeries,代码行数:29,代码来源:SCarryObjectComponent.cpp

示例7: Hit

Hit Plane::intersect(const Ray &ray)
{
	double denom, t, denomAbs;
	Point pos;
	Vector N, vec10 = position0 - position1, vec12 = position2 - position1;
	// calculate normal of plane
	N = vec10.cross(vec12);
	N.normalize();
	
	// calculate denominator and calculate the absolute value
	denom = N.dot(ray.D);
	if (denom < 0){
		denomAbs = denom * -1;
	} else{
		denomAbs = denom;
	}
	// if the absolute value < epsilon, no hit
	if (denomAbs > 1e-6) {
		// calculate distance to possible intersection
		t = (position0-ray.O).dot(N)/denom;
		// point of intersection
		pos = ray.O + ray.D*t;
		
		// if t is negative, no intersection
		if (t<0 )  return Hit::NO_HIT();
		// if the plane is set to finite, the intersection is compared to min and max coordinates. If it is too big or small, not hit
		#ifdef FINITE
		if(!(pos.x >= minX && pos.x <= maxX) || !(pos.y >= minY && pos.y <= maxY) || !(pos.z >= minZ && pos.z <= maxZ)) return Hit::NO_HIT();
		#endif
	}else{
		return Hit::NO_HIT();
	}
    return Hit(t,N);
}
开发者ID:DanielsWrath,项目名称:ComputerGraphics,代码行数:34,代码来源:plane.cpp

示例8: Hit

void Player::HandleCollision(Sprite* sprite, Level* level) {
    ActionType hitAction;
    
    if (currAction == STAND) {
        hitAction = prevAction;
    } else {
        hitAction = currAction;
    }
    
    if (attacking) {
        sound.setBuffer(hit);
        sprite->Hit(hitAction, level);
    }
    else {
        if (dynamic_cast<Princess*>(sprite)) {
            sound.setBuffer(kiss);
            level->SetStatus(Level::COMPLETE);
        } else {
            sound.setBuffer(no);
            Hit(sprite->GetAction(), level);
        }
    }
    
    sound.play();
}
开发者ID:danielbreves,项目名称:HeroMustSavePrincess,代码行数:25,代码来源:Player.cpp

示例9: TraceParams

AInventoryItem* APlayerCharacter::GetUsableItemInView()
{
	FVector camLoc;
	FRotator camRot;

	if (Controller == NULL)
		return NULL;

	Controller->GetPlayerViewPoint(camLoc, camRot);
	const FVector start_trace = camLoc;
	const FVector direction = camRot.Vector();
	const FVector end_trace = start_trace + (direction * MaxUseDist);

	FCollisionQueryParams TraceParams(FName(TEXT("")), true, this);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = false;
	TraceParams.bTraceComplex = true;

	FHitResult Hit(ForceInit);
	GetWorld()->LineTraceSingleByChannel(Hit, start_trace, end_trace, ECollisionChannel::ECC_EngineTraceChannel1, TraceParams);

	//DrawDebugLine(GetWorld(), start_trace, end_trace, FColor(255, 0, 0), false, -1, 0, 12.333);

	return Cast<AInventoryItem>(Hit.GetActor());
}
开发者ID:jackdurnford,项目名称:MidnightSnag,代码行数:25,代码来源:PlayerCharacter.cpp

示例10: TraceParams

AUsableActor* AXtremeJanitorCharacter::GetUsableInView()
{
	FVector CamLoc;
	FRotator CamRot;

	if (Controller == NULL)
		return NULL;

	Controller->GetPlayerViewPoint(CamLoc, CamRot);
	const FVector TraceStart = CamLoc;
	const FVector Direction = CamRot.Vector();
	const FVector TraceEnd = TraceStart + (Direction * MaxUseDistance);

	FCollisionQueryParams TraceParams(FName(TEXT("TraceUsableActor")), true, this);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = false;
	TraceParams.bTraceComplex = true;

	FHitResult Hit(ForceInit);
	GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, ECC_Visibility, TraceParams);

	// Cette ligne sera en commentaire plus tard
	DrawDebugLine(GetWorld(), TraceStart, TraceEnd, FColor::Red, false, 1.0f);

	return Cast<AUsableActor>(Hit.GetActor());
}
开发者ID:MelBeee,项目名称:UE4_FinalProject_A15,代码行数:26,代码来源:XtremeJanitorCharacter.cpp

示例11: GetMap

void Fire::Process()
{
    auto enm = GetMap()->GetEnemyHolder()->GetNearest(this->pixel_x(), this->pixel_y(), 7, 
                                                     [this](Enemy* e) 
        /*I AM KING OF SPACES*/                      {
                                                         return !e->IsRocketFriend()
                                                                && e != this;
                                                     });

    ++length_;

    if (enm != nullptr)
    {
        ProcessSpeed(enm->pixel_x(), enm->pixel_y(), 1);
        if ((abs(enm->pixel_x() - pixel_x()) + abs(enm->pixel_y() - pixel_y())) < 48)
        {
            enm->Hit(1);
        }
    }
    ProcessMove();

    state_w_ = (length_ / 5) % 6;

    if (length_ > 30)
        GetMap()->GetEnemyHolder()->AddToDelete(this);
}
开发者ID:kremius,项目名称:space-dworf-strategy,代码行数:26,代码来源:enemy.cpp

示例12:

const HitList & QueryConnector::evaluateHits(HitList & hl) const
{
    if (evaluate()) {
        hl.push_back(Hit(1, 0, 0, 1));
    }
    return hl;
}
开发者ID:songhtdo,项目名称:vespa,代码行数:7,代码来源:query.cpp

示例13: GetInputAxisValue

void ATP_TwinStickPawn::Tick(float DeltaSeconds)
{
	// Find movement direction
	const float ForwardValue = GetInputAxisValue(MoveForwardBinding);
	const float RightValue = GetInputAxisValue(MoveRightBinding);

	// Clamp max size so that (X=1, Y=1) doesn't cause faster movement in diagonal directions
	const FVector MoveDirection = FVector(ForwardValue, RightValue, 0.f).GetClampedToMaxSize(1.0f);

	// Calculate  movement
	const FVector Movement = MoveDirection * MoveSpeed * DeltaSeconds;

	// If non-zero size, move this actor
	if (Movement.SizeSquared() > 0.0f)
	{
		const FRotator NewRotation = Movement.Rotation();
		FHitResult Hit(1.f);
		RootComponent->MoveComponent(Movement, NewRotation, true, &Hit);
		
		if (Hit.IsValidBlockingHit())
		{
			const FVector Normal2D = Hit.Normal.GetSafeNormal2D();
			const FVector Deflection = FVector::VectorPlaneProject(Movement, Normal2D) * (1.f - Hit.Time);
			RootComponent->MoveComponent(Deflection, NewRotation, true);
		}
	}
	
	// Create fire direction vector
	const float FireForwardValue = GetInputAxisValue(FireForwardBinding);
	const float FireRightValue = GetInputAxisValue(FireRightBinding);
	const FVector FireDirection = FVector(FireForwardValue, FireRightValue, 0.f);

	// Try and fire a shot
	FireShot(FireDirection);
}
开发者ID:colwalder,项目名称:unrealengine,代码行数:35,代码来源:TP_TwinStickPawn.cpp

示例14: Hit

Hit BVH::BVHLeaf::trace(const AABB_Ray & aabb_ray, const Ray & ray, Amount minT)
{
   if(object.bounds.intersect(aabb_ray)){
      return object.geometry->intersectTransform(ray,minT);
   }
   return Hit(ray);
}
开发者ID:kyle-piddington,项目名称:PovTracer,代码行数:7,代码来源:BVH.cpp

示例15: Hit

// does the recursive (shadow rays & recursive/glossy rays) work
Vec3f RayTracer::TraceRay(const Ray &ray, Hit &hit, int bounce_count) const
{
        hit = Hit();
        bool intersect = CastRay(ray,hit,false);

        Vec3f answer(args->background_color_linear);

        if (intersect == true) {
                const Material *m = hit.getMaterial();
                assert (m != NULL);

                // rays coming from the light source are set to white, don't bother to ray trace further.
                if (m->getEmittedColor().Length() > 0.001) {
                        answer = Vec3f(1,1,1);
                } else {
                        // ambient light
                        answer = args->ambient_light_linear *
                                 m->getDiffuseColor(hit.get_s(),hit.get_t());

                        // Shadows
                        answer += shadows(ray, hit);

                        // Reflections
                        Vec3f reflectiveColor = m->getReflectiveColor();
                        double roughness = m->getRoughness();
                        if (bounce_count > 0 && reflectiveColor.Length() > MIN_COLOR_LEN) {
                        	answer += reflectiveColor * reflections(ray, hit, bounce_count, roughness);
                        }
                }
        }

        return answer;
}
开发者ID:linkinpark342,项目名称:parashader,代码行数:34,代码来源:raytracer.cpp


注:本文中的Hit函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。