NLS Engine  v0.1
The Next Logical Step in game engine design.
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines
TextureScroller.cpp
Go to the documentation of this file.
00001 
00010 #pragma once
00011 
00012 #include "TextureScroller.h"
00013 
00014 // Standard Includes
00015 #include <string>
00016 
00017 // Library Includes
00018 #include <d3dx9.h>
00019 
00020 // Local Includes
00021 #include "../RenderModule.h"
00022 #include "TexturesSystemInterface.h"
00023 
00024 // Forward Declarations
00025 
00026 // Typedefs
00027 
00028 // Local Constants
00029 namespace GraphicsCore {
00030   static const float TWO_PI = 6.283185307179586476925286766559f;
00031 }
00032 
00033 
00034 namespace GraphicsCore {
00035   TextureScroller::TextureScroller() {
00036     this->Init(0.0f, 0.0f, 0.0f);
00037   }
00038   
00039   TextureScroller::TextureScroller(TextureInterface* texture) {
00040     this->Init(0.0f, 0.0f, 0.0f);
00041     this->texture = texture;
00042   }
00043   
00044   TextureScroller::~TextureScroller() {
00045     if (this->texture != nullptr) {
00046       TexturesSystemInterface::DestroyTexture(this->texture);
00047     }
00048   }
00049   
00050   /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00051   void TextureScroller::SetUVVelocity(float u_vel, float v_vel) {
00052     this->SetUVelocity(u_vel);
00053     this->SetVVelocity(v_vel);
00054   }
00055   
00056   /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00057   void TextureScroller::SetUVelocity(float u_vel) {
00058     this->velocity.u = u_vel;
00059   }
00060   
00061   /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00062   void TextureScroller::SetVVelocity(float v_vel) {
00063     this->velocity.v = v_vel;
00064   }
00065   
00066   /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00067   void TextureScroller::SetAngularVelocity(float angle_vel) {
00068     while (angle_vel > TWO_PI) {
00069       angle_vel -= TWO_PI;
00070     }
00071     while (angle_vel < -TWO_PI) {
00072       angle_vel += TWO_PI;
00073     }
00074     
00075     this->velocity.a = angle_vel;
00076   }
00077   
00078   /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00079   void TextureScroller::Apply(LPDIRECT3DDEVICE9 d3d_device) {
00080     d3d_device->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
00081     d3d_device->SetTransform(D3DTS_TEXTURE0, &this->currentMatrix);
00082     if (this->texture != nullptr) {
00083       this->texture->Apply(d3d_device);
00084     }
00085   }
00086   
00087   /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00088   void TextureScroller::Update(double dt) {
00089     // Translate the matrix
00090     this->currentMatrix._31 += (float) (this->velocity.u * dt);
00091     this->currentMatrix._32 += (float) (this->velocity.v * dt);
00092     
00093     // *TODO: the rotation parts of the matrix
00094     
00095   }
00096   
00097   /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00098   void TextureScroller::Init(float u_vel, float v_vel, float angle_vel) {
00099     this->texture = nullptr;
00100     
00101     this->SetUVVelocity(u_vel, v_vel);
00102     this->SetAngularVelocity(angle_vel);
00103     
00104     D3DXMatrixIdentity(&this->currentMatrix);
00105   }
00106   
00107 }