📄 plant.cpp
字号:
//--------------------------------------------------
// Desc: Plant
// Author: artsylee/2007.2.25
//--------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include "Plant.h"
#include "Heightmap.h"
#include "Common.h"
#include "ase/ASEngine.h"
extern CHeightmap g_Hmap;
CPlant::CPlant()
{
}
CPlant::~CPlant()
{
}
bool CPlant::LoadPlant(char *pFile)
{
FILE *fp = fopen(pFile, "rb");
if(fp == NULL)
return false;
// BITMAPFILEHEADER fileheader;
// fread(&fileheader, sizeof(BITMAPFILEHEADER), 1, fp);
// if(fileheader.bfType != 19778)
// return false;
fseek(fp, 1078, SEEK_SET);
for(int z=PLANT_MAP_SIZE-1; z>=0; z--)
{
for(int x=0; x<PLANT_MAP_SIZE; x++)
{
fread(&m_PlantData[z][x], sizeof(unsigned char), 1, fp);
}
}
fclose(fp);
// plant position
for(int z=0; z<PLANT_MAP_SIZE; z++)
{
for(int x=0; x<PLANT_MAP_SIZE; x++)
{
m_PlantOffset[z][x].xbias = 5+(rand()%30); // max 40
m_PlantOffset[z][x].zbias = 5+(rand()%30);
}
}
return true;
}
void CPlant::Render()
{
int tx, tz; // in terrain map
int cx, cz; // in cover map
int type;
D3DXVECTOR3 pos;
// g_pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
if(g_Hmap.m_bViewerChange)
{
m_VertexIndex = 0;
for(int x=108; x<148; x++)
{
for(int z= 108; z<148; z++)
{
if(g_Hmap.m_Frustum.IsInFrustum(x, z))
{
tx = g_Hmap.m_pMovemap[z*256+x].xpos;
tz = g_Hmap.m_pMovemap[z*256+x].zpos;
pos = g_Hmap.ConvertToWorld(x, z);
cx = tx/4;
cz = tz/4;
type = m_PlantData[cz][cx];
if(type!=0)
{
// type = 192;
pos.x += m_PlantOffset[cz][cx].xbias;
pos.z += m_PlantOffset[cz][cx].zbias;
/*
if(type>130)
pos.ypos=m_cHmap.GetHeight(pos.xpos,pos.zpos)-2;
else
pos.ypos=m_cHmap.GetHeight(pos.xpos,pos.zpos)-1;
if(type==64)
m_cBush1.RenderBush(pos);
if(type==128)
m_cPine.RenderPine(pos);
if(type==192)
m_cTree1.Render3DTree(pos);
if(type==255)
m_cTree2.Render3DTree(pos);
*/
// pos.y=g_Hmap.GetHeight(pos.x, pos.z)-2;
// m_Tree.RenderTree(pos, m_Vertex, &m_VertexIndex);
}
}
}
}
}
SET_TEXTURE_TYPE(0, 1003);
g_pD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, m_VertexIndex/3, m_Vertex, sizeof(HeightmapVertex));
// m_Tree.RenderTree(D3DXVECTOR3(1240, 88, 4427));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -