本文整理汇总了C++中Perlin类的典型用法代码示例。如果您正苦于以下问题:C++ Perlin类的具体用法?C++ Perlin怎么用?C++ Perlin使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Perlin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void Particle::update(const Perlin &perlin)
{
// get Perlin noise value based on my location and
// elapsed seconds and turn this noise value into an angle.
float nX = mLoc.x * 0.005f;
float nY = mLoc.y * 0.005f;
float nZ = app::getElapsedSeconds() * 0.1f;
float noise = perlin.fBm( nX, nY, nZ );
float angle = noise * 15.0f;
Vec3f noiseVector( cos( angle ), sin (angle), cos(angle));
mVel += noiseVector * 0.3f * ( 1.0f - mAgePercentage );
mLoc += mVel;
mVel *= mDecay;
if (mLoc.x > 0 && mLoc.x < getWindowWidth() ) {
mXPercentage = (float) mLoc.x / (float) getWindowWidth();
}
if (mLoc.y > 0 && mLoc.y < getWindowWidth() ) {
mYPercentage = (float) mLoc.y / (float) getWindowHeight();
}
if (mAge > mLifespan) {
mIsDead = true;
} else {
mAge++;
mAgePercentage = (float) mAge / (float) mLifespan;
}
}
示例2: update
void svvimApp::update() {
float noise = mPerlinGenerator.fBm(Vec2f(0., app::getElapsedSeconds()));
app::console() << noise << "\n";
// Update alpha values
getAlpha();
if (mPoolWaterMovie)
mMaskTexture = mPoolWaterMovie.getTexture();
if (mCurrentMovie.isDone()) {
incrementMovie();
}
app::console() << 10 * app::getElapsedSeconds() << "\n";
mImageTexture = mCurrentMovie.getTexture();
//mImageTexture = mCurrentBgTexture;
// ...
}
示例3: Step
void Particle::Step(float pElapsed, const Perlin &pNoise)
{
Age--;
if (Age>0)
{
PAlpha = math<float>::min(1, ((float)Age * 0.5f * (float)Age) / (float)mLifeSpan);
PPosition.y += mVelocity.y;
float cNoise = pNoise.fBm(vec3(PPosition.x*0.005f, PPosition.y*0.01f, PPosition.z*0.005f));
float cAngle = cNoise*15.0f;
PPosition.x += (cos(cAngle)*mVelocity.x*(1.0f-PAlpha))*0.1f;
PPosition.z += (sin(cAngle)*mVelocity.z*(1.0f - PAlpha))*0.1f;
mVelocity.x *= 1.001f;
mVelocity.y *= .99999f;
mVelocity.z *= 1.001f;
float elapsedFrames = pElapsed;
//PModelMatrix = mat4();
//PModelMatrix = glm::rotate(PModelMatrix, mRotSpeed *elapsedFrames* 0.2f, vec3(0, 0, 1));
//PModelMatrix = glm::rotate(PModelMatrix, mRotSpeed *elapsedFrames* 0.2f, vec3(1, 0, 0));
//PModelMatrix = glm::rotate(PModelMatrix, mRotSpeed *elapsedFrames* 0.2f, vec3(0, 1, 0));
//PModelMatrix = glm::translate(PModelMatrix, PPosition);
}
}
示例4: update
void Corrdinate_spacesApp::update()
{
vector<Vec3f> positions;
positions.resize(4);
for( int i=0;i<positions.size();i++ ){
Perlin p;
positions[i] = 3. * ( p.dnoise( getElapsedSeconds()+i,
getElapsedSeconds()+i*2,
getElapsedSeconds() ) * 2 - Vec3f(1.,1.,1.) );
}
mVboMesh->bufferPositions(positions);
mVboMesh->unbindBuffers();
}
示例5: vec3
void BasicParticleApp::update()
{
mAnimationCounter += 10.0f; // move ahead in time, which becomes the z-axis of our 3D noise
// Save off the last position for drawing lines
for( list<Particle>::iterator partIt = mParticles.begin(); partIt != mParticles.end(); ++partIt )
partIt->mLastPosition = partIt->mPosition;
// Add some perlin noise to the velocity
for( list<Particle>::iterator partIt = mParticles.begin(); partIt != mParticles.end(); ++partIt ) {
vec3 deriv = mPerlin.dfBm( vec3( partIt->mPosition.x, partIt->mPosition.y, mAnimationCounter ) * 0.001f );
partIt->mZ = deriv.z;
vec2 deriv2 = normalize( vec2( deriv.x, deriv.y ) );
partIt->mVelocity += deriv2 * SPEED;
}
// Move the particles according to their velocities
for( list<Particle>::iterator partIt = mParticles.begin(); partIt != mParticles.end(); ++partIt )
partIt->mPosition += partIt->mVelocity;
// Dampen the velocities for the next frame
for( list<Particle>::iterator partIt = mParticles.begin(); partIt != mParticles.end(); ++partIt )
partIt->mVelocity *= CONSERVATION_OF_VELOCITY;
// Replace any particles that have gone offscreen with a random onscreen position
for( list<Particle>::iterator partIt = mParticles.begin(); partIt != mParticles.end(); ++partIt ) {
if( isOffscreen( partIt->mPosition ) )
*partIt = Particle( vec2( Rand::randFloat( getWindowWidth() ), Rand::randFloat( getWindowHeight() ) ) );
}
}
示例6: generateTexture2D
int generateTexture2D(char *framebuffer, int width, int height, char* imagePx) {
GzColor textureColor = { 0, 0, 0 };
int finalColor[] = { 0, 0, 0 };
char *copybuffer = framebuffer;
Perlin *per = new Perlin(4, 6.5, 0.5, 10);
for (float x = 0; x < 256; x += 1) {
for (float y = 0; y < 256; y += 1) {
float noise = per->Get(x, y);
//float noise = perlin_type1_2D(x, y);
textureColor[RED] = finddensity(y, x, 256, 256, noise, 145);
textureColor[GREEN] = finddensity(y, x, 256, 256, noise, 145);
//textureColor[RED] = noise;
//textureColor[GREEN] = noise;
textureColor[BLUE] = 0.8;
finalColor[RED] = (int)(textureColor[RED] * 255);
finalColor[GREEN] = (int)(textureColor[GREEN] * 255);
finalColor[BLUE] = (int)(textureColor[BLUE] * 255);
if (finalColor[RED] > 255)
finalColor[RED] = 255;
if (finalColor[RED] < 0)
finalColor[RED] = 0;
if (finalColor[GREEN] > 255)
finalColor[GREEN] = 255;
if (finalColor[GREEN] < 0)
finalColor[GREEN] = 0;
if (finalColor[BLUE] > 255)
finalColor[BLUE] = 255;
if (finalColor[BLUE] < 0)
finalColor[BLUE] = 0;
*(framebuffer++) = (char)(finalColor[RED]);
*(framebuffer++) = (char)(finalColor[GREEN]);
*(framebuffer++) = (char)(finalColor[BLUE]);
}
}
return 0;
}
示例7: CreateNoiseTexture
unsigned int TextureLoader::CreateNoiseTexture(double alpha, double beta, int n, int side) {
Perlin perlin;
float* data = new float[side*side*side];
double step = 1.0/(side-1.0);
int index = 0;
for (double x = 0; x <= 1; x += step) {
for (double y = 0; y <= 1; y += step) {
for(double z = 0; z <= 1; z += step) {
float noise = static_cast<float>(perlin.PerlinNoise3D(x, y, z, alpha, beta, n));
data[index] = noise;
index++;
}
}
}
//create the OpenGL texture
unsigned int gl_texture_object;
glGenTextures(1, &gl_texture_object);
glBindTexture(GL_TEXTURE_3D, gl_texture_object);
//filtering
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
float maxAnisotropy;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy);
//when we work with textures of sizes not divisible by 4 we have to use the line reader
//which loads the textures in OpenGL so as it can work with a 1 alligned memory (default is 4)
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
//Generates texture
glTexImage3D(GL_TEXTURE_3D, 0, GL_R32F, side, side, side, 0, GL_RED, GL_FLOAT, data);
//eliminates the array from the RAM
delete data;
//creates the mipmap hierarchy
glGenerateMipmap(GL_TEXTURE_3D);
//returns the texture object
return gl_texture_object;
}
示例8: Color
void CinderGridApp::draw()
{
gl::clear( Color( 0, 0, 0 ));
Perlin perlin;
for(int y = 0; y < 100; y++) {
for(int x = 0; x < 100; x++) {
float noiseVal = perlin.noise(x * 0.05, y * 0.15, frameCount / 50.0f);
float r = ((0.3 + noiseVal) * (0.3 + noiseVal)) * 8.;
float gridSpace = 10;
gl::color(noiseVal + 0.3, 1.0 - (noiseVal * 0.5), (noiseVal + 0.8) / 2.);
gl::drawSolidCircle( Vec2f((gridSpace * x), (gridSpace * y)) , r);
}
}
frameCount++;
}
示例9: p00
void TerrainApp::addQuad( int x, int y )
{
Vec2f p00( x, y );
Vec2f p10( x + 1, y );
Vec2f p11( x + 1, y + 1 );
Vec2f p01( x, y + 1 );
float zScale = mHeight;
float noiseScale = mNoiseScale;
float z00 = zScale * mPerlin.fBm( p00 * noiseScale );
float z10 = zScale * mPerlin.fBm( p10 * noiseScale );
float z11 = zScale * mPerlin.fBm( p11 * noiseScale );
float z01 = zScale * mPerlin.fBm( p01 * noiseScale );
size_t idx = mTriMesh.getNumVertices();
// positions
Vec3f t00( p00.x - xSize / 2., z00, p00.y - ySize / 2. );
Vec3f t10( p10.x - xSize / 2., z10, p10.y - ySize / 2. );
Vec3f t11( p11.x - xSize / 2., z11, p11.y - ySize / 2. );
Vec3f t01( p01.x - xSize / 2., z01, p01.y - ySize / 2. );
mTriMesh.appendVertex( t00 );
mTriMesh.appendVertex( t10 );
mTriMesh.appendVertex( t01 );
mTriMesh.appendVertex( t10 );
mTriMesh.appendVertex( t11 );
mTriMesh.appendVertex( t01 );
// normals
Vec3f n0 = ( t10 - t00 ).cross( t10 - t01 ).normalized();
Vec3f n1 = ( t11 - t10 ).cross( t11 - t01 ).normalized();
mTriMesh.appendNormal( n0 );
mTriMesh.appendNormal( n0 );
mTriMesh.appendNormal( n0 );
mTriMesh.appendNormal( n1 );
mTriMesh.appendNormal( n1 );
mTriMesh.appendNormal( n1 );
mTriMesh.appendTriangle( idx, idx + 1, idx + 2 );
mTriMesh.appendTriangle( idx + 3, idx + 4, idx + 5 );
}
示例10: init
///Initializes the image by performing all perlin, mesh, heightmap, and other calls that generate the terrain.
void init(){
glfwEnable(GLFW_KEY_REPEAT);
///--- Initializes the Perlin noise texture
///--- Initializes the fBm texture
///--- Sets background color
glClearColor(/*gray*/ .8,.8,.8, /*solid*/1.0 );
glEnable(GL_DEPTH_TEST);
///--- Initlializes the terrain quad mesh (?takes the fBm as an input for displacing the height of vertices?)
quad.init(perlin.init());
}
示例11: copyNoiseToHeightmap
void copyNoiseToHeightmap(Perlin& pn, RECT rc, HeightMap<T>* pHMap, int tMax)
{
int x,y;
float xStep = 1.0f/(rc.right-rc.left);
float yStep = 1.0f/(rc.bottom-rc.top);
//Perlin产生的值域在[-振幅,+振幅]之间
//--缩放到0-255的区间
float offset = pn.GetAmplitude();
float range = pn.GetAmplitude()*2;
for(y=rc.top; y<rc.bottom; y++)
{
for(x=rc.left; x<rc.right; x++)
{
float n = pn.Get(x*xStep, y*yStep);
T tn = T((n+offset)/range*tMax);
pHMap->setValue(x, y, tn);
}
}//endof for
}
示例12: update
void FurPoint::update(const Perlin &perlin, float stepX, float stepY, float stepZ){
if (1.0f - age / lifetime <= 0.0f) isDead = true;
if (position.x < 0 || position.x > getWindowWidth()) isDead = true;
if (position.y < 0 || position.y > getWindowHeight()) isDead = true;
noiseFloat = perlin.fBm( position.x * stepX, position.y * stepY, getElapsedFrames() * stepZ );
noiseVec.x = cos(((noiseFloat) * M_PI_2) * 10.0f);
noiseVec.y = sin(((noiseFloat) * M_PI_2) * 10.0f);
velocity += noiseVec;
velocity *= 0.5f;
position += velocity;
age++;
}
示例13: Perlin
void Water::createHeightMap(){
Perlin noise = Perlin(40);
float channelSize = 400 ;
cout << "Creating water height map - " << endl ;
Channel heightMapChannel = Channel8u(channelSize, channelSize);
Channel::Iter iter = heightMapChannel.getIter( heightMapChannel.getBounds());
float max_value = -1.0 ;
float min_value = 10001.0 ;
while(iter.line()){
while(iter.pixel()){
Vec2f current = iter.getPos();
float value = 255.0F * noise.fBm(5 * current.x/channelSize, 5 * current.y/channelSize);
if( value > max_value){
max_value = value ;
}
if( value < min_value){
min_value = value ;
}
}
}
iter = heightMapChannel.getIter( heightMapChannel.getBounds());
while(iter.line()){
while(iter.pixel()){
Vec2f current = iter.getPos();
float value = 255.0f * noise.fBm(5 * current.x/channelSize, 5 * current.y/channelSize);
value = 255.0f * (value - min_value) / (max_value - min_value);
iter.v() = value ;
}
}
heightMap = gl::Texture(heightMapChannel);
cout << min_value << " " << max_value << endl ;
cout << "Done creating water height map" << endl;
}
示例14: clock
void BasicParticleApp::setup()
{
mPerlin.setSeed( clock() );
mAnimationCounter = 0;
for( int s = 0; s < NUM_INITIAL_PARTICLES; ++s )
mParticles.push_back( Particle( Vec2f( Rand::randFloat( getWindowWidth() ), Rand::randFloat( getWindowHeight() ) ) ) );
CONSERVATION_OF_VELOCITY = 0.9f;
SPEED = 5.0f;
// Turn on additive blending
gl::enableAlphaBlending();
}
示例15: setup
void cApp::setup(){
setWindowPos( 0, 0 );
setWindowSize( mW*0.5, mH*0.5 );
mExp.setup( mW*mScale, mH*mScale,0, 2999, GL_RGB, mt::getRenderPath() );
mPln.setOctaves(4);
mPln.setSeed(1332);
randSeed( mt::getSeed() );
int count = 0;
for( int i=0; i<100; i++){
StrangeAgent sa;
sa.setRandom();
mSAs.push_back( sa );
for(int j=0; j<sa.points.size(); j++){
mPlnPts.push_back( Vec3f(count*scale,0,0) );
count++;
}
}
total = count;
if( 1 ){
CameraPersp cam;
cam.setNearClip(0.1);
cam.setFarClip(1000000);
cam.setFov(60);
cam.setEyePoint( Vec3f(0,0,-30 ) );
cam.setCenterOfInterestPoint( Vec3f(0,0,0) );
cam.setAspectRatio( (float)mW/mH );
mCamUi.setCurrentCam(cam);
}else{
ortho.setNearClip(0.1);
ortho.setFarClip(1000000);
ortho.setEyePoint( Vec3f(0,0,-7 ) );
ortho.setCenterOfInterestPoint( Vec3f(0,0,0) );
ortho.setAspectRatio( (float)mW/mH );
}
#ifdef RENDER
mExp.startRender();
#endif
}