📄 leaf.cpp
字号:
#include "stdafx.h"
#include "Leaf.h"
#include "ChGL.h"
#include <GL/glut.h>
Leaf::Leaf( float size, float twist, float expand, char* bmpPath ) {
// scales = 0.5f;
this->size = size;
this->twist = twist;
this->expand = expand + 10;
this->visible = true;
this->shakeble = false;
ChGL::loadTexture( bmpPath, &texture, true );
}
Leaf::~Leaf() {
}
void Leaf::draw() {
glBindTexture( GL_TEXTURE_2D, texture );
int randExpand = 0;
int randTwist = 0;
glPushMatrix();
//glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE );
//glDisable( GL_DEPTH_TEST );
glEnable( GL_BLEND ); // Enable Blending (disable alpha testing)
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glBindTexture( GL_TEXTURE_2D, texture );
if ( shakeble == true && ( rand() % 10 < 1 ) ) {
randExpand = 5 -rand() % 10;
}
if ( shakeble == true && ( rand() % 10 < 1 ) ) {
randTwist = 5 - rand() % 10;
}
glRotatef( randExpand, 1.0f, 0.0f, 0.0f );
glRotatef( randTwist, 0.0f, 1.0f, 0.0f );
glBegin( GL_QUADS );
glNormal3f( 1.0f, -1.0f, 1.0f );
glTexCoord2f( 1.0f, 0.0f );
glVertex3f( size, 0.0f, 0.0f );
glNormal3f( 1.0f, 1.0f, 1.0f );
glTexCoord2f( 1.0f, 1.0f );
glVertex3f( size, size * 2, 0.0f );
glNormal3f( -1.0f, 1.0f, 1.0f );
glTexCoord2f( 0.0f, 1.0f );
glVertex3f( -size, size * 2, 0.0f );
glNormal3f( -1.0f, -1.0f, 1.0f );
glTexCoord2f( 0.0f, 0.0f );
glVertex3f( -size, 0.0f, 0.0f );
glEnd();
glDisable( GL_BLEND );
//glEnable( GL_DEPTH_TEST );
//glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE );
glPopMatrix();
}
void Leaf::setSize( float size ) {
this->size = size;
}
void Leaf::setTwist( float twist ) {
this->twist = twist;
}
void Leaf::setExpand( float expand ) {
this->expand = expand;
}
void Leaf::setVisible( bool visible ) {
this->visible = visible;
}
void Leaf::setShakeble( bool shakeble ) {
this->shakeble = shakeble;
}
void Leaf::setTexture( char *bmpPath ) {
ChGL::loadTexture( bmpPath, &texture, true );
}
int Leaf::getSize() {
return size;
}
float Leaf::getTwist() {
return twist;
}
float Leaf::getExpand() {
return expand;
}
bool Leaf::isVisible() {
return visible;
}
bool Leaf::isShakeble() {
return shakeble;
}
unsigned int Leaf::getTexture() {
return texture;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -