您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ tanf函数代码示例

51自学网 2021-06-03 08:40:16
  C++
这篇教程C++ tanf函数代码示例写得很实用,希望能帮到您。

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

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

示例1: Orient

void Frustum::Enclose(const Frustum& other){    vec3 n = glm::normalize(other._origin - other._at);    vec3 u = glm::normalize(cross(other._up, n));    vec3 v = glm::normalize(cross(n, u));    if (_type == Projection::PERSPECTIVE)        Orient(_origin, other.GetCenter(), _up);    mat4 m = GetViewMatrix();    vec3 p[8];    if (other._type == Projection::PERSPECTIVE)    {        float dy = other._near * tanf(radians(other._fovy) / 2.0f);        float dx = other._ar * dy;        vec3 c = other._origin - n * other._near;        p[0] = c + u * dx + v * dy;        p[1] = c - u * dx + v * dy;        p[2] = c - u * dx - v * dy;        p[3] = c + u * dx - v * dy;        dy = other._far * tanf(glm::radians(other._fovy) / 2.0f);        dx = other._ar * dy;        c = other._origin - n * other._far;        p[4] = c + u * dx + v * dy;        p[5] = c - u * dx + v * dy;        p[6] = c - u * dx - v * dy;        p[7] = c + u * dx - v * dy;    }    else    {        vec3 c = other._origin - n * other._near;        p[0] = c + u * other._xmax + v * other._ymax;        p[1] = c + u * other._xmax + v * other._ymin;        p[2] = c + u * other._xmin + v * other._ymax;        p[3] = c + u * other._xmin + v * other._ymin;        c = other._origin - n * other._far;        p[4] = c + u * other._xmax + v * other._ymax;        p[5] = c + u * other._xmax + v * other._ymin;        p[6] = c + u * other._xmin + v * other._ymax;        p[7] = c + u * other._xmin + v * other._ymin;    }    if (_type == Projection::PERSPECTIVE)    {        _fovy = 0.0f;        _far = 0.0f;        _near = std::numeric_limits<float>::max();        float maxHorizAngle = 0.0f;        for (int i = 0; i < 8; i++)        {            vec4 pt = m * vec4(p[i], 1.0f);            if (pt.z < 0.0f)            {                float d = -pt.z;                float angle = atanf(fabs(pt.x) / d);                if (angle > maxHorizAngle)                    maxHorizAngle = angle;                angle = glm::degrees(atanf(fabs(pt.y) / d));                if (angle * 2.0f > _fovy)                    _fovy = angle * 2.0f;                if (_near > d)                    _near = d;                if (_far < d)                    _far = d;            }        }        float h = (_near * tanf(glm::radians(_fovy) / 2.0f))*2.0f;        float w = (_near * tanf(maxHorizAngle)) * 2.0f;        _ar = w / h;    }    else    {        _xmin = _ymin = _near = std::numeric_limits<float>::max();        _xmax = _ymax = _far = std::numeric_limits<float>::min();        for (int i = 0; i < 8; i++)        {            vec4 pt = m * vec4(p[i], 1.0f);            if (_xmin > pt.x)                _xmin = pt.x;            if (_xmax < pt.x)                _xmax = pt.x;            if (_ymin > pt.y)                 _ymin = pt.y;            if (_ymax < pt.y)                 _ymax = pt.y;            if (_near > -pt.z)                 _near = -pt.z;            if (_far < -pt.z)                 _far = -pt.z;        }    }}
开发者ID:nameless323,项目名称:Cookbook,代码行数:92,


示例2: tanf

void Taxi::Update(float time, float seconds){	//m_position.y = sinf(time * (((m_speed + 1) / 13.0f) * 1.0f)) * 0.5f + 0.5f;	//m_position.y *= 0.5f;	sm::Vec3 oldPos = m_position;	if (IsOccupied())	{		m_timeLeft -= seconds;		if (m_timeLeft < 0.0f)			m_timeLeft = 0.0f;	}	sm::Vec3 turnPivot;	sm::Matrix turnMatrix;	float pivotDistance = 0.0f;	m_speed += m_acc * 5.0f * seconds;	static float maxSpeed = 14.0f;	if (m_acc == 0.0f)	{		m_speed -= MathUtils::Min(MathUtils::Abs(m_speed), 8.0f * seconds) * MathUtils::Sign(m_speed);	}	if (m_speed > 0.0f && m_acc == -1.0f)	{		m_speed -= MathUtils::Min(MathUtils::Abs(m_speed), 12.0f * seconds) * MathUtils::Sign(m_speed);	}	m_speed = MathUtils::Clamp(m_speed, -maxSpeed / 4, maxSpeed);	SoundManager::GetInstance()->SetEnginePitch((MathUtils::Abs(m_speed) / maxSpeed) * 1.0f + 1.0f);	m_wheelsAngle += 2.0f * m_turnValue * seconds;	m_wheelsAngle = MathUtils::Clamp(m_wheelsAngle, -MathUtils::PI4, MathUtils::PI4);	if (m_wheelsAngle != 0.0f)	{		if (m_wheelsAngle < 0.0)		{			pivotDistance = m_backFrontWheelsDistance / tanf(fabs(m_wheelsAngle));			turnPivot = sm::Vec3(m_baseBackRightWheelPosition.x + pivotDistance, 0, m_baseBackRightWheelPosition.z);		}		else		{			pivotDistance = m_backFrontWheelsDistance / tanf(fabs(m_wheelsAngle));			turnPivot = sm::Vec3(m_baseBackLeftWheelPosition.x - pivotDistance, 0, m_baseBackLeftWheelPosition.z);		}		float angleSpeed = m_speed / (2.0f * MathUtils::PI * MathUtils::Abs(turnPivot.x));		sm::Matrix turnMatrixNormal =			sm::Matrix::RotateAxisMatrix(				angleSpeed * (MathUtils::PI * 2.0f) * seconds * MathUtils::Sign(m_wheelsAngle),				0, 1, 0);		turnPivot = m_worldMatrix * turnPivot;		turnPivot.y = 0.0f;		turnMatrix =			sm::Matrix::TranslateMatrix(turnPivot) *			turnMatrixNormal *			sm::Matrix::TranslateMatrix(turnPivot.GetReversed());		sm::Vec3 prevCarDirection = m_carDirection;		m_carDirection = turnMatrixNormal * m_carDirection;		m_carDirection.Normalize();			float angleDiff = sm::Vec3::GetAngle(prevCarDirection, m_carDirection);		m_wheelsAngle -= angleDiff * MathUtils::Sign(m_wheelsAngle);		m_position = turnMatrix * m_position;	}	else		m_position += m_carDirection * m_speed * seconds;	sm::Matrix newWorldMatrix =		sm::Matrix::TranslateMatrix(m_position) *		sm::Matrix::CreateLookAt(m_carDirection.GetReversed(), sm::Vec3(0, 1, 0));	sm::Vec3 boundsTopLeftWorldOld = m_worldMatrix * m_boundsTopLeft;	sm::Vec3 boundsBottomLeftWorldOld = m_worldMatrix * m_boundsBottomLeft;	sm::Vec3 boundsTopRightWorldOld = m_worldMatrix * m_boundsTopRight;	sm::Vec3 boundsBottomRightWorldOld = m_worldMatrix * m_boundsBottomRight;	sm::Vec3 boundsTopLeftWorldNew = newWorldMatrix * m_boundsTopLeft;	sm::Vec3 boundsBottomLeftWorldNew = newWorldMatrix * m_boundsBottomLeft;	sm::Vec3 boundsTopRightWorldNew = newWorldMatrix * m_boundsTopRight;	sm::Vec3 boundsBottomRightWorldNew = newWorldMatrix * m_boundsBottomRight;	sm::Vec3 collisionNormal;	sm::Vec3 collisionPoint;	if (Street::Instance->GetCollistion(boundsTopLeftWorldOld, boundsTopLeftWorldNew, collisionPoint, collisionNormal))	{//.........这里部分代码省略.........
开发者ID:asmCode,项目名称:steering_test,代码行数:101,


示例3: tanf

void Frustum::enclose( const Frustum & other ){    vec3 n = glm::normalize(other.origin - other.at);    vec3 u = glm::normalize(glm::cross(other.up, n));    vec3 v = glm::normalize(glm::cross(n, u));    if( type == Projection::PERSPECTIVE )        this->orient( origin, other.getCenter(), up );    mat4 m = this->getViewMatrix();    vec3 p[8];    // Get 8 points that define the frustum    if( other.type == Projection::PERSPECTIVE ) {        float dy = other.mNear * tanf( (float)TO_RADIANS(other.fovy) / 2.0f );        float dx = other.ar * dy;        vec3 c = other.origin - n * other.mNear;        p[0] = c + u * dx + v * dy;        p[1] = c - u * dx + v * dy;        p[2] = c - u * dx - v * dy;        p[3] = c + u * dx - v * dy;        dy = other.mFar * tanf( (float)TO_RADIANS(other.fovy) / 2.0f );        dx = other.ar * dy;        c = other.origin - n * other.mFar;        p[4] = c + u * dx + v * dy;        p[5] = c - u * dx + v * dy;        p[6] = c - u * dx - v * dy;        p[7] = c + u * dx - v * dy;    } else {        vec3 c = other.origin - n * other.mNear;        p[0] = c + u * other.xmax + v * other.ymax;        p[1] = c + u * other.xmax + v * other.ymin;        p[2] = c + u * other.xmin + v * other.ymax;        p[3] = c + u * other.xmin + v * other.ymin;        c = other.origin - n * other.mFar;        p[4] = c + u * other.xmax + v * other.ymax;        p[5] = c + u * other.xmax + v * other.ymin;        p[6] = c + u * other.xmin + v * other.ymax;        p[7] = c + u * other.xmin + v * other.ymin;    }    // Adjust frustum to contain    if( type == Projection::PERSPECTIVE ) {        fovy = 0.0f;        mFar = 0.0f;        mNear = std::numeric_limits<float>::max();        float maxHorizAngle = 0.0f;        for( int i = 0; i < 8; i++) {            // Convert to local space            vec4 pt = m * vec4(p[i],1.0f);            if( pt.z < 0.0f ) {                float d = -pt.z;                float angle = atanf( fabs(pt.x) / d );                if( angle > maxHorizAngle ) maxHorizAngle = angle;                angle = (float)TO_DEGREES( atanf( fabs(pt.y) / d ) );                if( angle * 2.0f > fovy ) fovy = angle * 2.0f;                if( mNear > d ) mNear = d;                if( mFar < d ) mFar = d;            }        }        float h = ( mNear * tanf( (float)TO_RADIANS(fovy)/ 2.0f) ) * 2.0f;        float w = ( mNear * tanf( maxHorizAngle ) ) * 2.0f;        ar = w / h;    } else {        xmin = ymin = mNear = std::numeric_limits<float>::max();        xmax = ymax = mFar = std::numeric_limits<float>::min();        for( int i = 0; i < 8; i++) {            // Convert to local space            vec4 pt = m * vec4(p[i],1.0f);            if( xmin > pt.x ) xmin = pt.x;            if( xmax < pt.x ) xmax = pt.x;            if( ymin > pt.y ) ymin = pt.y;            if( ymax < pt.y ) ymax = pt.y;            if( mNear > -pt.z ) mNear = -pt.z;            if( mFar < -pt.z ) mFar = -pt.z;        }    }}
开发者ID:wreardan,项目名称:cs559project2,代码行数:79,


示例4: assert

//.........这里部分代码省略.........					uint16_t d = *depth;					//mean filter					if (meanFilter)					{						double sum = 0.0;						unsigned count = 0;						for (int k=-1; k<=1; ++k)						{							int ii = static_cast<int>(i)+k;							if (ii>=0 && ii<static_cast<int>(s_wDepth))								for (int l=-1;l<=1;++l)								{									int jj = static_cast<int>(j)+l;									if (jj>=0 && jj<static_cast<int>(s_hDepth))									{										const uint16_t& dd = s_depth_data[jj*s_wDepth+ii];										if (dd < FREENECT_DEPTH_RAW_NO_VALUE)										{											sum += static_cast<double>(s_depth_data[jj*s_wDepth+ii]);											++count;										}									}								}						}						if (count > 1)							d = static_cast<uint16_t>(sum/count);					}					if (d < FREENECT_DEPTH_RAW_NO_VALUE)					{						//see http://openkinect.org/wiki/Imaging_Information						P.z = 12.36f * tanf(static_cast<float>(d) / 2842.5f + 1.1863f) - 3.7f;						//see http://nicolas.burrus.name/index.php/Research/KinectCalibration						P.x = (static_cast<float>(i) - cx) * (P.z + minDistance) / fx;						P.y = (static_cast<float>(j) - cy) * (P.z + minDistance) / fy ;						if (hasRGB)						{							assert(s_last_rgb_data);							Q = depth2rgb * P;							Q.x = (Q.x * fx_rgb / Q.z) + cx_rgb;							Q.y = (Q.y * fy_rgb / Q.z) + cy_rgb;							int i_rgb = (int)Q.x;							int j_rgb = (int)Q.y;							if (i_rgb>=0 && i_rgb<(int)s_wDepth && j_rgb>=0 && j_rgb<(int)s_hDepth)							{								col = s_last_rgb_data+(i_rgb+j_rgb*s_wRgb)*3;							}							else							{								col = white;							}						}						P.y = -P.y;						P.z = -P.z;						depthMap->addPoint(P);						if (col)							depthMap->addRGBColor(col);					}				}
开发者ID:getov,项目名称:trunk,代码行数:67,


示例5: node_shader_exec_math

static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) {	float a, b, r = 0.0f;		nodestack_get_vec(&a, SOCK_FLOAT, in[0]);	nodestack_get_vec(&b, SOCK_FLOAT, in[1]);		switch (node->custom1) {			case 0: /* Add */			r = a + b;			break;		case 1: /* Subtract */			r = a - b;			break;		case 2: /* Multiply */			r = a * b;			break;		case 3: /* Divide */		{			if (b == 0) /* We don't want to divide by zero. */				r = 0.0;			else				r = a / b;			break;		}		case 4: /* Sine */		{			if (in[0]->hasinput || !in[1]->hasinput)  /* This one only takes one input, so we've got to choose. */				r = sinf(a);			else				r = sinf(b);			break;		}		case 5: /* Cosine */		{			if (in[0]->hasinput || !in[1]->hasinput)  /* This one only takes one input, so we've got to choose. */				r = cosf(a);			else				r = cosf(b);			break;		}		case 6: /* Tangent */		{			if (in[0]->hasinput || !in[1]->hasinput)  /* This one only takes one input, so we've got to choose. */				r = tanf(a);			else				r = tanf(b);			break;		}		case 7: /* Arc-Sine */		{			if (in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */				/* Can't do the impossible... */				if (a <= 1 && a >= -1)					r = asinf(a);				else					r = 0.0;			}			else {				/* Can't do the impossible... */				if (b <= 1 && b >= -1)					r = asinf(b);				else					r = 0.0;			}			break;		}		case 8: /* Arc-Cosine */		{			if (in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */				/* Can't do the impossible... */				if (a <= 1 && a >= -1)					r = acosf(a);				else					r = 0.0;			}			else {				/* Can't do the impossible... */				if (b <= 1 && b >= -1)					r = acosf(b);				else					r = 0.0;			}			break;		}		case 9: /* Arc-Tangent */		{			if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */				r = atan(a);			else				r = atan(b);			break;		}		case 10: /* Power */		{			/* Only raise negative numbers by full integers */			if (a >= 0) {				r = pow(a, b);			}//.........这里部分代码省略.........
开发者ID:SuriyaaKudoIsc,项目名称:blender-git,代码行数:101,


示例6: ofGetOrientation

//----------------------------------------------------------void ofCairoRenderer::setupScreenPerspective(float width, float height, float fov, float nearDist, float farDist){	if(!b3D) return;	if(width < 0) width = viewportRect.width;	if(height < 0) height = viewportRect.height;	ofOrientation orientation = ofGetOrientation();	float viewW = viewportRect.width;	float viewH = viewportRect.height;	float eyeX = viewW / 2;	float eyeY = viewH / 2;	float halfFov = PI * fov / 360;	float theTan = tanf(halfFov);	float dist = eyeY / theTan;	float aspect = (float) viewW / viewH;	if(nearDist == 0) nearDist = dist / 10.0f;	if(farDist == 0) farDist = dist * 10.0f;	projection.makePerspectiveMatrix(fov,aspect,nearDist,farDist);	modelView.makeLookAtViewMatrix(ofVec3f(eyeX,eyeY,dist),ofVec3f(eyeX,eyeY,0),ofVec3f(0,1,0));	//note - theo checked this on iPhone and Desktop for both vFlip = false and true	switch(orientation) {		case OF_ORIENTATION_180:			modelView.glRotate(-180,0,0,1);			if(isVFlipped()){				modelView.glScale(-1,-1,1);				modelView.glTranslate(width,0,0);			}else{				modelView.glTranslate(width,-height,0);			}			break;		case OF_ORIENTATION_90_RIGHT:			modelView.glRotate(-90,0,0,1);			if(isVFlipped()){				modelView.glScale(1,1,1);			}else{				modelView.glScale(1,-1,1);				modelView.glTranslate(-width,-height,0);			}			break;		case OF_ORIENTATION_90_LEFT:			modelView.glRotate(90,0,0,1);			if(isVFlipped()){				modelView.glScale(1,1,1);				modelView.glTranslate(0,-height,0);			}else{				modelView.glScale(1,-1,1);				modelView.glTranslate(0,0,0);			}			break;		case OF_ORIENTATION_DEFAULT:		default:			if(isVFlipped()){				modelView.glScale(-1,-1,1);				modelView.glTranslate(-width,-height,0);			}			break;	}};
开发者ID:MartinHN,项目名称:openFrameworks,代码行数:68,


示例7: CG_AddViewWeapon

// Add the weapon, and flash for the player's viewvoid CG_AddViewWeapon( playerState_t *ps ) {	// no gun if in third person view or a camera is active	if ( ps->persistant[PERS_TEAM] == TEAM_SPECTATOR || ps->pm_type == PM_INTERMISSION || cg.renderingThirdPerson ) {		return;	}	const int weap = cg_fakeGun.integer ? cg_fakeGun.integer : ps->weapon;	float desiredFov = 0.0f;	if ( !cg.renderingThirdPerson		&& (cg_trueGuns.integer || weap == WP_SABER || weap == WP_MELEE)		&& cg_trueFOV.value		&& cg.predictedPlayerState.pm_type != PM_SPECTATOR		&& cg.predictedPlayerState.pm_type != PM_INTERMISSION )	{		desiredFov = cg_fovViewmodel.integer ? cg_fovViewmodel.value : cg_trueFOV.value;	}	else {		desiredFov = cg_fovViewmodel.integer ? cg_fovViewmodel.value : cg_fov.value;	}	desiredFov = Q_clampi( 1, desiredFov, 180 );	// allow the gun to be completely removed	if ( !cg_fakeGun.integer && (!cg_drawGun.integer || cg.predictedPlayerState.zoomMode || cg_trueGuns.integer		|| weap == WP_SABER || weap == WP_MELEE) ) {		return;	}	// don't draw if testing a gun model	if ( cg.testGun ) {		return;	}	centity_t *cent = &cg_entities[cg.predictedPlayerState.clientNum];	CG_RegisterWeapon( weap );	refEntity_t hand;	memset( &hand, 0, sizeof(hand) );	// set up gun position	vector3 angles;	CG_CalculateWeaponPosition( &hand.origin, &angles );	refdef_t *refdef = CG_GetRefdef();	VectorMA( &hand.origin, cg.gunAlign.x, &refdef->viewaxis[0], &hand.origin );	VectorMA( &hand.origin, cg.gunAlign.y, &refdef->viewaxis[1], &hand.origin );	VectorMA( &hand.origin, cg.gunAlign.z, &refdef->viewaxis[2], &hand.origin );	AnglesToAxis( &angles, hand.axis );	if ( cg_fovViewmodel.integer ) {		float fracDistFOV, fracWeapFOV;		float fov = desiredFov;		if ( cg_fovAspectAdjust.integer ) {			// Based on LordHavoc's code for Darkplaces			// http://www.quakeworld.nu/forum/topic/53/what-does-your-qw-look-like/page/30			const float baseAspect = 0.75f; // 3/4			const float aspect = (float)cgs.glconfig.vidWidth / (float)cgs.glconfig.vidHeight;			fov = atanf( tanf( desiredFov*M_PI / 360.0f ) * baseAspect*aspect )*360.0f / M_PI;		}		fracDistFOV = tanf( refdef->fov_x * M_PI / 360.0f );		fracWeapFOV = (1.0f / fracDistFOV) * tanf( fov * M_PI / 360.0f );		VectorScale( &hand.axis[0], fracWeapFOV, &hand.axis[0] );	}	// map torso animations to weapon animations	if ( cg_debugGunFrame.integer ) {		// development tool		hand.frame = hand.oldframe = cg_debugGunFrame.integer;		hand.backlerp = 0;	}	else {		float currentFrame;		// get clientinfo for animation map		clientInfo_t *ci = nullptr;		if ( cent->currentState.eType == ET_NPC ) {			if ( !cent->npcClient ) {				return;			}			ci = cent->npcClient;		}		else {			ci = &cgs.clientinfo[cent->currentState.clientNum];		}		// smoother first-person anims by eezstreet http://jkhub.org/topic/1499-/		//		actually ported from SP#if 1		// Sil's fix		trap->G2API_GetBoneFrame( cent->ghoul2, "lower_lumbar", cg.time, &currentFrame, cgs.gameModels, 0 );		hand.frame = CG_MapTorsoToWeaponFrame( ci, ceilf( currentFrame ), cent->currentState.torsoAnim );		hand.oldframe = CG_MapTorsoToWeaponFrame( ci, floorf( currentFrame ), cent->currentState.torsoAnim );		hand.backlerp = 1.0f - (currentFrame - floorf( currentFrame ));#else		// basejka style		hand.frame = CG_MapTorsoToWeaponFrame( ci, cent->pe.torso.frame, cent->currentState.torsoAnim );		hand.oldframe = CG_MapTorsoToWeaponFrame( ci, cent->pe.torso.oldFrame, cent->currentState.torsoAnim );//.........这里部分代码省略.........
开发者ID:Razish,项目名称:japp,代码行数:101,


示例8: Tan

//-------------------------------------------------------------//!	@brief		: タンジェント//!	@param[in]	: ラジアン
C++ tanh函数代码示例
C++ tan函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。