Mercurial > mm7
comparison mm7_3.cpp @ 173:a8c700f3f5ec
Слияние
author | Ritor1 |
---|---|
date | Fri, 15 Feb 2013 10:06:47 +0600 |
parents | e6db0995ac4b 91fa025e6ca6 |
children | 4ae88cd19c30 |
comparison
equal
deleted
inserted
replaced
172:e6db0995ac4b | 173:a8c700f3f5ec |
---|---|
6987 { | 6987 { |
6988 v30 = 1.0 / (array_73D150[v28].vWorldViewPosition.x + 0.0000001); | 6988 v30 = 1.0 / (array_73D150[v28].vWorldViewPosition.x + 0.0000001); |
6989 memcpy(&array_50AC10[v28], &array_73D150[v28], sizeof(array_50AC10[v28])); | 6989 memcpy(&array_50AC10[v28], &array_73D150[v28], sizeof(array_50AC10[v28])); |
6990 ++v28; | 6990 ++v28; |
6991 --v29; | 6991 --v29; |
6992 array_50A2B0[v28 + 49].flt_20 = v30; | 6992 array_50A2B0[v28 + 49]._rhw = v30; |
6993 } | 6993 } |
6994 while ( v29 ); | 6994 while ( v29 ); |
6995 pFace = v46; | 6995 pFace = v46; |
6996 } | 6996 } |
6997 | 6997 |
7354 do | 7354 do |
7355 { | 7355 { |
7356 v32 = 1.0 / (*(float *)(v31 * 48 + 7590236) + 0.0000001); | 7356 v32 = 1.0 / (*(float *)(v31 * 48 + 7590236) + 0.0000001); |
7357 memcpy(&array_50AC10[v31], &array_73D150[v31], sizeof(array_50AC10[v31])); | 7357 memcpy(&array_50AC10[v31], &array_73D150[v31], sizeof(array_50AC10[v31])); |
7358 ++v31; | 7358 ++v31; |
7359 array_50A2B0[v31 + 49].flt_20 = v32; | 7359 array_50A2B0[v31 + 49]._rhw = v32; |
7360 v84 = v12->sTextureDeltaU + *(short *)(v30 - 40); | 7360 v84 = v12->sTextureDeltaU + *(short *)(v30 - 40); |
7361 array_50A2B0[v31 + 49].u = (double)v84 * v28; | 7361 array_50A2B0[v31 + 49].u = (double)v84 * v28; |
7362 v33 = v12->sTextureDeltaV + *(short *)v30; | 7362 v33 = v12->sTextureDeltaV + *(short *)v30; |
7363 v30 += 2; | 7363 v30 += 2; |
7364 v34 = v83-- == 1; | 7364 v34 = v83-- == 1; |
7717 goto LABEL_24; | 7717 goto LABEL_24; |
7718 } | 7718 } |
7719 return result; | 7719 return result; |
7720 } | 7720 } |
7721 | 7721 |
7722 | |
7723 | |
7724 unsigned short *LoadTgaTexture(const wchar_t *filename, int *out_width = nullptr, int *out_height = nullptr) | |
7725 { | |
7726 #pragma pack(push, 1) | |
7727 struct TGAHeader | |
7728 { | |
7729 unsigned char tgaSkip; | |
7730 unsigned char colourmaptype; // type of colour map 0=none, 1=has palette | |
7731 unsigned char tgaType; // type of image 0=none,1=indexed,2=rgb,3=grey,+8=rle packed | |
7732 | |
7733 short colourmapstart; // first colour map entry in palette | |
7734 short colourmaplength; // number of colours in palette | |
7735 char colourmapbits; // number of bits per palette entry 15,16,24,32 | |
7736 | |
7737 //unsigned char tgaDontCare2[9]; | |
7738 short xstart; // image x origin | |
7739 short ystart; // image y origin | |
7740 | |
7741 unsigned short tgaWidth; | |
7742 unsigned short tgaHeight; | |
7743 unsigned char tgaBPP; | |
7744 | |
7745 char descriptor; // image descriptor bits: 00vhaaaa | |
7746 // h horizontal flip | |
7747 // v vertical flip | |
7748 // a alpha bits | |
7749 }; | |
7750 #pragma pack(pop) | |
7751 | |
7752 if (out_width) | |
7753 *out_width = 0; | |
7754 if (out_height) | |
7755 *out_height = 0; | |
7756 | |
7757 DWORD w; | |
7758 auto file = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr); | |
7759 if (file == INVALID_HANDLE_VALUE) | |
7760 return nullptr; | |
7761 | |
7762 TGAHeader header; | |
7763 ReadFile(file, &header, sizeof(header), &w, nullptr); | |
7764 SetFilePointer(file, header.tgaSkip, nullptr, FILE_CURRENT); | |
7765 | |
7766 if (header.tgaBPP != 24 || header.tgaType != 2) | |
7767 { | |
7768 CloseHandle(file); | |
7769 return nullptr; | |
7770 } | |
7771 | |
7772 int imgSize = header.tgaWidth * header.tgaHeight * 3; | |
7773 auto pixels = new unsigned char[imgSize]; | |
7774 ReadFile(file, pixels, imgSize, &w, nullptr); | |
7775 CloseHandle(file); | |
7776 | |
7777 if (w != imgSize) | |
7778 { | |
7779 delete [] pixels; | |
7780 return nullptr; | |
7781 } | |
7782 | |
7783 if (out_width) | |
7784 *out_width = header.tgaWidth; | |
7785 if (out_height) | |
7786 *out_height = header.tgaHeight; | |
7787 | |
7788 auto pixels_16bit = new unsigned short[imgSize / 3]; | |
7789 for (int i = 0; i < imgSize / 3; ++i) | |
7790 { | |
7791 pixels_16bit[i] = (pixels[i * 3] / 8 & 0x1F) | | |
7792 ((pixels[i * 3 + 1] / 4 & 0x3F) << 5) | | |
7793 ((pixels[i * 3 + 2] / 8 & 0x1F) << 11); | |
7794 } | |
7795 delete [] pixels; | |
7796 return pixels_16bit; | |
7797 } | |
7798 | |
7799 unsigned short *skybox_xn, *skybox_xp, | |
7800 *skybox_yn, *skybox_yp, | |
7801 *skybox_zn, *skybox_zp; | |
7802 int skybox_width, skybox_height; | |
7803 IDirect3DTexture2 *skybox_texture; | |
7804 IDirectDrawSurface4 *skybox_surface; | |
7805 bool Skybox_Initialize(const wchar_t *skybox_name) | |
7806 { | |
7807 wchar_t xn_filename[1024], xp_filename[1024], | |
7808 yn_filename[1024], yp_filename[1024], | |
7809 zn_filename[1024], zp_filename[1024]; | |
7810 swprintf(xn_filename, L"%s_xn.tga", skybox_name); swprintf(xp_filename, L"%s_xp.tga", skybox_name); | |
7811 swprintf(yn_filename, L"%s_yn.tga", skybox_name); swprintf(yp_filename, L"%s_yp.tga", skybox_name); | |
7812 swprintf(zn_filename, L"%s_zn.tga", skybox_name); swprintf(zp_filename, L"%s_zp.tga", skybox_name); | |
7813 | |
7814 int xn_width, xn_height; | |
7815 skybox_xn = LoadTgaTexture(xn_filename, &xn_width, &xn_height); | |
7816 if (!skybox_xn) | |
7817 return false; | |
7818 | |
7819 int xp_width, xp_height; | |
7820 skybox_xp = LoadTgaTexture(xp_filename, &xp_width, &xp_height); | |
7821 if (!skybox_xp || xp_width != xn_width || xp_height != xn_height) | |
7822 { | |
7823 delete [] skybox_xn; | |
7824 if (skybox_xp) delete [] skybox_xp; | |
7825 return false; | |
7826 } | |
7827 | |
7828 int yn_width, yn_height; | |
7829 skybox_yn = LoadTgaTexture(yn_filename, &yn_width, &yn_height); | |
7830 if (!skybox_yn || yn_width != xn_width || yn_height != xn_height) | |
7831 { | |
7832 delete [] skybox_xn; | |
7833 if (skybox_xp) delete [] skybox_xp; | |
7834 if (skybox_yn) delete [] skybox_yn; | |
7835 return false; | |
7836 } | |
7837 | |
7838 int yp_width, yp_height; | |
7839 skybox_yp = LoadTgaTexture(yp_filename, &yp_width, &yp_height); | |
7840 if (!skybox_yp || yp_width != xn_width || yp_height != xn_height) | |
7841 { | |
7842 delete [] skybox_xn; | |
7843 if (skybox_xp) delete [] skybox_xp; | |
7844 if (skybox_yn) delete [] skybox_yn; | |
7845 if (skybox_yp) delete [] skybox_yp; | |
7846 return false; | |
7847 } | |
7848 | |
7849 int zn_width, zn_height; | |
7850 skybox_zn = LoadTgaTexture(zn_filename, &zn_width, &zn_height); | |
7851 if (!skybox_zn || zn_width != xn_width || zn_height != xn_height) | |
7852 { | |
7853 delete [] skybox_xn; | |
7854 if (skybox_xp) delete [] skybox_xp; | |
7855 if (skybox_yn) delete [] skybox_yn; | |
7856 if (skybox_yp) delete [] skybox_yp; | |
7857 if (skybox_zn) delete [] skybox_zn; | |
7858 return false; | |
7859 } | |
7860 | |
7861 int zp_width, zp_height; | |
7862 skybox_zp = LoadTgaTexture(zp_filename, &zp_width, &zp_height); | |
7863 if (!skybox_zp || zp_width != xn_width || zp_height != xn_height) | |
7864 { | |
7865 delete [] skybox_xn; | |
7866 if (skybox_xp) delete [] skybox_xp; | |
7867 if (skybox_yn) delete [] skybox_yn; | |
7868 if (skybox_yp) delete [] skybox_yp; | |
7869 if (skybox_zn) delete [] skybox_zn; | |
7870 if (skybox_zp) delete [] skybox_zp; | |
7871 return false; | |
7872 } | |
7873 | |
7874 skybox_width = xn_width; | |
7875 skybox_height = xn_height; | |
7876 | |
7877 | |
7878 if (!pRenderer->pRenderD3D->CreateTexture(skybox_width, skybox_height, &skybox_surface, &skybox_texture, | |
7879 false, false, pRenderer->uMinDeviceTextureDim)) | |
7880 return false; | |
7881 | |
7882 return true; | |
7883 } | |
7884 | |
7885 | |
7886 struct vector | |
7887 { | |
7888 float x, y, z; | |
7889 }; | |
7890 struct matrix | |
7891 { | |
7892 float m[4][4]; | |
7893 }; | |
7894 void VectorNormalize(vector *v) | |
7895 { | |
7896 float invmag = 1.0f / sqrtf(v->x * v->x + v->y * v->y + v->z * v->z); | |
7897 v->x *= invmag; | |
7898 v->y *= invmag; | |
7899 v->z *= invmag; | |
7900 } | |
7901 void MatrixRotationAxis(matrix *pout, CONST vector *pv, float angle) | |
7902 { | |
7903 memset(pout, 0, sizeof(matrix)); | |
7904 pout->m[3][0] = 0; | |
7905 pout->m[3][1] = 0; | |
7906 pout->m[3][2] = 0; | |
7907 pout->m[3][3] = 1; | |
7908 | |
7909 vector v; | |
7910 v.x = pv->x; v.y = pv->y; v.z = pv->z; | |
7911 VectorNormalize(&v); | |
7912 | |
7913 pout->m[0][0] = (1.0f - cos(angle)) * v.x * v.x + cos(angle); | |
7914 pout->m[1][0] = (1.0f - cos(angle)) * v.x * v.y - sin(angle) * v.z; | |
7915 pout->m[2][0] = (1.0f - cos(angle)) * v.x * v.z + sin(angle) * v.y; | |
7916 pout->m[0][1] = (1.0f - cos(angle)) * v.y * v.x + sin(angle) * v.z; | |
7917 pout->m[1][1] = (1.0f - cos(angle)) * v.y * v.y + cos(angle); | |
7918 pout->m[2][1] = (1.0f - cos(angle)) * v.y * v.z - sin(angle) * v.x; | |
7919 pout->m[0][2] = (1.0f - cos(angle)) * v.z * v.x - sin(angle) * v.y; | |
7920 pout->m[1][2] = (1.0f - cos(angle)) * v.z * v.y + sin(angle) * v.x; | |
7921 pout->m[2][2] = (1.0f - cos(angle)) * v.z * v.z + cos(angle); | |
7922 } | |
7923 void VectorTransform(const matrix *m, const vector *v, vector *out) | |
7924 { | |
7925 out->x = m->m[0][0] * v->x + m->m[1][0] * v->y + m->m[2][0] * v->z + m->m[3][0]; | |
7926 out->y = m->m[0][1] * v->x + m->m[1][1] * v->y + m->m[2][1] * v->z + m->m[3][1]; | |
7927 out->z = m->m[0][2] * v->x + m->m[1][2] * v->y + m->m[2][2] * v->z + m->m[3][2]; | |
7928 } | |
7929 | |
7930 | |
7931 bool DrawSkyD3D_Skybox() | |
7932 { | |
7933 static bool initialized = false, | |
7934 initialization_failed = false; | |
7935 if (initialization_failed) | |
7936 return false; | |
7937 | |
7938 static int last_camera_rot_y, | |
7939 last_camera_rot_x; | |
7940 if (!initialized) | |
7941 { | |
7942 if (!Skybox_Initialize(L"data/skybox/stars")) | |
7943 { | |
7944 initialization_failed = true; | |
7945 return false; | |
7946 } | |
7947 initialized = true; | |
7948 | |
7949 last_camera_rot_y = pParty->sRotationY + 1; // force update for the first run | |
7950 last_camera_rot_x = pParty->sRotationX + 1; | |
7951 } | |
7952 | |
7953 /* | |
7954 r(y) = | |
7955 cos y 0 sin y 0 | |
7956 0 1 0 0 | |
7957 -sin y 0 cos y 0 | |
7958 0 0 0 1 | |
7959 | |
7960 x cos y - z sin y | |
7961 y | |
7962 x sin y + z cos y | |
7963 1 | |
7964 | |
7965 | |
7966 | |
7967 r(x) = // should be r(right) actually | |
7968 1 0 0 0 | |
7969 0 cos x -sin x 0 | |
7970 0 sin x cos x 0 | |
7971 0 0 0 1 | |
7972 | |
7973 | |
7974 x | |
7975 y cos x + z sin x | |
7976 -y sin x + z cos x | |
7977 1 | |
7978 | |
7979 */ | |
7980 | |
7981 if (last_camera_rot_y == pParty->sRotationY && | |
7982 last_camera_rot_x == pParty->sRotationX) | |
7983 { | |
7984 draw: | |
7985 struct RenderVertexD3D3 v[6]; | |
7986 | |
7987 v[0].pos.x = pViewport->uScreenX; | |
7988 v[0].pos.y = pViewport->uScreenY; | |
7989 v[0].pos.z = 0.99989998; | |
7990 v[0].rhw = 1; | |
7991 v[0].diffuse = 0xFFFFFFFF; | |
7992 v[0].specular = 0; | |
7993 v[0].texcoord.x = 0; | |
7994 v[0].texcoord.y = 0; | |
7995 | |
7996 v[1].pos.x = pViewport->uScreenX + pViewport->uScreenWidth; | |
7997 v[1].pos.y = pViewport->uScreenY + pViewport->uScreenHeight; | |
7998 v[1].pos.z = 0.99989998; | |
7999 v[1].rhw = 1; | |
8000 v[1].diffuse = 0xFFFFFFFF; | |
8001 v[1].specular = 0; | |
8002 v[1].texcoord.x = (float)pViewport->uScreenWidth / skybox_width; | |
8003 v[1].texcoord.y = (float)pViewport->uScreenHeight / skybox_height; | |
8004 | |
8005 v[2].pos.x = pViewport->uScreenX + pViewport->uScreenWidth; | |
8006 v[2].pos.y = pViewport->uScreenY; | |
8007 v[2].pos.z = 0.99989998; | |
8008 v[2].rhw = 1; | |
8009 v[2].diffuse = 0xFFFFFFFF; | |
8010 v[2].specular = 0; | |
8011 v[2].texcoord.x = (float)pViewport->uScreenWidth / skybox_width; | |
8012 v[2].texcoord.y = 0; | |
8013 | |
8014 memcpy(&v[3], &v[0], sizeof(*v)); | |
8015 | |
8016 v[4].pos.x = pViewport->uScreenX; | |
8017 v[4].pos.y = pViewport->uScreenY + pViewport->uScreenHeight; | |
8018 v[4].pos.z = 0.99989998; | |
8019 v[4].rhw = 1; | |
8020 v[4].diffuse = 0xFFFFFFFF; | |
8021 v[4].specular = 0; | |
8022 v[4].texcoord.x = 0; | |
8023 v[4].texcoord.y = (float)pViewport->uScreenHeight / skybox_height; | |
8024 | |
8025 memcpy(&v[5], &v[1], sizeof(*v)); | |
8026 | |
8027 pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE); | |
8028 pRenderer->pRenderD3D->pDevice->SetTexture(0, skybox_texture); | |
8029 pRenderer->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, v, 6, D3DDP_DONOTUPDATEEXTENTS | D3DDP_DONOTLIGHT); | |
8030 //pRenderer->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, v + 1, 3, D3DDP_DONOTUPDATEEXTENTS | D3DDP_DONOTLIGHT); | |
8031 | |
8032 return true; | |
8033 } | |
8034 | |
8035 | |
8036 DDSURFACEDESC2 desc; | |
8037 desc.dwSize = sizeof(desc); | |
8038 if (!pRenderer->LockSurface_DDraw4(skybox_surface, &desc, DDLOCK_WAIT | DDLOCK_WRITEONLY)) | |
8039 return false; | |
8040 | |
8041 last_camera_rot_y = pParty->sRotationY; | |
8042 last_camera_rot_x = pParty->sRotationX; | |
8043 | |
8044 float aspect = (float)pViewport->uScreenWidth / (float)pViewport->uScreenHeight; | |
8045 float fov_x = 3.141592f * (pOutdoorCamera->uCameraFovInDegrees + 0) / 360.0f; | |
8046 float fov_y = fov_x / aspect; | |
8047 | |
8048 float ray_dx = fov_x / (float)pViewport->uScreenWidth, | |
8049 ray_dy = fov_y / (float)pViewport->uScreenHeight; | |
8050 float party_angle_x = 2 * 3.141592653589 * pParty->sRotationX / 2048.0, | |
8051 party_angle_y = 2 * 3.141592653589 * pParty->sRotationY / 2048.0; | |
8052 for (int y = 0; y < pViewport->uScreenHeight; ++y) | |
8053 for (int x = 0; x < pViewport->uScreenWidth; ++x) | |
8054 { | |
8055 float angle_x = party_angle_x - (y - pViewport->uScreenHeight / 2) * ray_dy; | |
8056 float angle_y = party_angle_y - (x - pViewport->uScreenWidth / 2) * ray_dx; | |
8057 | |
8058 float _dir_x_ = 1, | |
8059 _dir_y_ = 0, | |
8060 _dir_z_ = 0; | |
8061 | |
8062 float dir_x_ = _dir_x_ * cosf(angle_y);// - _dir_z_ * sinf(angle_y); // rotation around y | |
8063 //float dir_y_ = _dir_y_; | |
8064 float dir_z_ = _dir_x_ * sinf(angle_y);// + _dir_z_ * cosf(angle_y); | |
8065 | |
8066 //float dir_x = dir_x_; // rotation around x | |
8067 //float dir_y = /*dir_y_ * cosf(angle_x)*/ + dir_z_ * sinf(angle_x); | |
8068 //float dir_z = /*-dir_y_ * sinf(angle_x)*/ + dir_z_ * cosf(angle_x); | |
8069 | |
8070 vector right; // rotate around right actually to avoid space distortion | |
8071 right.x = /*dir_y * 0*/ - dir_z_ * 1; | |
8072 right.y = /*dir_z_ * 0 - dir_x_ * */0; | |
8073 right.z = dir_x_ * 1/* - dir_y_ * 0*/; | |
8074 //VectorNormalize(&right); | |
8075 | |
8076 matrix rightMatrix; | |
8077 MatrixRotationAxis(&rightMatrix, &right, angle_x); | |
8078 | |
8079 vector v1, v2; | |
8080 v1.x = dir_x_; v1.y = 0; v1.z = dir_z_; | |
8081 VectorTransform(&rightMatrix, &v1, &v2); | |
8082 | |
8083 float dir_x = v2.x, | |
8084 dir_y = v2.y, | |
8085 dir_z = v2.z; | |
8086 | |
8087 float abs_dir_x = fabsf(dir_x), | |
8088 abs_dir_y = fabsf(dir_y), | |
8089 abs_dir_z = fabsf(dir_z); | |
8090 | |
8091 unsigned short color = (0x1F << 11) | (0x1F << 5) | (5); //default to orange | |
8092 if (abs_dir_x >= abs_dir_y) | |
8093 { | |
8094 if (abs_dir_x >= abs_dir_z) | |
8095 { | |
8096 if (dir_x >= 0) | |
8097 { | |
8098 float instersect_y = dir_y / (2.0f * dir_x); // plane equation for this side is x + 0.5 = 0 | |
8099 float instersect_z = dir_z / (2.0f * dir_x); | |
8100 | |
8101 float u = 1.0f - (instersect_z + 0.5f), | |
8102 v = 1.0f - (instersect_y + 0.5f); | |
8103 | |
8104 int tx = u * (skybox_width - 1), | |
8105 ty = v * (skybox_height - 1); | |
8106 | |
8107 color = skybox_xp[ty * skybox_width + tx]; | |
8108 //color = ty * 0x1F / skybox_height; | |
8109 } | |
8110 else | |
8111 { | |
8112 float instersect_y = dir_y / (2.0f * dir_x); | |
8113 float instersect_z = dir_z / (2.0f * dir_x); | |
8114 | |
8115 float u = 1.0f - (instersect_z + 0.5f), | |
8116 v = instersect_y + 0.5f; | |
8117 | |
8118 int tx = u * (skybox_width - 1), | |
8119 ty = v * (skybox_height - 1); | |
8120 | |
8121 color = skybox_xn[ty * skybox_width + tx]; | |
8122 //color = tx * 0x1F / skybox_height; | |
8123 } | |
8124 } | |
8125 else if (dir_z >= 0) | |
8126 goto DIR_ZP; | |
8127 else | |
8128 goto DIR_ZN; | |
8129 } | |
8130 else if (abs_dir_y >= abs_dir_z) | |
8131 { | |
8132 if (dir_y >= 0) | |
8133 { | |
8134 float instersect_x = dir_x / (2.0f * dir_y); | |
8135 float instersect_z = dir_z / (2.0f * dir_y); | |
8136 | |
8137 float u = instersect_x + 0.5f, | |
8138 v = instersect_z + 0.5f; | |
8139 | |
8140 int tx = u * (skybox_width - 1), | |
8141 ty = v * (skybox_height - 1); | |
8142 | |
8143 color = skybox_yp[ty * skybox_width + tx]; | |
8144 //color = tx * 0x1F / skybox_height; | |
8145 } | |
8146 /*else should never be seen i guess | |
8147 { | |
8148 __debugbreak(); | |
8149 // -y | |
8150 //Log::Warning(L"(%03u, %03u): -y", x, y); | |
8151 }*/ | |
8152 } | |
8153 else if (dir_z >= 0) | |
8154 { | |
8155 DIR_ZP: | |
8156 // +z | |
8157 float instersect_x = dir_x / (2.0f * dir_z); | |
8158 float instersect_y = dir_y / (2.0f * dir_z); | |
8159 //float intersect_z = 0.5f; | |
8160 | |
8161 float u = instersect_x + 0.5f, | |
8162 v = -instersect_y + 0.5f; | |
8163 | |
8164 int tx = u * (skybox_width - 1), | |
8165 ty = v * (skybox_height - 1); | |
8166 | |
8167 color = skybox_zp[ty * skybox_width + tx]; | |
8168 } | |
8169 else | |
8170 { | |
8171 DIR_ZN: | |
8172 // -z | |
8173 float instersect_x = -dir_x / (2.0f * dir_z); | |
8174 float instersect_y = -dir_y / (2.0f * dir_z); | |
8175 //float intersect_z = -0.5f; | |
8176 | |
8177 float u = 1.0f - instersect_x - 0.5f, | |
8178 v = -instersect_y + 0.5f; | |
8179 | |
8180 int tx = u * (skybox_width - 1), | |
8181 ty = v * (skybox_height - 1); | |
8182 | |
8183 color = skybox_zn[ty * skybox_width + tx]; | |
8184 } | |
8185 | |
8186 //pRenderer->pTargetSurface[(pViewport->uScreenY + y) * pRenderer->uTargetSurfacePitch + pViewport->uScreenX + x] = color; | |
8187 ((unsigned __int16 *)((char *)desc.lpSurface + y * desc.lPitch))[x] = color; | |
8188 } | |
8189 | |
8190 ErrD3D((skybox_surface)->Unlock(0)); | |
8191 goto draw; | |
8192 } | |
8193 | |
7722 //----- (00479543) -------------------------------------------------------- | 8194 //----- (00479543) -------------------------------------------------------- |
7723 void Render::DrawSkyD3D() | 8195 void Render::DrawSkyD3D() |
7724 { | 8196 { |
7725 int v0; // esi@2 | 8197 int v0; // esi@2 |
7726 int v1; // eax@2 | 8198 int v1; // eax@2 |
7761 int v36; // [sp+14Ch] [bp-18h]@2 | 8233 int v36; // [sp+14Ch] [bp-18h]@2 |
7762 int v37; // [sp+154h] [bp-10h]@8 | 8234 int v37; // [sp+154h] [bp-10h]@8 |
7763 int v38; // [sp+158h] [bp-Ch]@1 | 8235 int v38; // [sp+158h] [bp-Ch]@1 |
7764 int v39; // [sp+15Ch] [bp-8h]@4 | 8236 int v39; // [sp+15Ch] [bp-8h]@4 |
7765 int v40; // [sp+160h] [bp-4h]@7 | 8237 int v40; // [sp+160h] [bp-4h]@7 |
8238 | |
8239 extern bool new_sky; | |
8240 if (new_sky) | |
8241 { | |
8242 if (DrawSkyD3D_Skybox()) | |
8243 return; | |
8244 } | |
7766 | 8245 |
7767 v30 = ((double)(pOutdoorCamera->int_fov_rad * pIndoorCamera->pos.z) | 8246 v30 = ((double)(pOutdoorCamera->int_fov_rad * pIndoorCamera->pos.z) |
7768 / ((double)pOutdoorCamera->int_fov_rad + 8192.0) + pViewport->uScreenCenterY); | 8247 / ((double)pOutdoorCamera->int_fov_rad + 8192.0) + pViewport->uScreenCenterY); |
7769 v38 = pViewport->uScreenCenterY - | 8248 v38 = pViewport->uScreenCenterY - |
7770 pOutdoorCamera->int_fov_rad / (pOutdoorCamera->shading_dist_mist * cos(pIndoorCamera->sRotationX * 0.003066406352445483) + 0.0000001000000011686097) * | 8249 pOutdoorCamera->int_fov_rad / (pOutdoorCamera->shading_dist_mist * cos(pIndoorCamera->sRotationX * 0.003066406352445483) + 0.0000001000000011686097) * |
7771 (pOutdoorCamera->shading_dist_mist * -sin(pIndoorCamera->sRotationX * 0.003066406352445483) - pIndoorCamera->pos.z); | 8250 (pOutdoorCamera->shading_dist_mist * -sin(pIndoorCamera->sRotationX * 0.003066406352445483) - pIndoorCamera->pos.z); |
7772 _this._48607B(&stru_8019C8); | 8251 _this._48607B(&stru_8019C8); |
7773 _this.ptr_38->_48694B(); | 8252 _this.ptr_38->_48694B(); |
7774 _this.uTileBitmapID = pOutdoor->uSky_TextureID; | 8253 _this.uTileBitmapID = pOutdoor->uSky_TextureID; |
7775 _this.pTexture = (Texture *)(SLOWORD(pOutdoor->uSky_TextureID) != -1 ? (int)&pBitmaps_LOD->pTextures[SLOWORD(pOutdoor->uSky_TextureID)] : 0); | 8254 _this.pTexture = (Texture *)(SLOWORD(pOutdoor->uSky_TextureID) != -1 ? &pBitmaps_LOD->pTextures[SLOWORD(pOutdoor->uSky_TextureID)] : 0); |
7776 if (pOutdoor->uSky_TextureID == -1) | 8255 if (pOutdoor->uSky_TextureID == -1) |
7777 return; | 8256 return; |
8257 | |
7778 _this.field_58 = 0; | 8258 _this.field_58 = 0; |
7779 _this.uNumVertices = 4; | 8259 _this.uNumVertices = 4; |
7780 _this.v_18.x = -stru_5C6E00->SinCos(pIndoorCamera->sRotationX - stru_5C6E00->uIntegerHalfPi + 16); | 8260 _this.v_18.x = -stru_5C6E00->SinCos(pIndoorCamera->sRotationX - stru_5C6E00->uIntegerHalfPi + 16); |
7781 _this.v_18.y = 0; | 8261 _this.v_18.y = 0; |
7782 _this.v_18.z = -stru_5C6E00->SinCos(pIndoorCamera->sRotationX + 16); | 8262 _this.v_18.z = -stru_5C6E00->SinCos(pIndoorCamera->sRotationX + 16); |
7857 v36 += ((unsigned __int64)(_this.ptr_38->field_1C * v13) >> 16); | 8337 v36 += ((unsigned __int64)(_this.ptr_38->field_1C * v13) >> 16); |
7858 v35 = 224 * pMiscTimer->uTotalGameTimeElapsed + (signed int)((unsigned __int64)(v37 * v18) >> 16) / 8; | 8338 v35 = 224 * pMiscTimer->uTotalGameTimeElapsed + (signed int)((unsigned __int64)(v37 * v18) >> 16) / 8; |
7859 v36 = 224 * pMiscTimer->uTotalGameTimeElapsed + (signed int)((unsigned __int64)(v36 * v18) >> 16) / 8; | 8339 v36 = 224 * pMiscTimer->uTotalGameTimeElapsed + (signed int)((unsigned __int64)(v36 * v18) >> 16) / 8; |
7860 | 8340 |
7861 array_50AC10[i].vWorldViewPosition.x = pOutdoorCamera->shading_dist_mist; | 8341 array_50AC10[i].vWorldViewPosition.x = pOutdoorCamera->shading_dist_mist; |
7862 array_50AC10[i].flt_20 = 1.0 / (double)(v17 / 65536); | 8342 array_50AC10[i]._rhw = 1.0 / (double)(v17 / 65536); |
7863 array_50AC10[i].u = (double)v35 / (65536.0 * pBitmaps_LOD->pTextures[pOutdoor->uSky_TextureID].uTextureWidth); | 8343 array_50AC10[i].u = (double)v35 / (65536.0 * pBitmaps_LOD->pTextures[pOutdoor->uSky_TextureID].uTextureWidth); |
7864 array_50AC10[i].v = (double)v36 / (65536.0 * pBitmaps_LOD->pTextures[pOutdoor->uSky_TextureID].uTextureWidth); | 8344 array_50AC10[i].v = (double)v36 / (65536.0 * pBitmaps_LOD->pTextures[pOutdoor->uSky_TextureID].uTextureWidth); |
7865 } | 8345 } |
7866 | 8346 |
7867 float t = (GetTickCount() % 96000) / 96000.0f; | 8347 float t = (GetTickCount() % 96000) / 96000.0f; |
7868 | 8348 |
7869 array_50AC10[0].vWorldViewPosition.x = pOutdoorCamera->shading_dist_mist; | 8349 array_50AC10[0].vWorldViewPosition.x = pOutdoorCamera->shading_dist_mist; |
7870 array_50AC10[0].flt_20 = 1; | 8350 array_50AC10[0]._rhw = 1; |
7871 array_50AC10[0].u = 0; | 8351 array_50AC10[0].u = 0; |
7872 array_50AC10[0].v = 0 + t; | 8352 array_50AC10[0].v = 0 + t; |
7873 | 8353 |
7874 array_50AC10[1].vWorldViewPosition.x = pOutdoorCamera->shading_dist_mist; | 8354 array_50AC10[1].vWorldViewPosition.x = pOutdoorCamera->shading_dist_mist; |
7875 array_50AC10[1].flt_20 = 1; | 8355 array_50AC10[1]._rhw = 1; |
7876 array_50AC10[1].u = 0; | 8356 array_50AC10[1].u = 0; |
7877 array_50AC10[1].v = 1 + t; | 8357 array_50AC10[1].v = 1 + t; |
7878 | 8358 |
7879 array_50AC10[2].vWorldViewPosition.x = pOutdoorCamera->shading_dist_mist; | 8359 array_50AC10[2].vWorldViewPosition.x = pOutdoorCamera->shading_dist_mist; |
7880 array_50AC10[2].flt_20 = 1; | 8360 array_50AC10[2]._rhw = 1; |
7881 array_50AC10[2].u = 1; | 8361 array_50AC10[2].u = 1; |
7882 array_50AC10[2].v = 0 + t; | 8362 array_50AC10[2].v = 0 + t; |
7883 | 8363 |
7884 array_50AC10[3].vWorldViewPosition.x = pOutdoorCamera->shading_dist_mist; | 8364 array_50AC10[3].vWorldViewPosition.x = pOutdoorCamera->shading_dist_mist; |
7885 array_50AC10[3].flt_20 = 1; | 8365 array_50AC10[3]._rhw = 1; |
7886 array_50AC10[3].u = 1; | 8366 array_50AC10[3].u = 1; |
7887 array_50AC10[3].v = 1 + t; | 8367 array_50AC10[3].v = 1 + t; |
7888 pRenderer->DrawStrip(_this.uNumVertices, &_this, | 8368 pRenderer->DrawStrip(_this.uNumVertices, &_this, |
7889 pBitmaps_LOD->pHardwareTextures[_this.uTileBitmapID]); | 8369 pBitmaps_LOD->pHardwareTextures[_this.uTileBitmapID]); |
7890 return; | 8370 return; |
9288 v3 = (double)pViewport->uScreenCenterY; | 9768 v3 = (double)pViewport->uScreenCenterY; |
9289 v4 = 0; | 9769 v4 = 0; |
9290 v5 = uNumVertices; | 9770 v5 = uNumVertices; |
9291 do | 9771 do |
9292 { | 9772 { |
9293 v6 = v1 * array_507D30[v4].flt_20; | 9773 v6 = v1 * array_507D30[v4]._rhw; |
9294 v7 = v6 * array_507D30[v4].vWorldViewPosition.y; | 9774 v7 = v6 * array_507D30[v4].vWorldViewPosition.y; |
9295 memcpy(&array_50AC10[v4], &array_507D30[v4], sizeof(array_50AC10[v4])); | 9775 memcpy(&array_50AC10[v4], &array_507D30[v4], sizeof(array_50AC10[v4])); |
9296 array_50AC10[v4].vWorldViewProjX = v2 - v7; | 9776 array_50AC10[v4].vWorldViewProjX = v2 - v7; |
9297 array_50AC10[v4].vWorldViewProjY = v3 - v6 * array_507D30[v4].vWorldViewPosition.z; | 9777 array_50AC10[v4].vWorldViewProjY = v3 - v6 * array_507D30[v4].vWorldViewPosition.z; |
9298 ++v4; | 9778 ++v4; |
18974 { | 19454 { |
18975 double v1; // st7@1 | 19455 double v1; // st7@1 |
18976 double v2; // st7@1 | 19456 double v2; // st7@1 |
18977 | 19457 |
18978 v1 = 1.0 / (v->vWorldViewPosition.x + 0.0000001); | 19458 v1 = 1.0 / (v->vWorldViewPosition.x + 0.0000001); |
18979 v->flt_20 = v1; | 19459 v->_rhw = v1; |
18980 v2 = v1 * (double)pOutdoorCamera->int_fov_rad; | 19460 v2 = v1 * (double)pOutdoorCamera->int_fov_rad; |
18981 v->vWorldViewProjX = (double)pViewport->uScreenCenterX - v2 * v->vWorldViewPosition.y; | 19461 v->vWorldViewProjX = (double)pViewport->uScreenCenterX - v2 * v->vWorldViewPosition.y; |
18982 v->vWorldViewProjY = (double)pViewport->uScreenCenterY - v2 * v->vWorldViewPosition.z; | 19462 v->vWorldViewProjY = (double)pViewport->uScreenCenterY - v2 * v->vWorldViewPosition.z; |
18983 } | 19463 } |
18984 | 19464 |
19966 v13 = v8 * v7 * 65536.0; | 20446 v13 = v8 * v7 * 65536.0; |
19967 v14 = v13 + 6.7553994e15; | 20447 v14 = v13 + 6.7553994e15; |
19968 v1->z = LODWORD(v14); | 20448 v1->z = LODWORD(v14); |
19969 } | 20449 } |
19970 | 20450 |
19971 //----- (0044C448) -------------------------------------------------------- | 20451 |
19972 GUIFont *LoadFont(const char *pFontFile, const char *pFontPalette, ...) | 20452 |
19973 { | 20453 |
19974 GUIFont *result; // eax@1 | 20454 |
19975 const char *v3; // edi@1 | 20455 |
19976 const char **v4; // ebx@2 | |
19977 unsigned int v5; // eax@3 | |
19978 unsigned __int16 **v6; // ecx@6 | |
19979 GUIFont *v7; // [sp+4h] [bp-Ch]@1 | |
19980 int v8; // [sp+8h] [bp-8h]@1 | |
19981 unsigned __int16 **v9; // [sp+Ch] [bp-4h]@2 | |
19982 | |
19983 result = (GUIFont *)pIcons_LOD->LoadRaw(pFontFile, 0); | |
19984 v3 = pFontPalette; | |
19985 v8 = 0; | |
19986 v7 = result; | |
19987 if ( pFontPalette ) | |
19988 { | |
19989 v4 = &pFontPalette; | |
19990 v9 = result->pFontPalettes; | |
19991 do | |
19992 { | |
19993 v5 = pIcons_LOD->LoadTexture(v3, TEXTURE_16BIT_PALETTE); | |
19994 if ( v5 == -1 ) | |
19995 { | |
19996 sprintf(pTmpBuf, "Unable to open %s", v3); | |
19997 Abortf(pTmpBuf); | |
19998 } | |
19999 ++v4; | |
20000 v6 = v9; | |
20001 v3 = *v4; | |
20002 ++v8; | |
20003 ++v9; | |
20004 *v6 = (v5 != -1 ? pIcons_LOD->pTextures[v5].pPalette16 : 0); | |
20005 } | |
20006 while ( v3 ); | |
20007 result = v7; | |
20008 } | |
20009 result->field_8 = v8; | |
20010 return result; | |
20011 } | |
20012 | |
20013 | |
20014 | |
20015 | |
20016 //----- (0044C768) -------------------------------------------------------- | |
20017 char *__fastcall FitTextInAWindow(const char *pInString, GUIFont *pFont, GUIWindow *pWindow, unsigned int uX, int a5) | |
20018 { | |
20019 const char *v5; // edi@1 | |
20020 GUIFont *v6; // esi@1 | |
20021 unsigned int v8; // eax@3 | |
20022 int v9; // edi@3 | |
20023 unsigned __int8 v10; // cl@4 | |
20024 int v11; // edx@10 | |
20025 GUICharMetric *v12; // ecx@10 | |
20026 int v13; // edx@11 | |
20027 int v14; // edx@12 | |
20028 int v15; // edx@13 | |
20029 unsigned int v16; // esi@15 | |
20030 unsigned int v17; // edx@15 | |
20031 unsigned int v18; // ecx@15 | |
20032 int v19; // ebx@16 | |
20033 unsigned __int8 v20; // zf@16 | |
20034 char v21; // sf@16 | |
20035 unsigned __int8 v22; // of@16 | |
20036 int v23; // edi@16 | |
20037 unsigned __int8 v24; // dl@17 | |
20038 int v25; // edi@39 | |
20039 int v26; // eax@42 | |
20040 std::string v27; // [sp-18h] [bp-40h]@2 | |
20041 const char *v28; // [sp-8h] [bp-30h]@2 | |
20042 int v29; // [sp-4h] [bp-2Ch]@2 | |
20043 const char *v30; // [sp+Ch] [bp-1Ch]@1 | |
20044 char Str[3]; // [sp+10h] [bp-18h]@42 | |
20045 char v32; // [sp+13h] [bp-15h]@42 | |
20046 size_t v33; // [sp+14h] [bp-14h]@3 | |
20047 unsigned int v34; // [sp+18h] [bp-10h]@3 | |
20048 GUIFont *v35; // [sp+1Ch] [bp-Ch]@1 | |
20049 int v36; // [sp+20h] [bp-8h]@3 | |
20050 int v37; // [sp+24h] [bp-4h]@3 | |
20051 | |
20052 v5 = pInString; | |
20053 v6 = pFont; | |
20054 v30 = pInString; | |
20055 v35 = pFont; | |
20056 if ( !pInString ) | |
20057 { | |
20058 MessageBoxW(nullptr, L"Invalid string passed !", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Font.cpp:445", 0); | |
20059 return 0; | |
20060 } | |
20061 v33 = strlen(pInString); | |
20062 strcpy(pTmpBuf3, v5); | |
20063 v8 = uX; | |
20064 v9 = 0; | |
20065 v36 = 0; | |
20066 v34 = uX; | |
20067 v37 = 0; | |
20068 if ( (signed int)v33 > 0 ) | |
20069 { | |
20070 while ( 1 ) | |
20071 { | |
20072 v10 = pTmpBuf3[v9]; | |
20073 if ((v10 < v6->cFirstChar || v10 > v6->cLastChar) | |
20074 && v10 != '\f' && v10 != '\r' && v10 != '\t' && v10 != '\n' ) | |
20075 goto LABEL_34; | |
20076 v11 = v10 - 9; | |
20077 v12 = &v6->pMetrics[v10]; | |
20078 if ( !v11 ) | |
20079 { | |
20080 strncpy(Str, &pTmpBuf3[v9 + 1], 3u); | |
20081 v32 = 0; | |
20082 v26 = atoi(Str); | |
20083 v8 = uX + v26; | |
20084 v25 = v9 + 3; | |
20085 v34 = v8; | |
20086 goto LABEL_43; | |
20087 } | |
20088 v13 = v11 - 1; | |
20089 if ( !v13 ) | |
20090 break; | |
20091 v14 = v13 - 2; | |
20092 if ( !v14 ) | |
20093 { | |
20094 v25 = v9 + 5; | |
20095 LABEL_43: | |
20096 v37 = v25; | |
20097 goto LABEL_34; | |
20098 } | |
20099 v15 = v14 - 1; | |
20100 if ( v15 ) | |
20101 { | |
20102 if ( v15 != 19 ) | |
20103 { | |
20104 v16 = v12->uRightSpacing; | |
20105 v17 = v12->uWidth; | |
20106 v18 = v12->uLeftSpacing; | |
20107 if ( v8 + v16 + v18 + v17 < pWindow->uFrameWidth ) | |
20108 { | |
20109 if ( v37 > v36 ) | |
20110 v8 += v18; | |
20111 v8 += v17; | |
20112 if ( v37 < (signed int)v33 ) | |
20113 v8 += v16; | |
20114 v6 = v35; | |
20115 } | |
20116 else | |
20117 { | |
20118 v19 = v36; | |
20119 v8 = v34; | |
20120 v22 = v36 > v37; | |
20121 v20 = v36 == v37; | |
20122 v21 = v36 - v37 < 0; | |
20123 v6 = v35; | |
20124 pTmpBuf3[v36] = 10; | |
20125 v23 = v19; | |
20126 if ( (unsigned __int8)(v21 ^ v22) | v20 ) | |
20127 { | |
20128 do | |
20129 { | |
20130 v24 = pTmpBuf3[v23]; | |
20131 if ( v24 >= v6->cFirstChar && v24 <= v6->cLastChar || v24 == 12 || v24 == 13 || v24 == 9 || v24 == 10 ) | |
20132 { | |
20133 if ( v23 > v19 ) | |
20134 v8 += v6->pMetrics[v24].uLeftSpacing; | |
20135 v8 += *((int *)&v6->cFirstChar + 3 * v24 + 9); | |
20136 if ( v23 < v37 ) | |
20137 v8 += v6->pMetrics[v24].uRightSpacing; | |
20138 } | |
20139 ++v23; | |
20140 } | |
20141 while ( v23 <= v37 ); | |
20142 } | |
20143 } | |
20144 goto LABEL_34; | |
20145 } | |
20146 v8 += v12->uWidth; | |
20147 goto LABEL_41; | |
20148 } | |
20149 if ( !a5 ) | |
20150 return (char *)v30; | |
20151 LABEL_34: | |
20152 v9 = v37++ + 1; | |
20153 if ( v37 >= (signed int)v33 ) | |
20154 return pTmpBuf3; | |
20155 } | |
20156 v8 = v34; | |
20157 LABEL_41: | |
20158 v36 = v9; | |
20159 goto LABEL_34; | |
20160 } | |
20161 return pTmpBuf3; | |
20162 } | |
20163 //----- (00401000) -------------------------------------------------------- | 20456 //----- (00401000) -------------------------------------------------------- |
20164 void __stdcall mm7__vector_constructor(void *a1, int objSize, int numObjs, int (__thiscall *constructor)(int)) | 20457 void __stdcall mm7__vector_constructor(void *a1, int objSize, int numObjs, int (__thiscall *constructor)(int)) |
20165 { | 20458 { |
20166 void *v4; // esi@2 | 20459 void *v4; // esi@2 |
20167 int v5; // edi@2 | 20460 int v5; // edi@2 |