1.) Remove artifacts from bike animation
2.) Normalize FPS
https://youtu.be/nl96ZvXI_3Q
Bike animation I made by atlas: 256x80 - 4 frames
Scale/Scroll UV coordinates.
Code: Select all
animtime++;
if(animtime>6)animtime=0;
if(receiver.IsKeyDown(KEY_KEY_A)) {
playerNode->setSize ( dimension2df(-32,-40) ) ;
if(animtime<3) playerNode->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0.5f,0);
else playerNode->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0.75f,0);
if(dy<40)dy+=4;
}
else if(receiver.IsKeyDown(KEY_KEY_D)) {
playerNode->setSize ( dimension2df(32,40) ) ;
if(animtime<3) playerNode->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0.5f,0);
else playerNode->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0.75f,0);
if(dy>-40)dy-=4;
}
else {
if(dy>0)dy-=4;
if(dy<0)dy+=4;
if(animtime<3)playerNode->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0,0);
else playerNode->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0.25f,0);
}
objects are selected from atlas: 256x256
each billboard is a unique node.
Terrain ass one polygon and animate by UV scroll
Code: Select all
#ifndef ENVIRONMENT_H_INCLUDED
#define ENVIRONMENT_H_INCLUDED
#include "Globalvar.h"
#include "Player.h"
#include <cstdlib>
class Environment
{
public:
IMeshSceneNode * gndNode;
IBillboardSceneNode* levelNode[50];
struct myObjects
{
int type;
vector3df Pos;
};
myObjects objects[50];
IMesh* gndmesh;
IMesh* fogPlane;
float scroll,gndScroll;
IMeshSceneNode* fognode;
ITexture *texObj1;
Environment(){
}
void initNode(int num, ITexture* tex,vector3df pos ){
}
void init(){
texObj1= driver->getTexture("spr/objects.png");
for(int i=0;i<50;i++){
objects[i].Pos.X=rand()%500;
objects[i].Pos.Z=rand()%1000;
objects[i].type=rand()%5;
levelNode[i]= smgr->addBillboardSceneNode();
levelNode[i]->setMaterialTexture(0, texObj1);
levelNode[i]->setMaterialFlag(EMF_LIGHTING, false);
levelNode[i]->setMaterialFlag(EMF_FOG_ENABLE,true);
levelNode[i]->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
levelNode[i]->setMaterialFlag(EMF_BILINEAR_FILTER, false);
levelNode[i]->setAutomaticCulling(EAC_FRUSTUM_BOX);
levelNode[i]->setMaterialFlag(EMF_FOG_ENABLE,true);
switch ( objects[i].type )
{
case 0:
objects[i].Pos.Y=64;
levelNode[i]->setSize ( dimension2df(64,128) ) ;
levelNode[i]->getMaterial(0).getTextureMatrix(0).setScale(vector3df(0.25f,0.5f,0));
levelNode[i]->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0.75f,0);
break;
case 1:
objects[i].Pos.Y=64;
levelNode[i]->setSize ( dimension2df(64,128) ) ;
levelNode[i]->getMaterial(0).getTextureMatrix(0).setScale(vector3df(0.25f,0.5f,0));
levelNode[i]->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0.75f,0.5f);
break;
case 2:
objects[i].Pos.Y=80;
levelNode[i]->setSize( dimension2df(192,192)) ;
levelNode[i]->getMaterial(0).getTextureMatrix(0).setScale(vector3df(0.75f,0.75f,0));
levelNode[i]->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0,0.33f);
break;
case 3: objects[i].Pos.Y=32;
levelNode[i]->setSize( dimension2df(96,64)) ;
levelNode[i]->getMaterial(0).getTextureMatrix(0).setScale(vector3df(0.375f,0.25f,0));
levelNode[i]->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0,0);
break;
case 4: objects[i].Pos.Y=32;
levelNode[i]->setSize( dimension2df(96,64)) ;
levelNode[i]->getMaterial(0).getTextureMatrix(0).setScale(vector3df(0.375f,0.25f,0));
levelNode[i]->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0.375f,0);
break;
}
levelNode[i]->setPosition(objects[i].Pos);
}
gndmesh=smgr->getMesh("spr/plane2.obj");
gndmesh->setMaterialFlag(EMF_LIGHTING, false);
gndNode = smgr->addMeshSceneNode(gndmesh);
gndNode->setMaterialTexture( 0, driver->getTexture("spr/terrain.png") );
gndNode->setMaterialFlag(EMF_TRILINEAR_FILTER,false);
gndNode->setMaterialFlag(EMF_FOG_ENABLE,true);
gndNode->setMaterialFlag(EMF_LIGHTING, false);
gndNode->setScale(vector3df(100,0,100));
gndNode->setPosition(vector3df(500,0,00));
gndNode->setRotation(vector3df(180,0,0));
gndNode->getMaterial(0).getTextureMatrix(0).setScale(vector3df(25,25,0));
gndNode->setMaterialFlag(EMF_BACK_FACE_CULLING, false);
fogPlane=smgr->getMesh("spr/plane2.obj");
fogPlane->setMaterialFlag(EMF_LIGHTING, false);
fognode = smgr->addMeshSceneNode(fogPlane);
fognode->setMaterialTexture( 0, driver->getTexture("spr/fog.png") );
fognode->setMaterialFlag(EMF_TRILINEAR_FILTER,true);
fognode->setMaterialFlag(EMF_FOG_ENABLE,true);
fognode->setScale(vector3df(100,0,100));
fognode->setPosition(vector3df(500,170,00));
fognode->setRotation(vector3df(180,0,0));
fognode->getMaterial(0).getTextureMatrix(0).setScale(vector3df(10,10,0));
}
void update(float speed)
{
for(int i=0;i<50;i++){
objects[i].Pos.Z+=speed*160;
levelNode[i]->setPosition(objects[i].Pos);
if(objects[i].Pos.Z>1000)objects[i].Pos.Z=0;
}
gndScroll +=speed;
fognode->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0,gndScroll);
gndNode->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0,gndScroll);
levelNode[1]->setPosition(vector3df(0,80,100));
}
};
#endif // ENVIRONMENT_H_INCLUDED