本文整理汇总了C++中sinf函数的典型用法代码示例。如果您正苦于以下问题:C++ sinf函数的具体用法?C++ sinf怎么用?C++ sinf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sinf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main() {
// Set the image rotation (in degrees)
float theta = 3.14159/6;
float cos_theta = cosf(theta);
float sin_theta = sinf(theta);
printf("theta = %f (cos theta = %f, sin theta = %f)\n", theta, cos_theta,
sin_theta);
// Rows and columns in the input image
int imageHeight;
int imageWidth;
const char* inputFile = "input.bmp";
const char* outputFile = "output.bmp";
// Homegrown function to read a BMP from file
float* inputImage = readImage(inputFile, &imageWidth,
&imageHeight);
// Size of the input and output images on the host
int dataSize = imageHeight*imageWidth*sizeof(float);
// Output image on the host
float* outputImage = NULL;
outputImage = (float*)malloc(dataSize);
// Set up the OpenCL environment
cl_int status;
// Discovery platform
cl_platform_id platforms[2];
cl_platform_id platform;
status = clGetPlatformIDs(2, platforms, NULL);
chk(status, "clGetPlatformIDs");
platform = platforms[PLATFORM_TO_USE];
// Discover device
cl_device_id device;
clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, 1, &device, NULL);
chk(status, "clGetDeviceIDs");
// Create context
cl_context_properties props[3] = {CL_CONTEXT_PLATFORM,
(cl_context_properties)(platform), 0};
cl_context context;
context = clCreateContext(props, 1, &device, NULL, NULL, &status);
chk(status, "clCreateContext");
// Create command queue
cl_command_queue queue;
queue = clCreateCommandQueue(context, device, 0, &status);
chk(status, "clCreateCommandQueue");
// Create the input and output buffers
cl_mem d_input;
d_input = clCreateBuffer(context, CL_MEM_READ_ONLY, dataSize, NULL,
&status);
chk(status, "clCreateBuffer");
cl_mem d_output;
d_output = clCreateBuffer(context, CL_MEM_WRITE_ONLY, dataSize, NULL,
&status);
chk(status, "clCreateBuffer");
// Copy the input image to the device
status = clEnqueueWriteBuffer(queue, d_input, CL_TRUE, 0, dataSize,
inputImage, 0, NULL, NULL);
chk(status, "clEnqueueWriteBuffer");
const char* source = readSource("rotation.cl");
// Create a program object with source and build it
cl_program program;
program = clCreateProgramWithSource(context, 1, &source, NULL, NULL);
chk(status, "clCreateProgramWithSource");
status = clBuildProgram(program, 1, &device, NULL, NULL, NULL);
chk(status, "clBuildProgram");
// Create the kernel object
cl_kernel kernel;
kernel = clCreateKernel(program, "img_rotate", &status);
chk(status, "clCreateKernel");
// Set the kernel arguments
status = clSetKernelArg(kernel, 0, sizeof(cl_mem), &d_output);
status |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &d_input);
status |= clSetKernelArg(kernel, 2, sizeof(int), &imageWidth);
status |= clSetKernelArg(kernel, 3, sizeof(int), &imageHeight);
status |= clSetKernelArg(kernel, 4, sizeof(float), &sin_theta);
status |= clSetKernelArg(kernel, 5, sizeof(float), &cos_theta);
chk(status, "clSetKernelArg");
// Set the work item dimensions
size_t globalSize[2] = {imageWidth, imageHeight};
status = clEnqueueNDRangeKernel(queue, kernel, 2, NULL, globalSize, NULL, 0,
NULL, NULL);
chk(status, "clEnqueueNDRange");
// Read the image back to the host
//.........这里部分代码省略.........
开发者ID:Soledad89,项目名称:learnOpenCL,代码行数:101,代码来源:rotation.c
示例2: cosf
void ofxChartSeriesPieSlice::setupSlice(int pixelOffset, int radius, float _percentage,float height, ofColor color)
{
percent = _percentage;
int numVertices = _percentage * 360 ;
//setup topface
mFace.addVertex(ofVec3f(0,0,0));
mFace.addNormal(ofVec3f(0,0,1));
mFace.addColor(color);
for (int i = 0; i < numVertices; i++) {
float x = radius * cosf(ofDegToRad(i));
float y = radius * sinf(ofDegToRad(i));
mFace.addVertex(ofVec3f(x,y,0));
mFace.addNormal(ofVec3f(0,0,1));
mFace.addColor(color);
}
mFace.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
mBottom.addVertex(ofVec3f(0,0,height));
mBottom.addNormal(ofVec3f(0,0,1));
mBottom.addColor(color);
for (int i = 0; i < numVertices; i++) {
float x = radius * cosf(ofDegToRad(i));
float y = radius * sinf(ofDegToRad(i));
mBottom.addVertex(ofVec3f(x,y,height));
mBottom.addNormal(ofVec3f(0,0,1));
mBottom.addColor(color);
}
mBottom.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
vector<ofVec3f>edgeVertices = vector<ofVec3f>(numVertices*2) ;
vector<ofVec3f>edgeNormals = vector<ofVec3f>(numVertices*2) ;
//calculate edge color
ofColor edgeColor = color/2;
mEdge.addVertex(ofVec3f(0,0,0));
mEdge.addVertex(ofVec3f(0,0,height));
mEdge.addNormal(ofVec3f(0,0,1));
mEdge.addNormal(ofVec3f(0,0,1));
mEdge.addColor(edgeColor);
mEdge.addColor(edgeColor);
//setup edge
for (int i = 0; i < numVertices; i++) {
float x = radius * cosf(ofDegToRad(i));
float y = radius * sinf(ofDegToRad(i));
edgeVertices[2 * i] = ofVec3f(x, y, 0);
edgeVertices[2 * i + 1] = ofVec3f(x, y, height);
}
for (int i = 0; i < (numVertices * 2)-3; i++) {
ofVec3f v1 = edgeVertices[i];
ofVec3f v2 = edgeVertices[i + 1];
ofVec3f v3 = edgeVertices[i + 2];
mEdge.addColor(edgeColor);
if (i % 2 == 0) {
ofVec3f u1 =v2- v1; //vector product
ofVec3f u2 = v3-v1;
ofVec3f normal = normalize(u1.cross(u2)); //normalized cross product
edgeNormals[i] = normal;
edgeNormals[i + 1] = normal;
}
}
//add results to mesh
mEdge.addVertices(edgeVertices);
mEdge.addNormals(edgeNormals);
mEdge.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); //?
}
开发者ID:aakashapoorv,项目名称:ofxChart,代码行数:83,代码来源:ofxChartSeriesPie.cpp
示例3: main
//.........这里部分代码省略.........
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(6 * sizeof(GLfloat)));
glEnableVertexAttribArray(2);
glBindVertexArray(0);
int width, height;
unsigned char* image = SOIL_load_image("container.jpg", &width, &height, 0, SOIL_LOAD_RGB);
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
glGenerateMipmap(GL_TEXTURE_2D);
SOIL_free_image_data(image);
glBindTexture(GL_TEXTURE_2D, 0);
unsigned char* image2 = SOIL_load_image("awesomeface.png", &width, &height, 0, SOIL_LOAD_RGB);
GLuint texture2;
glGenTextures(1, &texture2);
glBindTexture(GL_TEXTURE_2D, texture2);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image2);
glGenerateMipmap(GL_TEXTURE_2D);
SOIL_free_image_data(image2);
glBindTexture(GL_TEXTURE_2D, 0);
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
//do rendering
glClearColor(0.2, 0.3, 0.3, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(shaderProgram);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glUniform1i(glGetUniformLocation(shaderProgram, "ourTexture1"), 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texture2);
glUniform1i(glGetUniformLocation(shaderProgram, "ourTexture2"), 1);
glUniform1f(glGetUniformLocation(shaderProgram, "mixValue"), mixValue);
glm::mat4 trans;
trans = glm::translate(trans, glm::vec3(0.5f, -0.5f, 0.0f));
trans = glm::rotate(trans, glm::radians((GLfloat)glfwGetTime() * 50.0f),
glm::vec3(0.0f, 0.0f, 1.0f));
GLuint transformLoc = glGetUniformLocation(shaderProgram, "transforms");
glUniformMatrix4fv(transformLoc, 1, GL_FALSE, glm::value_ptr(trans));
//draw the first triangles
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
trans = glm::mat4(); //reset the previous matrix
trans = glm::translate(trans, glm::vec3(-0.5f, 0.5f, 0.0f));
float scaleFactor = sinf((GLfloat)glfwGetTime()) ;
trans = glm::scale(trans,glm::vec3(scaleFactor, scaleFactor, 1.0f ));
glUniformMatrix4fv(transformLoc, 1, GL_FALSE, glm::value_ptr(trans));
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
glfwSwapBuffers(window);
}
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
glDeleteBuffers(1, &EBO);
glDeleteProgram(shaderProgram);
glfwTerminate();
return 0;
}
开发者ID:zilongshanren,项目名称:LearnOpenGL.com,代码行数:101,代码来源:main.cpp
示例4: return
int ScriptMonitor::sin(int angle) {
return (int)(1000*sinf((float)angle)*M_PI/180.0);
}
开发者ID:Dustpup,项目名称:aurora-game-engine,代码行数:3,代码来源:script_monitor.cpp
示例5: voltage_switch_inverter_VSI
void voltage_switch_inverter_VSI(int S_A, int S_B, int S_C)
{
/*
float duty_a=1.0f;
float duty_b=1.0f;
float duty_c=1.0f;
float attenuation =1.0f;
*/
close_loop=true;
cur_angle+=2.0f*PI*TICK_PERIOD*ref_freq;
//converting big angles into something between 0 and 2pi
if (cur_angle >= (2.0f*PI)) {
cur_angle=cur_angle-(2.0f*PI);
}
//close_loop=false;
if (!close_loop)
{
duty_a=sinf(cur_angle);
duty_b=sinf(cur_angle+2.0f*PI/3.0f);
duty_c=sinf(cur_angle+4.0f*PI/3.0f);
}
else
{
duty_a=1.0f;
duty_b=1.0f;
duty_c=1.0f;
attenuation =1.0f;//0.5f;//1.0f;
}
if (motor_off)
{
duty_a=0.0f;
duty_b=0.0f;
duty_c=0.0f;
attenuation=1.0f;
}
/*
//#define CURRENT_LIMIT 14.0f
if ( i_sA >CURRENT_LIMIT || i_sA <-CURRENT_LIMIT ||
i_sB >CURRENT_LIMIT || i_sB <-CURRENT_LIMIT ||
(-i_sA-i_sB)>CURRENT_LIMIT || (-i_sA-i_sB)<-CURRENT_LIMIT)
{
duty_a=0.0f;
duty_b=0.0f;
duty_c=0.0f;
attenuation=1.0f;
motor_stop=true;
//printf("\n\nMotor off, overcurrent...\n\n");
}
*/
/* //PWM mode
TIM_OCM_FROZEN,
TIM_OCM_ACTIVE,
TIM_OCM_INACTIVE,
TIM_OCM_TOGGLE,
TIM_OCM_FORCE_LOW,
TIM_OCM_FORCE_HIGH,
TIM_OCM_PWM1,
TIM_OCM_PWM2,
*/
//dtc switching selection
if (close_loop)
{
//----------------SA: S1 and S4---------------------------------
if (S_A==1)
{
timer_set_oc_mode(TIM1, TIM_OC1, TIM_OCM_PWM1);
//timer_set_oc_mode (TIM1, TIM_OC1, TIM_OCM_FORCE_HIGH);
timer_enable_oc_output (TIM1, TIM_OC1 ); //S1 on
timer_disable_oc_output (TIM1, TIM_OC1N); //S4 off
}
else if (S_A==0)
{
timer_set_oc_mode(TIM1, TIM_OC1, TIM_OCM_PWM1);
//timer_set_oc_mode (TIM1, TIM_OC1, TIM_OCM_FORCE_HIGH);
timer_disable_oc_output (TIM1, TIM_OC1); //S1 off
timer_enable_oc_output (TIM1, TIM_OC1N); //S4 on
}
else
{
duty_a=0.0f;
timer_set_oc_mode(TIM1, TIM_OC1, TIM_OCM_PWM1);
//timer_set_oc_mode (TIM1, TIM_OC1, TIM_OCM_FORCE_HIGH);
timer_disable_oc_output (TIM1, TIM_OC1); //S1 off
timer_disable_oc_output (TIM1, TIM_OC1N); //S4 on
}
//-------------SB: S3 and S6------------------------------------
if (S_B==1)
{
timer_set_oc_mode(TIM1, TIM_OC2, TIM_OCM_PWM1);
//timer_set_oc_mode(TIM1, TIM_OC2, TIM_OCM_FORCE_HIGH);
timer_enable_oc_output(TIM1, TIM_OC2 ); //S3 on
timer_disable_oc_output (TIM1, TIM_OC2N); //S6 off
//.........这里部分代码省略.........
开发者ID:likon,项目名称:open-coroco,代码行数:101,代码来源:DTC.c
示例6: sphere
TriMeshf sphere(const float radius, const ml::vec3f& pos, const size_t stacks /*= 10*/, const size_t slices /*= 10*/, const ml::vec4f& color /*= ml::vec4f(1,1,1,1) */) {
MeshDataf meshdata;
auto& V = meshdata.m_Vertices;
auto& I = meshdata.m_FaceIndicesVertices;
auto& N = meshdata.m_Normals;
auto& C = meshdata.m_Colors;
const float thetaDivisor = 1.0f / stacks * ml::math::PIf;
const float phiDivisor = 1.0f / slices * 2.0f * ml::math::PIf;
for (size_t t = 0; t < stacks; t++) { // stacks increment elevation (theta)
float theta1 = t * thetaDivisor;
float theta2 = (t + 1) * thetaDivisor;
for (size_t p = 0; p < slices; p++) { // slices increment azimuth (phi)
float phi1 = p * phiDivisor;
float phi2 = (p + 1) * phiDivisor;
const auto sph2xyz = [&](float r, float theta, float phi) {
const float sinTheta = sinf(theta), sinPhi = sinf(phi), cosTheta = cosf(theta), cosPhi = cosf(phi);
return ml::vec3f(r * sinTheta * cosPhi, r * sinTheta * sinPhi, r * cosTheta);
};
// phi2 phi1
// | |
// 2------1 -- theta1
// |\ _ |
// | \ |
// 3------4 -- theta2
//
// Points
const ml::vec3f c1 = pos + sph2xyz(radius, theta1, phi1),
c2 = pos + sph2xyz(radius, theta1, phi2),
c3 = pos + sph2xyz(radius, theta2, phi2),
c4 = pos + sph2xyz(radius, theta2, phi1);
V.push_back(c1);
V.push_back(c2);
V.push_back(c3);
V.push_back(c4);
// Colors
for (int i = 0; i < 4; i++) {
C.push_back(color);
}
// Normals
N.push_back(c1.getNormalized());
N.push_back(c2.getNormalized());
N.push_back(c3.getNormalized());
N.push_back(c4.getNormalized());
const UINT baseIdx = static_cast<UINT>(t * slices * 4 + p * 4);
// Indices
std::vector<unsigned int> indices;
if ( t == 0 ) { // top cap -- t1p1, t2p2, t2p1
indices.push_back(baseIdx + 0);
indices.push_back(baseIdx + 2);
indices.push_back(baseIdx + 3);
I.push_back(indices);
}
else if ( t + 1 == stacks ) { // bottom cap -- t2p2, t1p1, t1p2
indices.push_back(baseIdx + 2);
indices.push_back(baseIdx + 0);
indices.push_back(baseIdx + 1);
I.push_back(indices);
}
else { // regular piece
indices.push_back(baseIdx + 0);
indices.push_back(baseIdx + 1);
indices.push_back(baseIdx + 3);
I.push_back(indices);
indices.clear();
indices.push_back(baseIdx + 1);
indices.push_back(baseIdx + 2);
indices.push_back(baseIdx + 3);
I.push_back(indices);
}
}
}
//meshdata.mergeCloseVertices(0.00001f, true);
return TriMeshf(meshdata);
}
开发者ID:ZaneYang,项目名称:VoxelHashing,代码行数:81,代码来源:meshShapes.cpp
示例7: cosf
void GeometryGenerator::CreateCylinder(float bottomRadius, float topRadius,
float height, UINT sliceCount, UINT stackCount, MeshData& meshData)
{
meshData.Vertices.clear();
meshData.Indices.clear();
//
// Build Stacks.
//
float stackHeight = height / stackCount;
// Amount to increment radius as we move up each stack level from bottom to top.
float radiusStep = (topRadius - bottomRadius) / stackCount;
UINT ringCount = stackCount + 1;
// Compute vertices for each stack ring starting at the bottom and moving up.
for (UINT i = 0; i < ringCount; ++i)
{
float y = -0.5f*height + i*stackHeight;
float r = bottomRadius + i*radiusStep;
// vertices of ring
float dTheta = 2.0f*XM_PI / sliceCount;
for (UINT j = 0; j <= sliceCount; ++j)
{
Vertex vertex;
float c = cosf(j*dTheta);
float s = sinf(j*dTheta);
vertex.Position = XMFLOAT3(r*c, y, r*s);
vertex.TexC.x = (float)j / sliceCount;
vertex.TexC.y = 1.0f - (float)i / stackCount;
// Cylinder can be parameterized as follows, where we introduce v
// parameter that goes in the same direction as the v tex-coord
// so that the bitangent goes in the same direction as the v tex-coord.
// Let r0 be the bottom radius and let r1 be the top radius.
// y(v) = h - hv for v in [0,1].
// r(v) = r1 + (r0-r1)v
//
// x(t, v) = r(v)*cos(t)
// y(t, v) = h - hv
// z(t, v) = r(v)*sin(t)
//
// dx/dt = -r(v)*sin(t)
// dy/dt = 0
// dz/dt = +r(v)*cos(t)
//
// dx/dv = (r0-r1)*cos(t)
// dy/dv = -h
// dz/dv = (r0-r1)*sin(t)
// This is unit length.
vertex.TangentU = XMFLOAT3(-s, 0.0f, c);
float dr = bottomRadius - topRadius;
XMFLOAT3 bitangent(dr*c, -height, dr*s);
XMVECTOR T = XMLoadFloat3(&vertex.TangentU);
XMVECTOR B = XMLoadFloat3(&bitangent);
XMVECTOR N = XMVector3Normalize(XMVector3Cross(T, B));
XMStoreFloat3(&vertex.Normal, N);
meshData.Vertices.push_back(vertex);
}
}
// Add one because we duplicate the first and last vertex per ring
// since the texture coordinates are different.
UINT ringVertexCount = sliceCount + 1;
// Compute indices for each stack.
for (UINT i = 0; i < stackCount; ++i)
{
for (UINT j = 0; j < sliceCount; ++j)
{
meshData.Indices.push_back(i*ringVertexCount + j);
meshData.Indices.push_back((i + 1)*ringVertexCount + j);
meshData.Indices.push_back((i + 1)*ringVertexCount + j + 1);
meshData.Indices.push_back(i*ringVertexCount + j);
meshData.Indices.push_back((i + 1)*ringVertexCount + j + 1);
meshData.Indices.push_back(i*ringVertexCount + j + 1);
}
}
BuildCylinderTopCap(bottomRadius, topRadius, height, sliceCount, stackCount, meshData);
BuildCylinderBottomCap(bottomRadius, topRadius, height, sliceCount, stackCount, meshData);
}
开发者ID:tczzyzymj,项目名称:Prectice,代码行数:93,代码来源:GeometryGenerator.cpp
示例8: SinCos
float SinCos(float x, float y) {
return 0.3f * cosf(3.0f * x * PI) * sinf(3.0f * y * PI);
}
开发者ID:Nazul,项目名称:MSC-CG_OpenGL,代码行数:3,代码来源:Demo06.cpp
示例9: SinCosNormal
VECTOR4D SinCosNormal(float x, float y, float z) {
VECTOR4D N = { 0.3f * 3.0f * PI * sin(3.0f * x * PI) * sinf(3.0f * y * PI), -0.3f * 3.0f * PI * cosf(3.0f * x * PI) * cos(3.0f * y * PI), 1.0f, 0.0f };
N = Normalize(N);
return N;
}
开发者ID:Nazul,项目名称:MSC-CG_OpenGL,代码行数:5,代码来源:Demo06.cpp
示例10: while
bool AudioOutput::mix(void *outbuff, unsigned int nsamp) {
QList<AudioOutputUser *> qlMix;
QList<AudioOutputUser *> qlDel;
if (g.s.fVolume < 0.01f) {
return false;
}
const float adjustFactor = std::pow(10.f , -18.f / 20);
const float mul = g.s.fVolume;
const unsigned int nchan = iChannels;
ServerHandlerPtr sh = g.sh;
VoiceRecorderPtr recorder;
if (sh) {
recorder = g.sh->recorder;
}
qrwlOutputs.lockForRead();
bool prioritySpeakerActive = false;
QMultiHash<const ClientUser *, AudioOutputUser *>::const_iterator it = qmOutputs.constBegin();
while (it != qmOutputs.constEnd()) {
AudioOutputUser *aop = it.value();
if (! aop->needSamples(nsamp)) {
qlDel.append(aop);
} else {
qlMix.append(aop);
const ClientUser *user = it.key();
if (user && user->bPrioritySpeaker) {
prioritySpeakerActive = true;
}
}
++it;
}
if (g.prioritySpeakerActiveOverride) {
prioritySpeakerActive = true;
}
if (! qlMix.isEmpty()) {
STACKVAR(float, speaker, iChannels*3);
STACKVAR(float, svol, iChannels);
STACKVAR(float, fOutput, iChannels * nsamp);
float *output = (eSampleFormat == SampleFloat) ? reinterpret_cast<float *>(outbuff) : fOutput;
bool validListener = false;
memset(output, 0, sizeof(float) * nsamp * iChannels);
boost::shared_array<float> recbuff;
if (recorder) {
recbuff = boost::shared_array<float>(new float[nsamp]);
memset(recbuff.get(), 0, sizeof(float) * nsamp);
recorder->prepareBufferAdds();
}
for (unsigned int i=0;i<iChannels;++i)
svol[i] = mul * fSpeakerVolume[i];
if (g.s.bPositionalAudio && (iChannels > 1) && g.p->fetch() && (g.bPosTest || g.p->fCameraPosition[0] != 0 || g.p->fCameraPosition[1] != 0 || g.p->fCameraPosition[2] != 0)) {
float front[3] = { g.p->fCameraFront[0], g.p->fCameraFront[1], g.p->fCameraFront[2] };
float top[3] = { g.p->fCameraTop[0], g.p->fCameraTop[1], g.p->fCameraTop[2] };
// Front vector is dominant; if it's zero we presume all is zero.
float flen = sqrtf(front[0]*front[0]+front[1]*front[1]+front[2]*front[2]);
if (flen > 0.0f) {
front[0] *= (1.0f / flen);
front[1] *= (1.0f / flen);
front[2] *= (1.0f / flen);
float tlen = sqrtf(top[0]*top[0]+top[1]*top[1]+top[2]*top[2]);
if (tlen > 0.0f) {
top[0] *= (1.0f / tlen);
top[1] *= (1.0f / tlen);
top[2] *= (1.0f / tlen);
} else {
top[0] = 0.0f;
top[1] = 1.0f;
top[2] = 0.0f;
}
if (std::abs<float>(front[0] * top[0] + front[1] * top[1] + front[2] * top[2]) > 0.01f) {
// Not perpendicular. Assume Y up and rotate 90 degrees.
float azimuth = 0.0f;
if ((front[0] != 0.0f) || (front[2] != 0.0f))
azimuth = atan2f(front[2], front[0]);
float inclination = acosf(front[1]) - static_cast<float>(M_PI) / 2.0f;
top[0] = sinf(inclination)*cosf(azimuth);
top[1] = cosf(inclination);
top[2] = sinf(inclination)*sinf(azimuth);
}
} else {
//.........这里部分代码省略.........
开发者ID:Acidburn0zzz,项目名称:mumble,代码行数:101,代码来源:AudioOutput.cpp
示例11: GL_draw_frame
void GL_draw_frame( void * vp )
{
static float rot;
static int t0;
float s;
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLineWidth(1.f);
set_camera_view();
if ( t0 == 0 ) {
init_VBO();
t0 = 1;
}
int now = get_milliseconds();
/*
while ( now - t0 > 20 ) {
rot += 1.0f;
t0 += 20;
if ( rot > 360.f )
rot -= 360.f;
if ( rot < 0.f )
rot += 360.f;
}
*/
// hack to get rotation timer right
const float p180 = 0.017453126f;
const float c180p = 57.295776f;
const float c2pi = 6.2831854f;
const int ms_per_frame = 20; // milliseconds per frame
const float rot_per_frame = 1.0f * p180;
/*
while ( now - t0 > ms_per_frame ) {
rot += 1.0f;
t0 += ms_per_frame;
} */
static int set = 0;
if ( t0 <= 0 )
t0 = 1;
if ( now - t0 > 0 )
{
int diff = now - t0;
/* the rotation is incremented 1 rot_per_frame each 1 ms_per_frame */
float newrot = rot + (rot_per_frame/(float)ms_per_frame) * ((float)diff);
if ( set < 20 )
core.printf( "hiccup > 2pi: before: %f, %f ", rot, sinf(rot) );
rot = newrot;
// catch it up
t0 = now;
if ( set < 20 )
core.printf( "after: %f, %f\n", rot, sinf( rot ) );
// clamp
if ( rot > c2pi ) {
rot = rot - c2pi;
set = 1; // no more print
core.printf( " --> MARK <-- \n" );
}
if ( set != 0 )
++set;
}
const float rotdeg = rot * c180p;
/// -- DRAW ---
// rotating wire spiral
glColor4ub( 255,255,255,255 );
glPushMatrix();
glRotatef( rotdeg, 0, 1, 0 );
draw_spiral( 24.0f, 10.f, 0.05f );
glPopMatrix();
// rotating circle
glEnable(GL_TEXTURE_2D);
glBindTexture( GL_TEXTURE_2D, core.materials.findByName( "jr_bob" )->img->texhandle );
//.........这里部分代码省略.........
开发者ID:gmn,项目名称:Homemade-3D-Engine,代码行数:101,代码来源:gl_drawing.cpp
示例12: update
void CCEaseSineOut::update(float time)
{
m_pOther->update(sinf(time * (float)M_PI_2));
}
开发者ID:897290110,项目名称:MoonWarriors,代码行数:4,代码来源:CCActionEase.cpp
示例13: synthesise
void synthesise(
kiss_fft_cfg fft_inv_cfg,
float Sn_[], /* time domain synthesised signal */
MODEL *model, /* ptr to model parameters for this frame */
float Pn[], /* time domain Parzen window */
int shift /* flag used to handle transition frames */
)
{
int i,l,j,b; /* loop variables */
COMP Sw_[FFT_DEC]; /* DFT of synthesised signal */
COMP sw_[FFT_DEC]; /* synthesised signal */
if (shift) {
/* Update memories */
for(i=0; i<N-1; i++) {
Sn_[i] = Sn_[i+N];
}
Sn_[N-1] = 0.0;
}
for(i=0; i<FFT_DEC; i++) {
Sw_[i].real = 0.0;
Sw_[i].imag = 0.0;
}
/*
Nov 2010 - found that synthesis using time domain cos() functions
gives better results for synthesis frames greater than 10ms. Inverse
FFT synthesis using a 512 pt FFT works well for 10ms window. I think
(but am not sure) that the problem is related to the quantisation of
the harmonic frequencies to the FFT bin size, e.g. there is a
8000/512 Hz step between FFT bins. For some reason this makes
the speech from longer frame > 10ms sound poor. The effect can also
be seen when synthesising test signals like single sine waves, some
sort of amplitude modulation at the frame rate.
Another possibility is using a larger FFT size (1024 or 2048).
*/
#define FFT_SYNTHESIS
#ifdef FFT_SYNTHESIS
/* Now set up frequency domain synthesised speech */
for(l=1; l<=model->L; l++) {
//for(l=model->L/2; l<=model->L; l++) {
//for(l=1; l<=model->L/4; l++) {
b = (int)(l*model->Wo*FFT_DEC/TWO_PI + 0.5);
if (b > ((FFT_DEC/2)-1)) {
b = (FFT_DEC/2)-1;
}
Sw_[b].real = model->A[l]*cosf(model->phi[l]);
Sw_[b].imag = model->A[l]*sinf(model->phi[l]);
Sw_[FFT_DEC-b].real = Sw_[b].real;
Sw_[FFT_DEC-b].imag = -Sw_[b].imag;
}
/* Perform inverse DFT */
kiss_fft(fft_inv_cfg, (kiss_fft_cpx *)Sw_, (kiss_fft_cpx *)sw_);
#else
/*
Direct time domain synthesis using the cos() function. Works
well at 10ms and 20ms frames rates. Note synthesis window is
still used to handle overlap-add between adjacent frames. This
could be simplified as we don't need to synthesise where Pn[]
is zero.
*/
for(l=1; l<=model->L; l++) {
for(i=0,j=-N+1; i<N-1; i++,j++) {
Sw_[FFT_DEC-N+1+i].real += 2.0*model->A[l]*cos(j*model->Wo*l + model->phi[l]);
}
for(i=N-1,j=0; i<2*N; i++,j++)
Sw_[j].real += 2.0*model->A[l]*cos(j*model->Wo*l + model->phi[l]);
}
#endif
/* Overlap add to previous samples */
for(i=0; i<N-1; i++) {
Sn_[i] += sw_[FFT_DEC-N+1+i].real*Pn[i];
}
if (shift)
for(i=N-1,j=0; i<2*N; i++,j++)
Sn_[i] = sw_[j].real*Pn[i];
else
for(i=N-1,j=0; i<2*N; i++,j++)
Sn_[i] += sw_[j].real*Pn[i];
}
开发者ID:0x0B501E7E,项目名称:codec2,代码行数:88,代码来源:sine.c
示例14: getOrientation
void getOrientation(float *smoothAcc, float *orient, float *accData, float *gyroData, float dt)
{
float accAngle[3];
float gyroRate[3];
if (evvgcCFinitialized == false)
{
initOrientation();
evvgcCFinitialized = true;
}
//-------------------------------------------
if (evvgcCFinitialized == true)
{
accAngle[ROLL ] = atan2f(-accData[YAXIS], -accData[ZAXIS]);
accAngle[PITCH] = atan2f(accData[XAXIS], -accData[ZAXIS]);
smoothAcc[ROLL] = ((smoothAcc[ROLL ] * 99.0f) + accAngle[ROLL ]) / 100.0f;
smoothAcc[PITCH] = ((smoothAcc[PITCH] * 99.0f) + accAngle[PITCH]) / 100.0f;
gyroRate[PITCH] = gyroData[PITCH];
orient[PITCH] = (orient[PITCH] + gyroRate[PITCH] * dt) + 0.0002f * (smoothAcc[PITCH] - orient[PITCH]);
gyroRate[ROLL] = gyroData[ROLL] * cosf(fabsf(orient[PITCH])) + gyroData[YAW] * sinf(orient[PITCH]);
orient[ROLL] = (orient[ROLL] + gyroRate[ROLL] * dt) + 0.0002f * (smoothAcc[ROLL] - orient[ROLL]);
gyroRate[YAW] = gyroData[YAW] * cosf(fabsf(orient[PITCH])) - gyroData[ROLL] * sinf(orient[PITCH]);
orient[YAW] = (orient[YAW] + gyroRate[YAW] * dt);
}
}
开发者ID:AmadeuJr,项目名称:BGC32-1,代码行数:32,代码来源:evvgcCF.c
示例15: stabilisation_wing_cascade_stabilise
//.........这里部分代码省略.........
rpyt_errors[1] = input.tvel[Z] - gps_speed_global[Z]; // Vertical speed
rpyt_errors[2] = 0.0f;
rpyt_errors[3] = airspeed_desired - stabilisation_wing->airspeed_analog->get_airspeed(); // Airspeed
// Compute the feedforward
feedforward[0] = 0.0f;
feedforward[1] = 0.0f;
feedforward[2] = 0.0f;
feedforward[3] = (airspeed_desired - 13.0f)/8.0f + 0.2f;
// run PID update on all velocity controllers
stabilisation_run_feedforward(&stabilisation_wing->stabiliser_stack.velocity_stabiliser, stabilisation_wing->dt_s, rpyt_errors, feedforward);
////////////////
// PID OUTPUT //
////////////////
// Get turn rate command and transform it into a roll angle command for next layer
input_turn_rate = stabilisation_wing->stabiliser_stack.velocity_stabiliser.output.rpy[0];
// TODO: Fix this in case of bad airspeed readings...
clipping_factor = stabilisation_wing->max_roll_angle / (PI/2.0f);
if(clipping_factor == 0.0f)
{
input_roll_angle = 0.0f;
}
else
{
input_roll_angle = clipping_factor * atanf( (1.0f/clipping_factor) * (stabilisation_wing->airspeed_analog->get_airspeed() * input_turn_rate / 9.81f) );
}
// Set input for next layer
input = stabilisation_wing->stabiliser_stack.velocity_stabiliser.output;
input.rpy[0] = input_roll_angle;
input.rpy[1] = - stabilisation_wing->stabiliser_stack.velocity_stabiliser.output.rpy[1];
input.thrust = stabilisation_wing->stabiliser_stack.velocity_stabiliser.output.thrust;
// Overwrite the commands during different key phases (take-off and landing)
if(stabilisation_wing->navigation->internal_state() == Navigation::NAV_TAKEOFF)
{
// Take-off: fixed 0 roll angle, fixed defined pitch angle and fixed defined constant thrust value.
input.rpy[0] = 0.0f;
input.rpy[1] = stabilisation_wing->take_off_pitch;
input.thrust = stabilisation_wing->take_off_thrust;
}
else if(stabilisation_wing->navigation->internal_state() == Navigation::NAV_LANDING)
{
// Landing: Limit the roll computed by the velocity layer (navigation), shut down the motor and impose a little pitch down to assure gliding without stall.
if(input.rpy[0] > stabilisation_wing->landing_max_roll)
{
input.rpy[0] = stabilisation_wing->landing_max_roll;
}
else if(input.rpy[0] < -stabilisation_wing->landing_max_roll)
{
input.rpy[0] = -stabilisation_wing->landing_max_roll;
}
input.rpy[1] = stabilisation_wing->landing_pitch;
input.thrust = -1.0f;
}
// -- no break here - we want to run the lower level modes as well! --
case ATTITUDE_COMMAND_MODE:
// Add "a priori on the pitch" to fly horizontally and to compensate for roll angle
attitude = coord_conventions_quat_to_aero(stabilisation_wing->ahrs->qe);
input.rpy[1] += stabilisation_wing->pitch_angle_apriori; // Constant compensation for horizontal
if(maths_f_abs(attitude.rpy[ROLL]) < PI/2.0f) // Compensation for the roll bank angle
{
input.rpy[1] += stabilisation_wing->pitch_angle_apriori_gain * maths_f_abs(input.rpy[0]*input.rpy[0]*input.rpy[0]);
}
// run absolute attitude_filter controller
rpyt_errors[0]= sinf(input.rpy[0]) + up_vec.v[1]; // Roll
rpyt_errors[1]= sinf(input.rpy[1]) - up_vec.v[0]; // Pitch
rpyt_errors[2]= 0.0f; // Yaw
rpyt_errors[3]= input.thrust; // no feedback for thrust at this level
// run PID update on all attitude_filter controllers
stabilisation_run(&stabilisation_wing->stabiliser_stack.attitude_stabiliser, stabilisation_wing->dt_s, rpyt_errors);
// use output of attitude_filter controller to set rate setpoints for rate controller
input = stabilisation_wing->stabiliser_stack.attitude_stabiliser.output;
// -- no break here - we want to run the lower level modes as well! --
case RATE_COMMAND_MODE: // this level is always run
// get rate measurements from IMU (filtered angular rates)
for (i=0; i<3; i++)
{
rpyt_errors[i]= input.rpy[i]- stabilisation_wing->ahrs->angular_speed[i];
}
rpyt_errors[3] = input.thrust ; // no feedback for thrust at this level
// run PID update on all rate controllers
stabilisation_run(&stabilisation_wing->stabiliser_stack.rate_stabiliser, stabilisation_wing->dt_s, rpyt_errors);
}
stabilisation_wing->torque_command->xyz[0] = stabilisation_wing->stabiliser_stack.rate_stabiliser.output.rpy[ROLL];
stabilisation_wing->torque_command->xyz[1] = stabilisation_wing->stabiliser_stack.rate_stabiliser.output.rpy[PITCH];
stabilisation_wing->thrust_command->thrust = stabilisation_wing->stabiliser_stack.rate_stabiliser.output.thrust;
}
开发者ID:lis-epfl,项目名称:MAVRIC_Library,代码行数:101,代码来源:stabilisation_wing.cpp
示例16: while
int gl_renderer::render() {
int running = 1;
/* ----- Event cycle --------------- */
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
running = 0;
break;
case SDL_KEYDOWN:
switch( event.key.keysym.sym ){
case SDLK_ESCAPE:
case SDLK_q:
running = 0;
break;
case SDLK_F1:
SDL_WM_ToggleFullScreen(screen);
break;
case SDLK_s:
control1->toggleEngineL();
break;
case SDLK_d:
control1->toggleEngineR();
break;
case SDLK_k:
control2->toggleEngineL();
break;
case SDLK_l:
control2->toggleEngineR();
break;
case SDLK_1:
switch_camera(0);
break;
case SDLK_2:
switch_camera(1);
break;
case SDLK_3:
switch_camera(2);
break;
default:
break;
}
break;
case SDL_VIDEORESIZE:
if((screen = SDL_SetVideoMode(event.resize.w, event.resize.h, bpp, flags)) == 0) {
fprintf(stderr, "Video resize failed: %s\n", SDL_GetError());
exit(-1);
}
glPushAttrib(GL_TRANSFORM_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0f, (GLfloat)event.resize.w/(GLfloat)event.resize.h, 0.1, 100000.0);
glViewport(0.0f, 0.0f, event.resize.w, event.resize.h);
glPopAttrib();
break;
case SDL_ACTIVEEVENT:
if(event.active.state != SDL_APPMOUSEFOCUS && event.active.gain == 0)
while(1){
SDL_WaitEvent(&event);
if(event.type == SDL_ACTIVEEVENT &&
event.active.state != SDL_APPMOUSEFOCUS &&
event.active.gain == 1);
break;
}
break;
default:
break;
}
}
interval = FrameTiming();
/* apply control movement */
/* ----- Blitting on the screen --------------- */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glLoadIdentity();
current_camera->apply_rotation();
//glutSolidCube(50.0);
//draw_skybox(200.0);
background_stars->draw();
current_camera->apply_translation();
/* ----- Light ----- */
angle += 0.001f * interval;
light1.Position[0] = sinf(angle) * 1.5f;
light1.Position[2] = cosf(angle) * 1.5f;
light2.Position[1] = sinf(angle) * 1.5f;
light2.Position[2] = cosf(angle) * 1.5f;
UpdateLight(&light1, GL_LIGHT1, 0.1f);
//.........这里部分代码省略.........
开发者ID:ptrhere,项目名称:norbit,代码行数:101,代码来源:gl_renderer.cpp
示例17: DoWeaponSwitch
//.........这里部分代码省略.........
1, 0, 0, -1, WEAPON_GUN);
// pack the Projectile and send it to the client Directly
CNetObj_Projectile p;
pProj->FillInfo(&p);
CMsgPacker Msg(NETMSGTYPE_SV_EXTRAPROJECTILE);
Msg.AddInt(1);
for(unsigned i = 0; i < sizeof(CNetObj_Projectile)/sizeof(int); i++)
Msg.AddInt(((int *)&p)[i]);
Server()->SendMsg(&Msg, 0, m_pPlayer->GetCID());
GameServer()->CreateSound(m_Pos, SOUND_GUN_FIRE);
} break;
case WEAPON_SHOTGUN:
{
int ShotSpread = 2;
CMsgPacker Msg(NETMSGTYPE_SV_EXTRAPROJECTILE);
Msg.AddInt(ShotSpread*2+1);
for(int i = -ShotSpread; i <= ShotSpread; ++i)
{
float Spreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f};
float a = GetAngle(Direction);
a += Spreading[i+2];
float v = 1-(absolute(i)/(float)ShotSpread);
float Speed = mix((float)GameServer()->Tuning()->m_ShotgunSpeeddiff, 1.0f, v);
CProjectile *pProj = new CProjectile(GameWorld(), WEAPON_SHOTGUN,
m_pPlayer->GetCID(),
ProjStartPos,
vec2(cosf(a), sinf(a))*Speed,
(int)(Server()->TickSpeed()*GameServer()->Tuning()->m_ShotgunLifetime),
1, 0, 0, -1, WEAPON_SHOTGUN);
// pack the Projectile and send it to the client Directly
CNetObj_Projectile p;
pProj->FillInfo(&p);
for(unsigned i = 0; i < sizeof(CNetObj_Projectile)/sizeof(int); i++)
Msg.AddInt(((int *)&p)[i]);
}
Server()->SendMsg(&Msg, 0,m_pPlayer->GetCID());
GameServer()->CreateSound(m_Pos, SOUND_SHOTGUN_FIRE);
} break;
case WEAPON_GRENADE:
{
CProjectile *pProj = new CProjectile(GameWorld(), WEAPON_GRENADE,
m_pPlayer->GetCID(),
ProjStartPos,
Direction,
(int)(Server()->TickSpeed()*GameServer()->Tuning()->m_GrenadeLifetime),
1, true, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE);
// pack the Projectile and send it to the client Directly
CNetObj_Projectile p;
pProj->FillInfo(&p);
CMsgPacker Msg(NETMSGTYPE_SV_EXTRAPROJECTILE);
Msg.AddInt(1);
for(unsigned i = 0; i < sizeof(CNetObj_Projectile)/sizeof(int); i++)
开发者ID:Defeater,项目名称:teeworlds-infclass,代码行数:67,代码来源:character.cpp
示例18: XMFLOAT3
void GeometryGenerator::CreateGeosphere(float radius, UINT numSubdivisions, MeshData& meshData)
{
// Put a cap on the number of subdivisions.
numSubdivisions = MathHelper::Min(numSubdivisions, 5u);
// Approximate a sphere by tessellating an icosahedron.
const float X = 0.525731f;
const float Z = 0.850651f;
XMFLOAT3 pos[12] =
{
XMFLOAT3(-X, 0.0f, Z), XMFLOAT3(X, 0.0f, Z),
XMFLOAT3(-X, 0.0f, -Z), XMFLOAT3(X, 0.0f, -Z),
XMFLOAT3(0.0f, Z, X), XMFLOAT3(0.0f, Z, -X),
XMFLOAT3(0.0f, -Z, X), XMFLOAT3(0.0f, -Z, -X),
XMFLOAT3(Z, X, 0.0f), XMFLOAT3(-Z, X, 0.0f),
XMFLOAT3(Z, -X, 0.0f), XMFLOAT3(-Z, -X, 0.0f)
};
DWORD k[60] =
{
1,4,0, 4,9,0, 4,5,9, 8,5,4, 1,8,4,
1,10,8, 10,3,8, 8,3,5, 3,2,5, 3,7,2,
3,10,7, 10,6,7, 6,11,7, 6,0,11, 6,1,0,
10,1,6, 11,0,9, 2,11,9, 5,2,9, 11,2,7
};
meshData.Vertices.resize(12);
meshData.Indices.resize(60);
for (UINT i = 0; i < 12; ++i)
meshData.Vertices[i].Position = pos[i];
for (UINT i = 0; i < 60; ++i)
meshData.Indices[i] = k[i];
for (UINT i = 0; i < numS
|
请发表评论