absence_thelab

diff src/3deng/objects.cpp @ 0:1cffe3409164

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 23 Oct 2014 01:46:07 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/3deng/objects.cpp	Thu Oct 23 01:46:07 2014 +0300
     1.3 @@ -0,0 +1,557 @@
     1.4 +#include "objects.h"
     1.5 +#include "3dengine.h"
     1.6 +#include "objectgen.h"
     1.7 +
     1.8 +Object::Object(GraphicsContext *gc, byte DetailLevels) {
     1.9 +	this->gc = gc;
    1.10 +
    1.11 +	mesh = new TriMesh(DetailLevels, gc);
    1.12 +
    1.13 +	SetShadingMode(GouraudShading);
    1.14 +	SetVertexProgram(FixedFunction);
    1.15 +	SetPixelProgram(0);
    1.16 +	rendp.Billboarded = false;
    1.17 +	rendp.SourceBlendFactor = BLEND_SRCALPHA;
    1.18 +	rendp.DestBlendFactor = BLEND_INVSRCALPHA;
    1.19 +	rendp.ZWrite = true;
    1.20 +	ShadowCount = 0;
    1.21 +	UseTextureMatrix = false;
    1.22 +
    1.23 +	ShadowVolumes = 0;
    1.24 +	CastShadows = false;
    1.25 +
    1.26 +	AutoSetZWrite = true;
    1.27 +}
    1.28 +
    1.29 +Object::~Object() {
    1.30 +	delete mesh;
    1.31 +	if(rendp.VertexProgram != FixedFunction) gc->DestroyVertexProgram(rendp.VertexProgram);
    1.32 +}
    1.33 +
    1.34 +TriMesh *Object::GetTriMesh() {
    1.35 +	return mesh;
    1.36 +}
    1.37 +
    1.38 +
    1.39 +// Reset Transformation Matrices
    1.40 +void Object::ResetTransform() {
    1.41 +	TransMat.ResetIdentity();
    1.42 +	RotMat.ResetIdentity();
    1.43 +	GRotMat.ResetIdentity();
    1.44 +	ScaleMat.ResetIdentity();
    1.45 +}
    1.46 +
    1.47 +void Object::ResetTranslation() { 
    1.48 +	TransMat.ResetIdentity();
    1.49 +}
    1.50 +
    1.51 +void Object::ResetRotation() {
    1.52 +	RotMat.ResetIdentity();
    1.53 +}
    1.54 +
    1.55 +void Object::ResetGlobalRotation() {
    1.56 +	GRotMat.ResetIdentity();
    1.57 +}
    1.58 +
    1.59 +void Object::ResetScaling() {
    1.60 +	ScaleMat.ResetIdentity();
    1.61 +}
    1.62 +
    1.63 +// Concatenate additional transformations
    1.64 +void Object::Translate(float tx, float ty, float tz) {
    1.65 +	TransMat.Translate(tx, ty, tz);
    1.66 +}
    1.67 +
    1.68 +void Object::Rotate(float rx, float ry, float rz) {
    1.69 +	RotMat.Rotate(rx, ry, rz);
    1.70 +}
    1.71 +
    1.72 +void Object::Rotate(const Vector3 &axis, float angle) {
    1.73 +	RotMat.Rotate(axis, angle);
    1.74 +}
    1.75 +
    1.76 +void Object::Rotate(const Matrix4x4 &rot) {
    1.77 +	RotMat *= rot;
    1.78 +}
    1.79 +
    1.80 +void Object::GlobalRotate(float rx, float ry, float rz) {
    1.81 +	GRotMat.Rotate(rx, ry, rz);
    1.82 +}
    1.83 +
    1.84 +void Object::GlobalRotate(const Vector3 &axis, float angle) {
    1.85 +	GRotMat.Rotate(axis, angle);
    1.86 +}
    1.87 +
    1.88 +void Object::GlobalRotate(const Matrix4x4 &rot) {
    1.89 +	GRotMat *= rot;
    1.90 +}
    1.91 +
    1.92 +void Object::Scale(float sx, float sy, float sz) {
    1.93 +	ScaleMat.Scale(sx, sy, sz);
    1.94 +}
    1.95 +
    1.96 +void Object::SetTranslation(float tx, float ty, float tz) {
    1.97 +	TransMat.SetTranslation(tx, ty, tz);
    1.98 +}
    1.99 +
   1.100 +void Object::SetRotation(float rx, float ry, float rz) {
   1.101 +	RotMat.Rotate(rx, ry, rz);
   1.102 +}
   1.103 +
   1.104 +void Object::SetRotation(const Vector3 &axis, float angle) {
   1.105 +	RotMat.Rotate(axis, angle);
   1.106 +}
   1.107 +
   1.108 +void Object::SetRotation(const Matrix4x4 &rot) {
   1.109 +	RotMat = rot;
   1.110 +}
   1.111 +
   1.112 +void Object::SetGlobalRotation(float rx, float ry, float rz) {
   1.113 +	GRotMat.Rotate(rx, ry, rz);
   1.114 +}
   1.115 +
   1.116 +void Object::SetGlobalRotation(const Vector3 &axis, float angle) {
   1.117 +	GRotMat.Rotate(axis, angle);
   1.118 +}
   1.119 +
   1.120 +void Object::SetGlobalRotation(const Matrix4x4 &rot) {
   1.121 +	GRotMat = rot;
   1.122 +}
   1.123 +
   1.124 +void Object::SetScaling(float sx, float sy, float sz) {
   1.125 +	ScaleMat.Scale(sx, sy, sz);
   1.126 +}
   1.127 +
   1.128 +const Matrix4x4 Object::GetWorldTransform() const {
   1.129 +	return ScaleMat * RotMat * TransMat * GRotMat;
   1.130 +}
   1.131 +
   1.132 +void Object::SetTextureMatrix(Matrix4x4 mat) {
   1.133 +	UseTextureMatrix = true;
   1.134 +	TextureMatrix = mat;
   1.135 +}
   1.136 +
   1.137 +Matrix4x4 Object::GetTextureMatrix() const {
   1.138 +	return TextureMatrix;
   1.139 +}
   1.140 +
   1.141 +void Object::SetVertexProgram(dword VertexProgram) {
   1.142 +	rendp.VertexProgram = VertexProgram;
   1.143 +}
   1.144 +
   1.145 +void Object::SetPixelProgram(dword PixelProgram) {
   1.146 +	rendp.PixelProgram = PixelProgram;
   1.147 +}
   1.148 +
   1.149 +void Object::SetShadingMode(ShadeMode smode) {
   1.150 +	rendp.Shading = smode;
   1.151 +}
   1.152 +
   1.153 +void Object::SetWriteZBuffer(bool enable) {
   1.154 +	rendp.ZWrite = enable;
   1.155 +	AutoSetZWrite = false;
   1.156 +}
   1.157 +
   1.158 +void Object::SetBlendFunc(BlendingFactor src, BlendingFactor dest) {
   1.159 +	rendp.SourceBlendFactor = src;
   1.160 +	rendp.DestBlendFactor = dest;
   1.161 +}
   1.162 +
   1.163 +void Object::GetBlendFunc(BlendingFactor *src, BlendingFactor *dest) {
   1.164 +	*src = rendp.SourceBlendFactor;
   1.165 +	*dest = rendp.DestBlendFactor;
   1.166 +}
   1.167 +
   1.168 +void Object::CalculateShadows(const Light **lights, int LightCount) {
   1.169 +	if(ShadowVolumes) {
   1.170 +		for(int i=0; i<ShadowCount; i++) {
   1.171 +			delete ShadowVolumes[i];
   1.172 +		}
   1.173 +		delete ShadowVolumes;
   1.174 +	}
   1.175 +
   1.176 +	ShadowVolumes = new TriMesh*[LightCount];
   1.177 +	for(int i=0; i<LightCount; i++) {
   1.178 +		ShadowVolumes[i] = CreateShadowVolume(*mesh, lights[i], GetWorldTransform());
   1.179 +	}
   1.180 +
   1.181 +	ShadowCount = LightCount;
   1.182 +}
   1.183 +
   1.184 +TriMesh *Object::GetShadowVolume(int light) {
   1.185 +	if(light >= ShadowCount) return 0;
   1.186 +	return ShadowVolumes[light];
   1.187 +}
   1.188 +
   1.189 +void Object::SetShadowCasting(bool enable) {
   1.190 +	CastShadows = enable;
   1.191 +}
   1.192 +
   1.193 +bool Object::GetShadowCasting() const {
   1.194 +	return CastShadows;
   1.195 +}
   1.196 +
   1.197 +///////////////////////////
   1.198 +
   1.199 +void Object::SetRenderStates() {
   1.200 +	gc->SetWorldMatrix(GetWorldTransform());
   1.201 +	
   1.202 +	gc->SetMaterial(material);
   1.203 +	if(AutoSetZWrite && material.Alpha < 0.991f) rendp.ZWrite = false;
   1.204 +	gc->SetSpecular(material.SpecularEnable);
   1.205 +
   1.206 +	gc->SetVertexProgram(rendp.VertexProgram);
   1.207 +	gc->SetPixelProgram(rendp.PixelProgram);
   1.208 +	gc->SetShadingMode(rendp.Shading);
   1.209 +}
   1.210 +
   1.211 +void Object::Render() {
   1.212 +	int TexUnits = gc->GetTextureStageNumber();
   1.213 +
   1.214 +	if(TexUnits < 4) {
   1.215 +		Render2TexUnits();
   1.216 +	} else if(TexUnits < 8) {
   1.217 +		Render4TexUnits();
   1.218 +	} else {
   1.219 +		Render8TexUnits();
   1.220 +	}
   1.221 +}
   1.222 +
   1.223 +void Object::Render2TexUnits() {
   1.224 +
   1.225 +	SetRenderStates();
   1.226 +
   1.227 +	VertexBuffer *vb = const_cast<VertexBuffer*>(mesh->GetVertexBuffer());
   1.228 +	IndexBuffer *ib = const_cast<IndexBuffer*>(mesh->GetIndexBuffer());
   1.229 +
   1.230 +	Material mat = material;
   1.231 +
   1.232 +	int TexCount = 0;
   1.233 +	for(int i=0; i<NumberOfTextureTypes; i++) {
   1.234 +		if(mat.Maps[i]) TexCount++;
   1.235 +	}
   1.236 +
   1.237 +	if(!rendp.ZWrite) gc->SetZWrite(false);
   1.238 +
   1.239 +	if(!TexCount) {
   1.240 +		// render without any texture
   1.241 +		gc->SetTexture(0, 0);
   1.242 +		gc->SetTextureStageColor(0, TexBlendSelectArg1, TexArgDiffuseColor, TexArgTexture);
   1.243 +		if(mat.Alpha < 1.0f) {
   1.244 +			gc->SetTextureFactor(Color(mat.Alpha, mat.Alpha, mat.Alpha, mat.Alpha).GetPacked32());
   1.245 +			gc->SetTextureStageAlpha(0, TexBlendSelectArg1, TexArgFactor, TexArgDiffuseColor);
   1.246 +		} else {
   1.247 +			gc->SetTextureStageAlpha(0, TexBlendSelectArg1, TexArgCurrent, TexArgTexture);
   1.248 +		}
   1.249 +		gc->DisableTextureStage(1);
   1.250 +		
   1.251 +		gc->SetAlphaBlending(true);
   1.252 +		gc->SetBlendFunc(rendp.SourceBlendFactor, rendp.DestBlendFactor);
   1.253 +		gc->Draw(vb, ib);
   1.254 +		gc->SetAlphaBlending(false);
   1.255 +	} else {
   1.256 +        
   1.257 +		////////// pass 1 (texture & env) ///////////
   1.258 +		int stage = 0;
   1.259 +		if(mat.Maps[TextureMap]) {
   1.260 +			if(UseTextureMatrix) gc->SetTextureMatrix(TextureMatrix, 0);
   1.261 +            gc->SetTexture(stage, mat.Maps[TextureMap]);
   1.262 +			gc->SetTextureStageColor(stage, TexBlendModulate, TexArgCurrent, TexArgTexture);
   1.263 +			if(mat.Alpha < 1.0f) {
   1.264 +				gc->SetTextureFactor(Color(mat.Alpha, mat.Alpha, mat.Alpha, mat.Alpha).GetPacked32());
   1.265 +				gc->SetTextureStageAlpha(stage, TexBlendModulate, TexArgTexture, TexArgFactor);
   1.266 +			} else {
   1.267 +				gc->SetTextureStageAlpha(stage, TexBlendSelectArg2, TexArgCurrent, TexArgTexture);
   1.268 +			}
   1.269 +			gc->SetTextureCoordIndex(stage, 0);
   1.270 +			stage++;
   1.271 +		}
   1.272 +
   1.273 +		if(mat.Maps[EnvironmentMap]) {
   1.274 +			gc->SetTexture(stage, mat.Maps[EnvironmentMap]);
   1.275 +			gc->SetTextureStageColor(stage, TexBlendAdd, TexArgCurrent, TexArgTexture);
   1.276 +			gc->SetTextureStageAlpha(stage, TexBlendSelectArg1, TexArgCurrent, TexArgTexture);
   1.277 +			Matrix4x4 TexMat = Matrix4x4(0.5f, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 0.5f, 0.0f, 1.0f);
   1.278 +            gc->SetTextureMatrix(TexMat, stage);
   1.279 +			gc->D3DDevice->SetTextureStageState(stage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
   1.280 +			gc->D3DDevice->SetTextureStageState(stage, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACENORMAL);
   1.281 +			stage++;
   1.282 +		}
   1.283 +
   1.284 +		gc->SetTexture(stage, 0);
   1.285 +		gc->DisableTextureStage(stage);
   1.286 +
   1.287 +		if(stage > 0) {
   1.288 +			gc->SetAlphaBlending(true);
   1.289 +			gc->SetBlendFunc(rendp.SourceBlendFactor, rendp.DestBlendFactor);
   1.290 +			gc->Draw(vb, ib);
   1.291 +			gc->SetAlphaBlending(false);
   1.292 +
   1.293 +			gc->SetTextureMatrix(Matrix4x4(), 0);
   1.294 +			gc->SetTextureMatrix(Matrix4x4(), 1);
   1.295 +		}
   1.296 +
   1.297 +		////////// pass 2 (Bump & Lightmap) //////////
   1.298 +		if(stage > 0) {	// did a first pass
   1.299 +			gc->SetAlphaBlending(true);
   1.300 +			gc->SetBlendFunc(BLEND_DESTCOLOR, BLEND_ZERO);		// mult blend
   1.301 +			mat.Emissive = Color(1.0f);	// do not recalculate lighting
   1.302 +		}
   1.303 +
   1.304 +		stage = 0;
   1.305 +		if(mat.Maps[LightMap]) {
   1.306 +            gc->SetTexture(stage, mat.Maps[LightMap]);
   1.307 +			gc->SetTextureStageColor(stage, TexBlendSelectArg2, TexArgCurrent, TexArgTexture);
   1.308 +			gc->SetTextureStageAlpha(stage, TexBlendSelectArg1, TexArgCurrent, TexArgTexture);
   1.309 +			gc->SetTextureCoordIndex(stage, 1);
   1.310 +			stage++;
   1.311 +		}
   1.312 +
   1.313 +		if(mat.Maps[BumpMap]) {
   1.314 +			// re-implementation due
   1.315 +		}
   1.316 +
   1.317 +		gc->SetTexture(stage, 0);
   1.318 +		gc->DisableTextureStage(stage);
   1.319 +
   1.320 +		if(stage > 0) gc->Draw(vb, ib);
   1.321 +
   1.322 +		gc->SetAlphaBlending(false);
   1.323 +	}
   1.324 +
   1.325 +	if(!rendp.ZWrite) gc->SetZWrite(true);
   1.326 +}
   1.327 +
   1.328 +
   1.329 +void Object::Render4TexUnits() {
   1.330 +	SetRenderStates();
   1.331 +
   1.332 +	VertexBuffer *vb = const_cast<VertexBuffer*>(mesh->GetVertexBuffer());
   1.333 +	IndexBuffer *ib = const_cast<IndexBuffer*>(mesh->GetIndexBuffer());
   1.334 +
   1.335 +	Material mat = material;
   1.336 +
   1.337 +	int TexCount = 0;
   1.338 +	for(int i=0; i<NumberOfTextureTypes; i++) {
   1.339 +		if(mat.Maps[i]) TexCount++;
   1.340 +	}
   1.341 +
   1.342 +	if(!rendp.ZWrite) gc->SetZWrite(false);
   1.343 +
   1.344 +	if(!TexCount) {
   1.345 +		// render without any texture
   1.346 +		gc->SetTexture(0, 0);
   1.347 +		gc->SetTextureStageColor(0, TexBlendSelectArg1, TexArgDiffuseColor, TexArgTexture);
   1.348 +		if(mat.Alpha < 1.0f) {
   1.349 +			gc->SetTextureFactor(Color(mat.Alpha, mat.Alpha, mat.Alpha, mat.Alpha).GetPacked32());
   1.350 +			gc->SetTextureStageAlpha(0, TexBlendSelectArg1, TexArgFactor, TexArgDiffuseColor);
   1.351 +		} else {
   1.352 +			gc->SetTextureStageAlpha(0, TexBlendSelectArg1, TexArgCurrent, TexArgTexture);
   1.353 +		}
   1.354 +		gc->DisableTextureStage(1);
   1.355 +		
   1.356 +		gc->SetAlphaBlending(true);
   1.357 +		gc->SetBlendFunc(rendp.SourceBlendFactor, rendp.DestBlendFactor);
   1.358 +		gc->Draw(vb, ib);
   1.359 +		gc->SetAlphaBlending(false);
   1.360 +	} else {
   1.361 +        
   1.362 +		////////// pass 1 (texture, detail, env, bump) ///////////
   1.363 +		int stage = 0;
   1.364 +		if(mat.Maps[TextureMap]) {
   1.365 +			if(UseTextureMatrix) gc->SetTextureMatrix(TextureMatrix, 0);
   1.366 +            gc->SetTexture(stage, mat.Maps[TextureMap]);
   1.367 +			gc->SetTextureStageColor(stage, TexBlendModulate, TexArgCurrent, TexArgTexture);
   1.368 +			if(mat.Alpha < 1.0f) {
   1.369 +				gc->SetTextureFactor(Color(mat.Alpha, mat.Alpha, mat.Alpha, mat.Alpha).GetPacked32());
   1.370 +				gc->SetTextureStageAlpha(stage, TexBlendModulate, TexArgTexture, TexArgFactor);
   1.371 +			} else {
   1.372 +				gc->SetTextureStageAlpha(stage, TexBlendSelectArg2, TexArgCurrent, TexArgTexture);
   1.373 +			}
   1.374 +			gc->SetTextureCoordIndex(stage, 0);
   1.375 +			stage++;
   1.376 +		}
   1.377 +
   1.378 +		if(mat.Maps[DetailMap]) {
   1.379 +            gc->SetTexture(stage, mat.Maps[DetailMap]);
   1.380 +			gc->SetTextureStageColor(stage, TexBlendAdd, TexArgCurrent, TexArgTexture);
   1.381 +			gc->SetTextureStageAlpha(stage, TexBlendSelectArg1, TexArgCurrent, TexArgTexture);
   1.382 +			gc->SetTextureCoordIndex(stage, 1);
   1.383 +			stage++;
   1.384 +		}
   1.385 +
   1.386 +		if(mat.Maps[EnvironmentMap]) {
   1.387 +			gc->SetTexture(stage, mat.Maps[EnvironmentMap]);
   1.388 +			gc->SetTextureStageColor(stage, TexBlendAdd, TexArgCurrent, TexArgTexture);
   1.389 +			gc->SetTextureStageAlpha(stage, TexBlendSelectArg1, TexArgCurrent, TexArgTexture);
   1.390 +			Matrix4x4 TexMat = Matrix4x4(0.5f, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 0.5f, 0.0f, 1.0f);
   1.391 +            gc->SetTextureMatrix(TexMat, stage);
   1.392 +			gc->D3DDevice->SetTextureStageState(stage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
   1.393 +			gc->D3DDevice->SetTextureStageState(stage, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACENORMAL);
   1.394 +			stage++;
   1.395 +		}
   1.396 +
   1.397 +		if(mat.Maps[BumpMap]) {
   1.398 +			// re-implementation due
   1.399 +		}
   1.400 +
   1.401 +		gc->SetTexture(stage, 0);
   1.402 +		gc->DisableTextureStage(stage);
   1.403 +
   1.404 +		if(stage > 0) {
   1.405 +			gc->SetAlphaBlending(true);
   1.406 +			gc->SetBlendFunc(rendp.SourceBlendFactor, rendp.DestBlendFactor);
   1.407 +			gc->Draw(vb, ib);
   1.408 +			gc->SetAlphaBlending(false);
   1.409 +
   1.410 +			gc->SetTextureMatrix(Matrix4x4(), 0);
   1.411 +			gc->SetTextureMatrix(Matrix4x4(), 1);
   1.412 +			gc->SetTextureMatrix(Matrix4x4(), 2);
   1.413 +		}
   1.414 +
   1.415 +		////////// pass 2 (Bump & Lightmap) //////////
   1.416 +		if(stage > 0) {	// did a first pass
   1.417 +			gc->SetAlphaBlending(true);
   1.418 +			gc->SetBlendFunc(BLEND_DESTCOLOR, BLEND_ZERO);		// mult blend
   1.419 +			mat.Emissive = Color(1.0f);	// do not recalculate lighting
   1.420 +		}
   1.421 +
   1.422 +		stage = 0;
   1.423 +		if(mat.Maps[LightMap]) {
   1.424 +            gc->SetTexture(stage, mat.Maps[LightMap]);
   1.425 +			gc->SetTextureStageColor(stage, TexBlendSelectArg2, TexArgCurrent, TexArgTexture);
   1.426 +			gc->SetTextureStageAlpha(stage, TexBlendSelectArg1, TexArgCurrent, TexArgTexture);
   1.427 +			gc->SetTextureCoordIndex(stage, 1);
   1.428 +			stage++;
   1.429 +		}
   1.430 +
   1.431 +		gc->SetTexture(stage, 0);
   1.432 +		gc->DisableTextureStage(stage);
   1.433 +
   1.434 +		if(stage > 0) gc->Draw(vb, ib);
   1.435 +
   1.436 +		gc->SetAlphaBlending(false);
   1.437 +	}
   1.438 +
   1.439 +	if(!rendp.ZWrite) gc->SetZWrite(false);
   1.440 +}
   1.441 +
   1.442 +
   1.443 +void Object::Render8TexUnits() {Render4TexUnits();}
   1.444 +
   1.445 +
   1.446 +
   1.447 +/*
   1.448 +void Object::Render() {
   1.449 +
   1.450 +	SetRenderStates();
   1.451 +	
   1.452 +	VertexBuffer *vb = const_cast<VertexBuffer*>(mesh->GetVertexBuffer());
   1.453 +	IndexBuffer *ib = const_cast<IndexBuffer*>(mesh->GetIndexBuffer());
   1.454 +
   1.455 +	Material mat = material;
   1.456 +	int MapsCount = 0, ActiveTex = 0;
   1.457 +	for(int i=0; i<NumberOfTextureTypes; i++) {
   1.458 +		if(mat.Maps[i]) MapsCount++;
   1.459 +	}
   1.460 +
   1.461 +	if(!MapsCount) {
   1.462 +		gc->SetTexture(0, 0);
   1.463 +		gc->DisableTextureStage(0);
   1.464 +		gc->Draw(vb, ib);
   1.465 +	} else {
   1.466 +		int pass = 1;
   1.467 +		TextureType PassFirstTexture;
   1.468 +		while(MapsCount) {
   1.469 +			
   1.470 +			if(mat.Maps[BumpMap]) {
   1.471 +				gc->SetTexture(ActiveTex, mat.Maps[BumpMap]);
   1.472 +				//gc->SetTextureFactor() TODO
   1.473 +				gc->SetTextureStageColor(ActiveTex, TexBlendDotProduct, TexArgFactor, TexArgTexture);
   1.474 +				mat.Maps[BumpMap] = 0;
   1.475 +				if(!ActiveTex) PassFirstTexture = BumpMap;
   1.476 +			} else if(mat.Maps[TextureMap]) {
   1.477 +				gc->SetTexture(ActiveTex, mat.Maps[TextureMap]);
   1.478 +				gc->SetTextureStageColor(ActiveTex, TexBlendModulate, TexArgCurrent, TexArgTexture);
   1.479 +				//gc->SetTextureStageColor(ActiveTex, TexBlendSelectArg2, TexArgCurrent, TexArgTexture);
   1.480 +				gc->SetTextureCoordIndex(ActiveTex, 0);
   1.481 +				mat.Maps[TextureMap] = 0;
   1.482 +				if(!ActiveTex) PassFirstTexture = TextureMap;
   1.483 +			} else if(mat.Maps[DetailMap]) {
   1.484 +				gc->SetTexture(ActiveTex, mat.Maps[DetailMap]);
   1.485 +				gc->SetTextureStageColor(ActiveTex, TexBlendAdd, TexArgCurrent, TexArgTexture);
   1.486 +				gc->SetTextureCoordIndex(ActiveTex, 1);
   1.487 +				mat.Maps[DetailMap] = 0;
   1.488 +				if(!ActiveTex) PassFirstTexture = DetailMap;
   1.489 +			} else if(mat.Maps[EnvironmentMap]) {
   1.490 +				gc->SetTexture(ActiveTex, mat.Maps[EnvironmentMap]);
   1.491 +				gc->SetTextureStageColor(ActiveTex, TexBlendAdd, TexArgCurrent, TexArgTexture);
   1.492 +
   1.493 +				//gc->SetTextureCoordGenerator(TexGenSpherical); TODO
   1.494 +				Matrix4x4 TexMat = Matrix4x4(0.5f,	0.0f,	0.0f,	0.0f,
   1.495 +											0.0f,	-0.5f,	0.0f,	0.0f,
   1.496 +											0.0f,	0.0f,	1.0f,	0.0f,
   1.497 +											0.5f,	0.5f,	0.0f,	1.0f ); 
   1.498 +				gc->SetTextureMatrix(TexMat, ActiveTex);
   1.499 +				gc->D3DDevice->SetTextureStageState(ActiveTex, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
   1.500 +				gc->D3DDevice->SetTextureStageState(ActiveTex, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACENORMAL);
   1.501 +
   1.502 +				mat.Maps[EnvironmentMap] = 0;
   1.503 +				if(!ActiveTex) PassFirstTexture = EnvironmentMap;
   1.504 +			} else if(mat.Maps[LightMap]) {
   1.505 +				gc->SetTexture(ActiveTex, mat.Maps[LightMap]);
   1.506 +				gc->SetTextureStageColor(ActiveTex, TexBlendModulate, TexArgCurrent, TexArgTexture);
   1.507 +				gc->SetTextureCoordIndex(ActiveTex, 2);
   1.508 +				mat.Maps[LightMap] = 0;
   1.509 +				if(!ActiveTex) PassFirstTexture = LightMap;
   1.510 +			}
   1.511 +
   1.512 +			MapsCount--;
   1.513 +			ActiveTex++;
   1.514 +
   1.515 +			if(!MapsCount) {
   1.516 +				gc->SetTextureStageColor(ActiveTex, TexBlendModulate, TexArgCurrent, TexArgDiffuseColor);
   1.517 +			}
   1.518 +
   1.519 +			if(ActiveTex >= gc->GetTextureStageNumber() || !MapsCount) {
   1.520 +				if(pass++ > 1) {
   1.521 +					gc->SetAlphaBlending(true);
   1.522 +					if(PassFirstTexture == DetailMap || PassFirstTexture == EnvironmentMap) {
   1.523 +						gc->SetBlendFunc(BLEND_ONE, BLEND_ONE);
   1.524 +					} else {
   1.525 +                        gc->SetBlendFunc(BLEND_DESTCOLOR, BLEND_ZERO);
   1.526 +					}
   1.527 +                    gc->Draw(vb, ib);
   1.528 +					gc->SetAlphaBlending(false);
   1.529 +				} else {
   1.530 +					gc->Draw(vb, ib);
   1.531 +				}
   1.532 +				ActiveTex = 0;
   1.533 +				for(int i=0; i<gc->GetTextureStageNumber(); i++) {
   1.534 +					gc->SetTextureMatrix(Matrix4x4(), i);
   1.535 +				}
   1.536 +			}
   1.537 +		}
   1.538 +	}
   1.539 +
   1.540 +	if(material.SpecularEnable) gc->SetSpecular(false);
   1.541 +}
   1.542 +*/
   1.543 +
   1.544 +
   1.545 +
   1.546 +void Object::RenderBare() {
   1.547 +	VertexBuffer *vb = const_cast<VertexBuffer*>(mesh->GetVertexBuffer());
   1.548 +	IndexBuffer *ib = const_cast<IndexBuffer*>(mesh->GetIndexBuffer());
   1.549 +	gc->Draw(vb, ib);
   1.550 +}
   1.551 +
   1.552 +
   1.553 +// generate geometry
   1.554 +void Object::CreatePlane(float size, dword subdivisions) {
   1.555 +	ObjGen::CreatePlane(gc, size, subdivisions, &mesh, mesh->GetLevelCount());
   1.556 +}
   1.557 +
   1.558 +void Object::CreateCube(float size) {
   1.559 +	ObjGen::CreateCube(gc, size, &mesh, mesh->GetLevelCount());
   1.560 +}