 |
Ver Mensagens sem resposta | Ver Tópicos Activos
| [ +/- ]
[ Data/Hora: 24 Mai 2013, 02:02 ]
|
|
| Autor |
Mensagem |
|
Vitali
|
Assunto da Mensagem: Skybox Enviado: 10 Ago 2010, 22:20 |
|
| Colaborador(a) |
 |
Registado: 02 Set 2004, 20:01 Mensagens: 1801 Localização: São Carlos, SP
|
Estou com um certo problema na minha Skybox: Download -> http://www.mediafire.com/?twuwxzqhpr42fudNão consigo achar o problema na skybox:  Classe Skybox: Code: #ifndef SKYBOX_H_ #define SKYBOX_H_
#pragma once #include <d3dx9.h> #include <vector> #include <string>
class SkyBox { public: SkyBox(); ~SkyBox();
ID3DXMesh* SkyboxMesh; IDirect3DTexture9* SkyboxTextures[6];
void CreateSkyBox( IDirect3DDevice9* D3DDevice ); void RenderSkybox( IDirect3DDevice9* D3DDevice, D3DXVECTOR3 EyePosition ); };
#endif //SKYBOX_H_ Code: ////////////////////////////////////////////////////////////////////////////////////////////////// // File: SkyBox.cpp // Author: Chris Smith // Date Created: 2/22/06 // Description: Holds all of the SkyBox data // Copyright: Use this however you want, but I am not responsible for anything //////////////////////////////////////////////////////////////////////////////////////////////////
#include "SkyBox.h"
/////////////////////////////////////////////////////// // SkyBox FVF /////////////////////////////////////////////////////// struct SkyboxVertex { SkyboxVertex(){} SkyboxVertex(float x, float y, float z, float u, float v) { _x = x; _y = y; _z = z; _u = u; _v = v; }
float _x, _y, _z, _u, _v;
static const DWORD FVF; }; const DWORD SkyboxVertex::FVF = D3DFVF_XYZ | D3DFVF_TEX1;
/////////////////////////////////////////////////////// // SkyBox Constructor /////////////////////////////////////////////////////// SkyBox::SkyBox() { SkyboxMesh = 0; for(int i = 0; i < 6; i++) SkyboxTextures[i] = 0; }
/////////////////////////////////////////////////////// // SkyBox Deconstructor /////////////////////////////////////////////////////// SkyBox::~SkyBox() { SkyboxMesh->Release(); SkyboxMesh = NULL; for(int i = 0; i < 6; i++) SkyboxTextures[i]->Release(); };
/////////////////////////////////////////////////////// // Create the SkyBox /////////////////////////////////////////////////////// void SkyBox::CreateSkyBox( IDirect3DDevice9* D3DDevice ) { //Create the skybox SkyboxMesh D3DXCreateMeshFVF( 12, 24, D3DXMESH_MANAGED, SkyboxVertex::FVF, D3DDevice, &SkyboxMesh);
// Fill the verticies SkyboxVertex* v = 0; SkyboxMesh->LockVertexBuffer(0, (void**)&v);
v[0] = SkyboxVertex( 1.0f, -1.0f, 1.0f, 0.0f, 1.0f); v[1] = SkyboxVertex( 1.0f, 1.0f, 1.0f, 0.0f, 0.0f); v[2] = SkyboxVertex( 1.0f, 1.0f, -1.0f, 1.0f, 0.0f); v[3] = SkyboxVertex( 1.0f, -1.0f, -1.0f, 1.0f, 1.0f);
v[4] = SkyboxVertex(-1.0f, -1.0f, -1.0f, 0.0f, 1.0f); v[5] = SkyboxVertex(-1.0f, 1.0f, -1.0f, 0.0f, 0.0f); v[6] = SkyboxVertex(-1.0f, 1.0f, 1.0f, 1.0f, 0.0f); v[7] = SkyboxVertex(-1.0f, -1.0f, 1.0f, 1.0f, 1.0f);
v[8] = SkyboxVertex(-1.0f, 1.0f, 1.0f, 0.0f, 1.0f); v[9] = SkyboxVertex(-1.0f, 1.0f, -1.0f, 0.0f, 0.0f); v[10] = SkyboxVertex( 1.0f, 1.0f, -1.0f, 1.0f, 0.0f); v[11] = SkyboxVertex( 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
v[12] = SkyboxVertex(-1.0f, -1.0f, -1.0f, 0.0f, 1.0f); v[13] = SkyboxVertex(-1.0f, -1.0f, 1.0f, 0.0f, 0.0f); v[14] = SkyboxVertex( 1.0f, -1.0f, 1.0f, 1.0f, 0.0f); v[15] = SkyboxVertex( 1.0f, -1.0f, -1.0f, 1.0f, 1.0f);
v[16] = SkyboxVertex(-1.0f, -1.0f, 1.0f, 0.0f, 1.0f); v[17] = SkyboxVertex(-1.0f, 1.0f, 1.0f, 0.0f, 0.0f); v[18] = SkyboxVertex( 1.0f, 1.0f, 1.0f, 1.0f, 0.0f); v[19] = SkyboxVertex( 1.0f, -1.0f, 1.0f, 1.0f, 1.0f);
v[20] = SkyboxVertex( 1.0f, -1.0f, -1.0f, 0.0f, 1.0f); v[21] = SkyboxVertex( 1.0f, 1.0f, -1.0f, 0.0f, 0.0f); v[22] = SkyboxVertex(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f); v[23] = SkyboxVertex(-1.0f, -1.0f, -1.0f, 1.0f, 1.0f);
SkyboxMesh->UnlockVertexBuffer();
// Create the index buffer WORD* i = 0; SkyboxMesh->LockIndexBuffer(0, (void**)&i);
i[0] = 0; i[1] = 1; i[2] = 2; i[3] = 0; i[4] = 2; i[5] = 3;
i[6] = 4; i[7] = 5; i[8] = 6; i[9] = 4; i[10] = 6; i[11] = 7;
i[12] = 8; i[13] = 9; i[14] = 10; i[15] = 8; i[16] = 10; i[17] = 11;
i[18] = 12; i[19] = 13; i[20] = 14; i[21] = 12; i[22] = 14; i[23] = 15;
i[24] = 16; i[25] = 17; i[26] = 18; i[27] = 16; i[28] = 18; i[29] = 19;
i[30] = 20; i[31] = 21; i[32] = 22; i[33] = 20; i[34] = 22; i[35] = 23;
SkyboxMesh->UnlockIndexBuffer();
//Put each face into a different subset DWORD* attributeBuffer = 0; SkyboxMesh->LockAttributeBuffer(0, &attributeBuffer);
for(int a = 0; a < 2; a++) attributeBuffer[a] = 0;
for(int b = 2; b < 4; b++) attributeBuffer[b] = 1;
for(int c = 4; c < 6; c++) attributeBuffer[c] = 2;
for(int d = 6; d < 8; d++) attributeBuffer[d] = 3;
for(int e = 8; e < 10; e++) attributeBuffer[e] = 4;
for(int f = 10; f < 12; f++) attributeBuffer[f] = 5;
SkyboxMesh->UnlockAttributeBuffer();
std::vector<DWORD> adjacencyBuffer(SkyboxMesh->GetNumFaces() * 3); SkyboxMesh->GenerateAdjacency(0.0f, &adjacencyBuffer[0]);
SkyboxMesh->OptimizeInplace( D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_COMPACT | D3DXMESHOPT_VERTEXCACHE, &adjacencyBuffer[0], 0, 0, 0);
//Load the skybox textures char* TextureFilenames[6] = { "SkyBox/rt.bmp", "SkyBox/lt.bmp", "SkyBox/up.bmp", "SkyBox/dn.bmp", "SkyBox/ft.bmp", "SkyBox/bk.bmp" }; for(int i = 0; i < 6; i++) D3DXCreateTextureFromFile( D3DDevice, TextureFilenames[i], &SkyboxTextures[i] ); }
/////////////////////////////////////////////////////// // Render the Skybox /////////////////////////////////////////////////////// void SkyBox::RenderSkybox( IDirect3DDevice9* D3DDevice, D3DXVECTOR3 EyePosition ) { D3DXMATRIX SkyboxWorld; D3DXMatrixIdentity( &SkyboxWorld ); SkyboxWorld._41 = EyePosition.x; SkyboxWorld._42 = EyePosition.y; SkyboxWorld._43 = EyePosition.z; D3DDevice->SetTransform(D3DTS_WORLD, &SkyboxWorld); D3DDevice->SetRenderState( D3DRS_ZENABLE, false ); D3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, false ); D3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); D3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
for(int i = 0; i < 6; i++) { D3DDevice->SetTexture( 0, SkyboxTextures[i] ); SkyboxMesh->DrawSubset(i); }
D3DDevice->SetRenderState( D3DRS_ZENABLE, true); D3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, true ); D3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); D3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); }
_________________ Meu blog http://mateusvitali.wordpress.com/
|
|
| Topo |
|
 |
|
bcsanches2
|
Assunto da Mensagem: Re: Skybox Enviado: 11 Ago 2010, 10:13 |
|
Registado: 23 Nov 2003, 18:58 Mensagens: 2812 Localização: Brasil
|
|
| Topo |
|
 |
|
Ferat
|
Assunto da Mensagem: Re: Skybox Enviado: 11 Ago 2010, 12:35 |
|
| Membro Avançado |
 |
Registado: 26 Jun 2008, 21:26 Mensagens: 673 Localização: Brasil
|
|
E aí vitali?
Cara, eu uso OpenGL, mas isso já aconteceu comigo. No caso, foi só aumentar o valor máximo de profundidade(não sei como se chama no D3D).
Então, eu criei um const float MAX_PROFUNDIDADE 500.0f(creio que seja um valor parecido no D3D), por exemplo, e quando quero modificar, modifico essa variável.
Parece que minha explicação foi quase a mesmo do amigo bcsanches2.
Boa sorte aí com seu skybox!!
_________________ "Uma pequena pedra...Pode provocar uma avalanche..."
Para quem quiser baixar meu jogo: http://www.megaupload.com/?d=EHPAYBVQ
Se quiser discutir e votar sobre o jogo: http://www.unidev.com.br/phpbb3/viewtopic.php?f=5&t=53423
|
|
| Topo |
|
 |
|
bcsanches2
|
Assunto da Mensagem: Re: Skybox Enviado: 11 Ago 2010, 12:49 |
|
Registado: 23 Nov 2003, 18:58 Mensagens: 2812 Localização: Brasil
|
|
| Topo |
|
 |
|
Vitali
|
Assunto da Mensagem: Re: Skybox Enviado: 11 Ago 2010, 19:29 |
|
| Colaborador(a) |
 |
Registado: 02 Set 2004, 20:01 Mensagens: 1801 Localização: São Carlos, SP
|
|
Não é, já havia testado o farClip.
O resto do cenário se você testou está normal...só acontece isso com a skybox
[]'s
_________________ Meu blog http://mateusvitali.wordpress.com/
|
|
| Topo |
|
 |
|
bcsanches2
|
Assunto da Mensagem: Re: Skybox Enviado: 11 Ago 2010, 20:08 |
|
Registado: 23 Nov 2003, 18:58 Mensagens: 2812 Localização: Brasil
|
|
| Topo |
|
 |
|
Vitali
|
Assunto da Mensagem: Re: Skybox Enviado: 12 Ago 2010, 10:45 |
|
| Colaborador(a) |
 |
Registado: 02 Set 2004, 20:01 Mensagens: 1801 Localização: São Carlos, SP
|
É realmente estava com problemas nas coordenadas da minha skybox, no caso se seu diminuísse o nearplane o problema era resolvido, mas não queria fazer isso, intão alterei os valores da coordenada: Code: v[0] = SkyboxVertex( 2.0f, -2.0f, 2.0f, 0.0f, 1.0f); v[1] = SkyboxVertex( 2.0f, 2.0f, 2.0f, 0.0f, 0.0f); v[2] = SkyboxVertex( 2.0f, 2.0f, -2.0f, 1.0f, 0.0f); v[3] = SkyboxVertex( 2.0f, -2.0f, -2.0f, 1.0f, 1.0f); []'s
_________________ Meu blog http://mateusvitali.wordpress.com/
|
|
| Topo |
|
 |
Quem está ligado: |
Utilizador a ver este Fórum: Nenhum utilizador registado e 1 visitante |
|
Criar Tópicos: Proibído Responder Tópicos: Proibído Editar Mensagens: Proibído Apagar Mensagens: Proibído
|
|
 |
|

|
 |