/*-----------------------------------------------------------------* | <<< ヒットポイント表示 >>> | 入力 iNum = 0 : プレイヤー、 1 : エネミー | fLen = バーの長さ(0.0f 〜 1.0f ) *-------------------------------------------------------------------*/ void HitPointDraw(int iNum, float fLen) { d3_stat_zwrite_set(false); d3_stat_zread_set( false); //--- HP描画 ---------------------------------------------------- VEC2 p0, p1; float a = 264.f; if(iNum == 0){ p0 = VEC2( 8, 8); p1 = VEC2( 8 + a, 40);} else { p0 = VEC2(368, 8); p1 = VEC2(368 + a, 40);} d3_2d_box_fill_draw(&p0, &p1, D3_COL(255, 255, 255, 0));// 下地 p0.x += 1, p1.x += -1; // 一回り小さくする p0.y += 1, p1.y += -1; if(iNum == 0){ p0.x += (a - a * fLen);} // プレイヤー else { p1.x -= (a - a * fLen);} // エネミー d3_2d_box_fill_draw(&p0, &p1, D3_COL(255, 255, 255, 0)); // ライフはボックスで //--- KO描画 ----------------------------------------------------- if(iNum == 1) // エネミーの時のみKO描画 { d3_spr_draw(TEX_KO_BAR, NULL, &VEC3(320, 24, 0)); } d3_stat_zread_set( true); d3_stat_zwrite_set(true); }
/*-----------------------------------------------------------------------------* | <<< メニュー使用時のタイトル >>> | 入力 iTex = 表示するテクスチャー番号 | iSound = 左クリック時の効果音 | bSw = true : フェードアウト開始 | 戻り値 true = モードが変わった *-------------------------------------------------------------------------------*/ bool TitleMenu(int iTex, int iSound, bool bSw) { bool bRet = false; //--- 640×480 ドットの絵を表示 -------------------- d3_tex_set(iTex); d3_2d_box_fill_tex_draw(&VEC2(0, 0), &VEC2(__SCR_W, __SCR_H), D3_COL((int)fCount, 255, 255, 255)); //--- キー入力チェック -------------------------------------- if(bSw) // ここ、Title関数と違う { iFade = 1; snd_play(iSound); } //--- フィード ------------------------------------ switch(iFade) { case -1: //イン fCount += FADE_SPEED_; if(fCount >= 255.0f){ fCount = 255.0f; iFade = 0;} break; case 1: //アウト fCount -= FADE_SPEED_; if(fCount <= 0.0f) { fCount = 0.0f; iFade = -1; bRet = true; } break; } return bRet; }
//------------------------------------------------------------------------------------ Mesh* SceneManager::CreatePlaneMesh( float w, float h ) { float halfW = w / 2; float halfH = h / 2; SVertex vert[4] = { SVertex(VEC3(-w,0,+h), VEC2(0,0), VEC3::UNIT_Y), SVertex(VEC3(+w,0,+h), VEC2(1,0), VEC3::UNIT_Y), SVertex(VEC3(+w,0,-h), VEC2(1,1), VEC3::UNIT_Y), SVertex(VEC3(-w,0,-h), VEC2(0,1), VEC3::UNIT_Y), }; DWORD dwIndex[6] = {0,1,3,1,2,3}; Mesh* pMesh = new Mesh; SubMesh* pSubmesh = new SubMesh; pSubmesh->InitVertData(eVertexType_General, vert, 4, true); pSubmesh->InitIndexData(dwIndex, 6, true); pMesh->AddSubMesh(pSubmesh); return pMesh; }
void fire_bullet(struct moag *m, char type, float x, float y, float vx, float vy) { int i = 0; while (m->bullets[i].active) if (++i >= MAX_BULLETS) return; m->bullets[i].active = 4; m->bullets[i].type = type; m->bullets[i].obj.pos = VEC2(x, y); m->bullets[i].x = (int)m->bullets[i].obj.pos.x; m->bullets[i].y = (int)m->bullets[i].obj.pos.y; m->bullets[i].obj.vel = VEC2(vx, vy); broadcast_bullet_chunk(m, SPAWN, i); }
void launch_ladder(struct moag *m, int x, int y) { int i = 0; while (m->bullets[i].active) if (++i >= MAX_BULLETS) return; m->bullets[i].active = LADDER_LENGTH; m->bullets[i].type = LADDER; m->bullets[i].x = x; m->bullets[i].y = y; m->bullets[i].obj.pos = VEC2(x, y); m->bullets[i].obj.vel = VEC2(0, -1); broadcast_bullet_chunk(m, SPAWN, i); }
//================================================================================ //! メソッド名 CTEXTURE_BASE::startTextureInitialize // // 機能 属性の初期化 // 更新 2008/08/30 <新規> //================================================================================ void CTEXTURE_BASE::startTextureInitialize(void) { vb = NULL; //!< バーテックスバッファ showSize = VEC2(0.0f, 0.0f); //!< 表示サイズ texSize = VEC2(0.0f, 0.0f); //!< テクスチャサイズ uCoord = VEC2(0.00001f, 1.0f); //!< UV座標(右上) vCoord = VEC2(0.00001f, 1.0f); //!< UV座標(左下) color = MY_COLOR_RGBA(); //!< カラー vertexPosition = eVERP_CENTER; //!< 頂点の位置 texd_ptr = NULL; //!< メッシュ情報ポインター bTextureLoaded = FALSE; //!< メッシュのロード確認 }
//---------------------------------------------------------------------------------------- D3D11RenderTarget::D3D11RenderTarget() :m_pRenderSystem(g_env.pRenderSystem) ,m_pRenderTexture(nullptr) ,m_clearColor(SColor::BLACK) ,m_bClearColor(true) ,m_bClearZBuffer(true) ,m_bHasDepthBuffer(false) ,m_bNoFrameBuffer(false) ,m_bUpdateRatioAspect(true) ,m_phaseFlag(eRenderPhase_Geometry) ,m_pDepthStencil(nullptr) ,m_sizeRatio(0, 0) { // Create screen quad static bool bCreate = false; if (!bCreate) { m_pQuadMesh = new Mesh; SubMesh* pSubMesh = new SubMesh; SVertex v[4] = { SVertex(VEC3(-1,1,0), VEC2(0,0)), SVertex(VEC3(1,1,0), VEC2(1,0)), SVertex(VEC3(-1,-1,0), VEC2(0,1)), SVertex(VEC3(1,-1,0), VEC2(1,1)) }; DWORD index[6] = { 0,1,2, 1,3,2 }; // Store index to frustum far corner v[0].normal.x = 0; v[1].normal.x = 1; v[2].normal.x = 2; v[3].normal.x = 3; pSubMesh->InitVertData(eVertexType_General, v, ARRAYSIZE(v), true); pSubMesh->InitIndexData(index, ARRAYSIZE(index), true); m_pQuadMesh->AddSubMesh(pSubMesh); m_pQuadEntity = new Entity(m_pQuadMesh); m_pQuadEntity->SetCastShadow(false); m_pQuadEntity->SetReceiveShadow(false); bCreate = true; } }
static void load_intersect(bool base, bool out, float dist, t_vertex const *ray, t_intersect *intersect) { intersect->dist = dist; intersect->pos = VEC3_ADD(ray->pos, VEC3_MUL1(ray->dir, dist)); if (base) intersect->norm = VEC3(0, 0, 1.f); else intersect->norm = ft_vec3norm(VEC3_Z(intersect->pos, -intersect->pos.z)); if (out) intersect->norm = VEC3_SUB(VEC3_0(), intersect->norm); if (base) intersect->tex = VEC2(intersect->pos.x, intersect->pos.y); else intersect->tex = VEC2(intersect->norm.z, intersect->norm.y / 2.f + 0.5f); }
static bool cone_side(t_vec2 *dist, t_vertex const *ray) { float a; float b; float d; a = (VEC2_DOT(ray->dir, ray->dir) - (ray->dir.z * ray->dir.z)) * 2.f; b = (VEC2_DOT(ray->pos, ray->dir) - (ray->pos.z * ray->dir.z)) * 2.f; d = b * b - (2.f * a * (VEC2_DOT(ray->pos, ray->pos) - (ray->pos.z * ray->pos.z))); if (d < 0.f) return (false); if (d != 0.f) d = sqrtf(d); *dist = VEC2((-b - d) / a, (-b + d) / a); if (!cone_check_side(dist->x, ray)) { if (!cone_check_side(dist->y, ray)) return (false); dist->x = dist->y; } else if (!cone_check_side(dist->y, ray)) dist->y = dist->x; return (true); }
//================================================================================ //! メソッド名 CSCENE_MOVIE3::コンストラクタ // // 引数 inFlag 現在のシーンフラグ // inNextFlag 次のシーンフラグ // inData シーン共有データ // 更新 2009/02/10 <新規> //================================================================================ CSCENE_MOVIE3::CSCENE_MOVIE3(SCENE_SHARE_DATA* inData) : //! ゲームシーン CSCENE_MOVIE_BASE(eSCENE_CHAPTER1_MOVIE3, eSCENE_CHAPTER1_STAGE3, inData) { // 初期化 this->camera = NULL; this->cameraTarget = NULL; this->kageo = NULL; this->kagemi = NULL; this->shabird = NULL; this->clime = NULL; this->tima = NULL; this->feather = NULL; this->yamakage = NULL; this->exe = NULL; this->objMapForest = NULL; this->objMapCave = NULL; this->back = NULL; this->cave = NULL; this->movieFlag = eM3F_FOREST; this->backSound = NULL; this->shaderZTexture = NULL; this->shaderDepthBuf = NULL; D3DXMatrixIdentity(&this->lightView); D3DXMatrixIdentity(&this->lightProj); this->lightShift = VEC3(0.0f, 0.0f, 0.0f); this->lightNearFar = VEC2(0.0f, 0.0f); }
/* WM_CREATE processing function */ void window::WMCreate(HWND &hwnd, UINT &message, WPARAM &wParam, LPARAM &lParam) { OpenFName.lStructSize = sizeof(OPENFILENAME); OpenFName.hwndOwner = hwnd; OpenFName.hInstance = NULL; OpenFName.lpstrFilter = "Text files(*.TXT)\0*.txt\0All Files(*.*)\0*.*\0"; OpenFName.lpstrCustomFilter = NULL; OpenFName.nMaxCustFilter = 0; OpenFName.nFilterIndex = 0; OpenFName.lpstrFile = NULL; OpenFName.nMaxFile = _MAX_PATH; OpenFName.lpstrFileTitle = NULL; OpenFName.nMaxFileTitle = _MAX_FNAME + _MAX_EXT; OpenFName.lpstrInitialDir = NULL; OpenFName.lpstrTitle = NULL; OpenFName.Flags = 0; OpenFName.nFileOffset = 0; OpenFName.nFileExtension = 0; OpenFName.lpstrDefExt = "txt"; OpenFName.lCustData = 0L; OpenFName.lpfnHook = NULL; OpenFName.lpTemplateName = NULL; cs = (CREATESTRUCT *)lParam; file_path = (char *)cs->lpCreateParams; if (file_path[0] != 0) txt.LoadFile(file_path); win_size = VEC2(cs->cx, cs->cy); client_field = VEC2(win_size.x / txt.GetFontSize().x, (win_size.y - STAT_BAR_H) / txt.GetFontSize().y ); hStatWnd = CreateWindowEx(0, STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0, hwnd, NULL, GetModuleHandle(NULL), NULL); SendMessage(hStatWnd, SB_SETPARTS, 2, (LPARAM)stat_parts); SendMessage(hStatWnd, SB_SETMINHEIGHT, STAT_BAR_H, 0); hDC = GetDC(hwnd); SelectObject(hDC, txt.GetFont()); SetTextColor(hDC, RGB(0, 255, 0)); SetBkColor(hDC, RGB(0, 0, 0)); ReleaseDC(hwnd, hDC); } /* End of 'WMCreate' function */
void Rasterizer::RasterizeTriangleList( SRenderContext& context ) { FaceList& faces = context.faces; VertexBuffer& verts = context.verts; //each triangle size_t nFace = faces.size(); for (size_t iFace=0; iFace<nFace; ++iFace) { const SFace& face = faces[iFace]; if(face.IsBackface || face.bCulled) continue; const Index idx1 = faces[iFace].index1; const Index idx2 = faces[iFace].index2; const Index idx3 = faces[iFace].index3; const SVertex& vert0 = verts[idx1]; const SVertex& vert1 = verts[idx2]; const SVertex& vert2 = verts[idx3]; assert(vert0.bActive && vert1.bActive && vert2.bActive && "Shit, this can't be true!"); // Determine mip level of this triangle const SMaterial* pMat = context.pMaterial; if (pMat->pDiffuseMap && pMat->pDiffuseMap->bMipMap) { const float areaScreen = Ext::CalcAreaOfTriangle( VEC2(vert0.pos.x, vert0.pos.y), VEC2(vert1.pos.x, vert1.pos.y), VEC2(vert2.pos.x, vert2.pos.y)); float ratio = face.texArea / areaScreen; context.texLod = Ext::Ftoi32_Fast(log(ratio) / log(4.0f) + pMat->pDiffuseMap->lodBias); //clamp it if(context.texLod < 0) context.texLod = 0; if(context.texLod >= pMat->pDiffuseMap->GetMipCount()) context.texLod = pMat->pDiffuseMap->GetMipCount() - 1; } _RasterizeTriangle(vert0, vert1, vert2, face, context); } }
vec3 goursat_grad(vec3 p, vec3 mods) { vec2 q; q = VEC2(0.0, 0.006); return (VEC3(goursat(p + q.yxx, mods) - goursat(p - q.yxx, mods), goursat(p + q.xyx, mods) - goursat(p - q.xyx, mods), goursat(p + q.xxy, mods) - goursat(p - q.xxy, mods))); }
//================================================================================ //! メソッド名 CTEXTURE_BASE::updateUVCoord // // 機能 UV座標の更新 // 更新 2008/08/28 <新規> //================================================================================ void CTEXTURE_BASE::updateUVCoord(void) { HRESULT hr; // 頂点情報(テクスチャ座標)の更新 CUSTOM_VERTEX *pV; hr = vb->Lock(0, 0, (void**)&pV, 0); if( FAILED(hr)) { // 失敗なら、例外を発生 throw hr; } pV[0].uv = VEC2(uCoord.x, vCoord.x); pV[1].uv = VEC2(uCoord.y, vCoord.x); pV[2].uv = VEC2(uCoord.y, vCoord.y); pV[3].uv = VEC2(uCoord.x, vCoord.y); vb->Unlock(); }
/* WM_SIZE message processing */ void window::WMSize(HWND &hwnd, UINT &message, WPARAM &wParam, LPARAM &lParam) { int delta, /* */ cur_vert_pos, //cur_horz_pos, new_horz_range, new_vert_range; VEC2 old_client_field; win_size.x = LOWORD(lParam); win_size.y = HIWORD(lParam); cur_vert_pos = GetScrollPos(hwnd, SB_VERT); //cur_horz_pos = GetScrollPos(hwnd, SB_HORZ); old_client_field = client_field; client_field = VEC2(win_size.x / txt.GetFontSize().x, (win_size.y - STAT_BAR_H) / txt.GetFontSize().y); /* Vert scrollbar */ new_vert_range = txt.num_of_str - client_field.y; if (new_vert_range < 0) new_vert_range = 0; if (new_vert_range > MAX_RANGE) vert_scrlb_step = (int)(ceil(new_vert_range * 1.0 / MAX_RANGE)); SetScrollRange(hwnd, SB_VERT, 0, new_vert_range /= vert_scrlb_step, TRUE); if (cur_vert_pos > new_vert_range) SetScrollPos(hwnd, SB_VERT, new_vert_range, TRUE); delta = cur_vert_pos - new_vert_range; if (delta > 0) txt -= delta * vert_scrlb_step; else txt += delta * vert_scrlb_step; /* Horz scrollbar */ new_horz_range = max_str_len - client_field.x; if (new_horz_range >= 0) SetScrollRange(hwnd, SB_HORZ, 0, new_horz_range, TRUE); else SetScrollRange(hwnd, SB_HORZ, 0, 0, TRUE); delta = max_str_len - start_str_pos; if (delta < client_field.x) { start_str_pos -= client_field.x - delta; if (start_str_pos < 0) start_str_pos = 0; } SendMessage(hStatWnd, WM_SIZE, wParam, lParam); InvalidateRect(hwnd, NULL, TRUE); } /* End of 'window::WMSize' function */
vec3 heart_grad(vec3 p) { vec2 q; q = VEC2(0.0, 0.006); return (VEC3(heart(p + q.yxx) - heart(p - q.yxx), heart(p + q.xyx) - heart(p - q.xyx), heart(p + q.xxy) - heart(p - q.xxy))); }
/*---------------------------------------------------------------------* <<<タイトル>>> 入力 iTex = 表示するテクスチャー番号 *pMode = 値をセットしたい変数のポインタ iNext = 左クリック時の次のモード ※pMode の次の値 iSound = 左クリック時の効果音 戻り値 true = モードが変わった瞬間 ※キーが押された瞬間 *-----------------------------------------------------------------------*/ bool Title(int iTex, int *pMode, int iNext, int iSound) { bool bRet = false; //--- 描画 ---------------------------------------------------------- d3_tex_set(iTex); d3_2d_box_fill_tex_draw(&VEC2(0,0), &VEC2(__SCR_W, __SCR_H)); //---キー入力チェック------------------------------------------------ // スペースキーかマウス左がクリックでモード切り替え if((pad.bKeyClick[KEY_SPACE] || pad.bLeftClick)) { snd_play(iSound); bRet = true; *pMode = iNext; // ポインタを使いモード切り替え } return bRet; }
//------------------------------------------------------------------------------------ bool SceneManager::Init() { m_camera = new Camera; m_camera->SetAspectRatio(m_pRenderSystem->GetWndWidth() / (float)m_pRenderSystem->GetWndHeight()); m_sunLight.lightDir.Set(1, -1, 2); m_sunLight.lightDir.Normalize(); m_sunLight.lightColor.Set(0.8f, 0.8f, 0.8f); m_pSSAO = new SSAO; { m_pDebugRTMesh = new Mesh; SubMesh* pSubMesh = new SubMesh; SVertex v[4] = { SVertex(VEC3(0.5f,1.0f,0), VEC2(0,0)), SVertex(VEC3(1.0f,1.0f,0), VEC2(1,0)), SVertex(VEC3(0.5f,0.4f,0), VEC2(0,1)), SVertex(VEC3(1.0f,0.4f,0), VEC2(1,1)) }; DWORD index[6] = { 0,1,2, 1,3,2 }; pSubMesh->InitVertData(eVertexType_General, v, ARRAYSIZE(v), true); pSubMesh->InitIndexData(index, ARRAYSIZE(index), true); m_pDebugRTMesh->AddSubMesh(pSubMesh); m_pDebugRTMaterial = new Material; m_pDebugRTMaterial->InitShader(GetResPath("DebugRT.hlsl"), GetResPath("DebugRT.hlsl")); pSubMesh->SetMaterial(m_pDebugRTMaterial); } _InitAllScene(); return true; }
/*------------------------------------------------------------------* | <<< 時計描画 >>> | 入力 fTime = 現在の時間 | fMax = 最大時間 *-------------------------------------------------------------------*/ void TimerDraw(float fTime, float fMax) { DWORD c; int i, j; fMax = (fTime / fMax) * 60.f; for(i = 0; i < 60; i++) { if(i < fMax){ c = D3_COL(200, 255, 10, 10); j = 0;} else { c = D3_COL(200, 255, 10, 10); j = 1;} CircleDraw(j, (i + 15) % 60, 60, &VEC2(320, 240), 190, 200, c); } }
bool Title(int iTex, int *pMode, int iNext, int iSound) { bool bRet = false; //--- 描画 ---------------------------------------------------------- d3_tex_set(iTex); d3_2d_box_fill_tex_draw(&VEC2(0,0), &VEC2(__SCR_W, __SCR_H), D3_COL((int)fCount, 255, 255, 255)); //---キー入力チェック------------------------------------------------ // スペースキーかマウス左がクリックでモード切り替え if((pad.bKeyClick[KEY_SPACE] || pad.bLeftClick) && iFade == 0) { iFade = 1; //いきなりモードを変えずに、フィード開始 snd_play(iSound); //bRet = true; //コメント //*pMode = iNext; //コメント } //--- フィード ----------------------------------- switch(iFade) { case -1: // イン fCount += FADE_SPEED_; if(fCount >= 255.0f){ fCount = 255.0f; iFade = 0;} break; case 1: fCount -= FADE_SPEED_; if(fCount <= 0.0f) { fCount = 0.0f; iFade = -1; *pMode = iNext; // フェードアウトしきった時に bRet = true; // 終了とする } break; } return bRet; }
void spawn_tank(struct moag *m, int id) { m->players[id].connected = true; m->players[id].spawn_timer = 0; m->players[id].ladder_timer = LADDER_TIME; m->players[id].ladder_count = 3; m->players[id].kleft = false; m->players[id].kright = false; m->players[id].kup = false; m->players[id].kdown = false; m->players[id].kfire = false; m->players[id].tank.x = rng_range(&m->rng, 20, LAND_WIDTH - 20); m->players[id].tank.y = 60; m->players[id].tank.obj.pos = VEC2(m->players[id].tank.x, m->players[id].tank.y); m->players[id].tank.obj.vel = VEC2(0, 0); m->players[id].tank.angle = 35; m->players[id].tank.facingleft = 0; m->players[id].tank.power = 0; m->players[id].tank.bullet = MISSILE; m->players[id].tank.num_burst = 1; explode(m, m->players[id].tank.x, m->players[id].tank.y - 12, 12, E_SAFE_EXPLODE); broadcast_tank_chunk(m, SPAWN, id); }
//------------------------------------------------------------------------------- void Water::_InitConstantBuffer() { HRESULT hr = S_OK; D3D11_BUFFER_DESC bd; ZeroMemory( &bd, sizeof(bd) ); bd.Usage = D3D11_USAGE_DEFAULT; bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; bd.CPUAccessFlags = 0; bd.ByteWidth = sizeof(cBufferVSFinal); V(m_pRenderSystem->GetDevice()->CreateBuffer( &bd, NULL, &m_pCB_VS )); m_constantBufVS.texScale = VEC2(25, 26); m_constantBufVS.bumpSpeed = VEC2(0.015f, 0.005f); m_constantBufVS.BumpScale = 0.2f; m_constantBufVS.waveFreq = 0.028f; m_constantBufVS.waveAmp = 1.8f; bd.ByteWidth = sizeof(cBufferPSFinal); V(m_pRenderSystem->GetDevice()->CreateBuffer( &bd, NULL, &m_pCB_PS )); m_constantBufPS.deepColor = VEC4(0.0f, 0.3f, 0.5f, 1.0f); m_constantBufPS.shallowColor = VEC4(0.0f, 1.0f, 1.0f, 1.0f); m_constantBufPS.reflectionColor = VEC4(0.95f, 1.0f, 1.0f, 1.0f); m_constantBufPS.reflectionAmount = 0.2f; m_constantBufPS.reflectionBlur = 0.0f; m_constantBufPS.waterAmount = 0.3f; m_constantBufPS.fresnelPower = 5.0f; m_constantBufPS.fresnelBias = 0.328f; m_constantBufPS.refractionAmount = 0.075f; bd.ByteWidth = sizeof(cBufferDepth); V(m_pRenderSystem->GetDevice()->CreateBuffer( &bd, NULL, &m_pCB_Depth )); m_constantBufDepth.waterPlaneHeight = m_waterPlane.d; m_constantBufDepth.depthLimit = 1.0f / 90.0f; }
/* \brief calculates relative view coordinates for a point in world coordinates */ GLHCKAPI kmVec2* glhckCameraPointViewCoordinates(glhckCamera *object, kmVec2 *pOut, const kmVec3 *point) { CALL(2, "%p, "VEC3S, pOut, VEC3(point)); if (!glhckFrustumContainsPoint(&object->frustum, point)) return NULL; kmVec3 p; kmVec3TransformCoord(&p, point, &object->view.viewProj); pOut->x = (p.x + 1)/2; pOut->y = (p.y + 1)/2; RET(2, VEC2S, VEC2(pOut)); return pOut; }
bool handle_cursor_move(t_scop *scop, t_vec2 *look) { double x; double y; if (!(scop->flags & FLAG_CURSOR_MOVE)) return (false); glfwGetCursorPos(scop->window, &x, &y); look->x += fmod((x - scop->cursor.x) / WIN_WIDTH * CURSOR_SPEED, M_PI * 2.0); look->y += fmod((y - scop->cursor.y) / WIN_HEIGHT * CURSOR_SPEED, M_PI * 2.0); scop->cursor = VEC2((float)x, (float)y); scop->flags &= ~FLAG_CURSOR_MOVE; return (true); }
//------------------------------------------------------------------------------------ Decal::Decal(const VEC3& pos, float size, const QUATERNION& rot) : m_vPos(pos) , m_fSize(size) , m_pMaterial(nullptr) { if (!m_pUnitCube) { SVertex vert[8] = { SVertex(VEC3(-0.5f, -0.5f, +0.5f), VEC2(0, 0)), SVertex(VEC3(+0.5f, -0.5f, +0.5f), VEC2(0, 0)), SVertex(VEC3(+0.5f, -0.5f, -0.5f), VEC2(0, 0)), SVertex(VEC3(-0.5f, -0.5f, -0.5f), VEC2(0, 0)), SVertex(VEC3(-0.5f, +0.5f, +0.5f), VEC2(0, 0)), SVertex(VEC3(+0.5f, +0.5f, +0.5f), VEC2(0, 0)), SVertex(VEC3(+0.5f, +0.5f, -0.5f), VEC2(0, 0)), SVertex(VEC3(-0.5f, +0.5f, -0.5f), VEC2(0, 0)), }; DWORD dwIndex[36] = { 0,2,1,0,3,2, // bottom 4,5,7,5,6,7, // top 4,7,0,7,3,0, // left 6,5,2,5,1,2, // right 7,6,3,6,2,3, // behind 5,4,1,4,0,1, // front }; Mesh* pMesh = new Mesh; SubMesh* pSubmesh = new SubMesh; pSubmesh->InitVertData(eVertexType_General, vert, 8, true); pSubmesh->InitIndexData(dwIndex, 36, true); pMesh->AddSubMesh(pSubmesh); m_pUnitCube = new Entity(pMesh); m_pUnitCube->SetCastShadow(false); m_pCB_Decal = g_env.pRenderer->GetRenderSys()->CreateConstantBuffer(sizeof(cBufferDecal), 10); } m_cbDecal.matRotation = rot.ToRotationMatrix().Transpose(); m_cbDecal.fProjClip = 10000.f; }
/* \brief cast a ray from camera at specified relative coordinate */ GLHCKAPI kmRay3* glhckCameraCastRayFromPoint(glhckCamera *object, kmRay3 *pOut, const kmVec2 *point) { CALL(2, "%p, "VEC2S, pOut, VEC2(point)); glhckFrustum *frustum = glhckCameraGetFrustum(object); kmVec3 nu, nv, fu, fv; kmVec3Subtract(&nu, &frustum->corners[GLHCK_FRUSTUM_CORNER_NEAR_BOTTOM_RIGHT], &frustum->corners[GLHCK_FRUSTUM_CORNER_NEAR_BOTTOM_LEFT]); kmVec3Subtract(&nv, &frustum->corners[GLHCK_FRUSTUM_CORNER_NEAR_TOP_LEFT], &frustum->corners[GLHCK_FRUSTUM_CORNER_NEAR_BOTTOM_LEFT]); kmVec3Subtract(&fu, &frustum->corners[GLHCK_FRUSTUM_CORNER_FAR_BOTTOM_RIGHT], &frustum->corners[GLHCK_FRUSTUM_CORNER_FAR_BOTTOM_LEFT]); kmVec3Subtract(&fv, &frustum->corners[GLHCK_FRUSTUM_CORNER_FAR_TOP_LEFT], &frustum->corners[GLHCK_FRUSTUM_CORNER_FAR_BOTTOM_LEFT]); kmVec3Scale(&nu, &nu, point->x); kmVec3Scale(&nv, &nv, point->y); kmVec3Scale(&fu, &fu, point->x); kmVec3Scale(&fv, &fv, point->y); pOut->start = frustum->corners[GLHCK_FRUSTUM_CORNER_NEAR_BOTTOM_LEFT]; pOut->dir = frustum->corners[GLHCK_FRUSTUM_CORNER_FAR_BOTTOM_LEFT]; kmVec3Add(&pOut->start, &pOut->start, &nu); kmVec3Add(&pOut->start, &pOut->start, &nv); kmVec3Add(&pOut->dir, &pOut->dir, &fu); kmVec3Add(&pOut->dir, &pOut->dir, &fv); kmVec3Subtract(&pOut->dir, &pOut->dir, &pOut->start); RET(2, "%p", pOut); return pOut; }
static bool cone_intersect(t_vec2 *dist, bool *base, t_vertex const *ray) { float tmp; if (!cone_side(dist, ray)) { if (!cone_base(&tmp, ray)) return (false); *dist = VEC2(tmp, tmp); base[0] = true; base[1] = true; } else if (!cone_base(&tmp, ray)) { base[0] = false; base[1] = false; } else { dist->x = (base[0] = (tmp < dist->x)) ? tmp : dist->x; dist->y = (base[1] = (tmp > dist->y)) ? tmp : dist->y; } return (true); }
//================================================================================ //! メソッド名 CSCENE_MOVIE3::sceneInitialize // // 機能 初期化 // 引数 inStageNum 外部データ番号 // 更新 2009/02/10 <新規> //================================================================================ void CSCENE_MOVIE3::sceneInitialize(int inStageNum) { // ムービーの初期化 this->initializeMovie(3); // 初期解放 this->sceneFinishalize(); // 初期化 // カメラ this->camera = new C3D_OBJECT_CAMERA(&VEC3(0.0f,0.0f,0.0f), &VEC3(0.0f,0.0f,0.0f)); this->camera->setViewFar(20000.0f); this->camera->setViewShift(&VEC3(100.0f, -500.0f, 2000.0f)); // カメラターゲット this->cameraTarget = new C3D_OBJECT(); // カゲオ this->kageo = new CSKIN_MESH(gDev->getDevice(), "movie_kageo"); // カゲミ this->kagemi = new CSKIN_MESH(gDev->getDevice(), "movie_kagemi"); // シャバード this->shabird = new CSKIN_MESH(gDev->getDevice(), "enemy_shabird"); // クライム this->clime = new CSKIN_MESH(gDev->getDevice(), "movie_clime"); // ティマ this->tima = new CSKIN_MESH(gDev->getDevice(), "movie_tima"); // フェザー this->feather = new CSKIN_MESH(gDev->getDevice(), "movie_feather"); // ヤマカゲ this->yamakage = new CSKIN_MESH(gDev->getDevice(), "movie_yamakage"); // エクス this->exe = new CSKIN_MESH(gDev->getDevice(), "movie_exe"); // 空背景 this->back = new CBACK_SKY(this->gDev->getDevice(), &VEC3(0.0f,0.0f,0.0f)); // 使用するエフェクトの生成 this->effectCenter->addEffects( EFFECT_SMOKE, new C3D_EFFECT(gDev->getDevice(), EFFECT_SMOKE, VEC3(0.0f,0.0f,0.0f))); // 洞窟 this->cave = new CMESH(gDev->getDevice(), "kage_stage_doom2"); // BGM this->backSound = new SSTREAMING("ainoaisatu"); this->backSound->play(0, DSBPLAY_LOOPING); // Zテクスチャシェーダの生成 this->shaderZTexture = CZTEX_SHA::getInstance(); this->shaderZTexture->initialize( this->gDev->getDevice(), this->gDev->getScreenSizeX(), this->gDev->getScreenSizeY()); // 深度バッファシェーダの生成 this->shaderDepthBuf = CDEPTH_SHA::getInstance(); this->shaderDepthBuf->initialize(this->gDev->getDevice()); this->shaderDepthBuf->setShadowMap(this->shaderZTexture->getZTex()); // ライトの設定------------------------------------------ // ライトビューのオフセット値を設定 this->lightNearFar = VEC2(1000.0f, 12000.0f); this->lightShift = VEC3(5000.0f, 5000.0f, -6000.0f); // ライト射影行列の設定 D3DXMatrixPerspectiveFovLH(&this->lightProj, D3DXToRadian(70), 1.0f, lightNearFar.x, lightNearFar.y); // ------------------------------------------------------ // 3Dマップ(森) this->objMapForest = new CGAME_MAP(); this->objMapForest->initialize(this->gDev->getDevice(), 203); // 3Dマップ(シャドウクリミナルアジト洞窟) this->objMapCave = new CGAME_MAP(); this->objMapCave->initialize(this->gDev->getDevice(), 204); this->movieFlag = eM3F_FOREST; // ムービーの開始 this->movieStartProc(); }
//================================================================================ //! メソッド名 CTEXTURE_BASE::updateCorner // // 機能 コーナーの更新 // 更新 2008/08/28 <新規> //================================================================================ void CTEXTURE_BASE::updateCorner(void) { VEC2 h = VEC2(0.0f, 0.0f); VEC2 v = VEC2(0.0f, 0.0f); // 頂点の位置を決定 switch(vertexPosition) { case eVERP_LEFT_UP: h += VEC2(-( 0.0f), (showSize.x )); v += VEC2( ( 0.0f), -(showSize.y )); break; case eVERP_UP: h += VEC2(-(showSize.x / 2.0f), (showSize.x / 2.0f)); v += VEC2( ( 0.0f), -(showSize.y )); break; case eVERP_RIGHT_UP: h += VEC2(-(showSize.x ), ( 0.0f)); v += VEC2( ( 0.0f), -(showSize.y )); break; case eVERP_RIGHT: h += VEC2(-(showSize.x ), ( 0.0f)); v += VEC2( (showSize.y / 2.0f), -(showSize.y / 2.0f)); break; case eVERP_RIGHT_DOWN: h += VEC2(-(showSize.x ), ( 0.0f)); v += VEC2( (showSize.y ), -( 0.0f)); break; case eVERP_DOWN: h += VEC2(-(showSize.x / 2.0f), (showSize.x / 2.0f)); v += VEC2( (showSize.y ), -( 0.0f)); break; case eVERP_LEFT_DOWN: h += VEC2(-( 0.0f), (showSize.x )); v += VEC2( (showSize.y ), -( 0.0f)); break; case eVERP_LEFT: h += VEC2(-( 0.0f), (showSize.x )); v += VEC2( (showSize.y / 2.0f), -(showSize.y / 2.0f)); break; case eVERP_CENTER: h += VEC2(-(showSize.x / 2.0f), (showSize.x / 2.0f)); v += VEC2( (showSize.y / 2.0f), -(showSize.y / 2.0f)); break; } corner[0] = VEC3(h.x, v.x, 0.0f); //!<左上 corner[1] = VEC3(h.y, v.x, 0.0f); //!<右上 corner[2] = VEC3(h.y, v.y, 0.0f); //!<右下 corner[3] = VEC3(h.x, v.y, 0.0f); //!<左下 HRESULT hr; // 頂点情報(テクスチャ座標)の更新 CUSTOM_VERTEX *pV; hr = vb->Lock(0, 0, (void**)&pV, 0); if( FAILED(hr)) { // 失敗なら、例外を発生 throw hr; } pV[0].pos = corner[0]; pV[1].pos = corner[1]; pV[2].pos = corner[2]; pV[3].pos = corner[3]; VEC3 min = pV[0].pos; VEC3 max = pV[0].pos; for(int i = 0; i < NUM_TEXTURE_VERTEX; i++) { min.x = min(pV[i].pos.x, min.x); min.y = min(pV[i].pos.y, min.y); min.z = min(pV[i].pos.z, min.z); max.x = max(pV[i].pos.x, max.x); max.y = max(pV[i].pos.y, max.y); max.z = max(pV[i].pos.z, max.z); } vb->Unlock(); }
// // 更新 // VOID CGfxBillboard::Update(const CEntityCamera *pCamera, CParticle *pParticleList, INT numParticles) { // // 1. 参数安全检查 // if (pCamera == NULL || pParticleList == NULL || numParticles <= 0) { return; } // // 2. 更新相机矩阵 // if (m_directionType == DIRECTION_CAMERA) { VEC3 direction; VEC3 position, up, target; Vec3Scale(&direction, pCamera->GetForwardDirection(), -1.0f); Vec3Set(&up, 0.0f, 1.0f, 0.0f); Vec3Set(&position, 0.0f, 0.0f, 0.0f); Vec3Ma(&target, &position, &direction, 1.0f); MtxDefLookAt(&m_mtxFaceToCamera, &position, &up, &target); } // // 3. 更新粒子数据 // VERTEX *vertices = (VERTEX *)SAFE_MALLOC(4 * numParticles * sizeof(*vertices), MEMTYPE_STACK); { // Billboard // 0 ___ 3 // | | // |___| // 1 2 INT indexVertex = 0; CParticle *pParticle = pParticleList; while (pParticle) { const VEC3 *parentWorldScale = pParticle->pEmitter->GetWorldScale(); const VEC3 *parentWorldPosition = pParticle->pEmitter->GetWorldPosition(); const QUAT *parentWorldOrientation = pParticle->pEmitter->GetWorldOrientation(); // // 1. 计算粒子位置与朝向 // VEC3 scale; VEC3 position; QUAT orientation; if (pParticle->bKeepLocal && pParticle->pEmitter) { Vec3Mul(&scale, &pParticle->localScale, parentWorldScale); if (m_directionType == DIRECTION_FIXED) { QuatMul(&orientation, &pParticle->localOrientation, parentWorldOrientation); } VEC3 scalePosition; VEC3 scaleOrientationPosition; Vec3Mul(&scalePosition, &pParticle->localPosition, parentWorldScale); Vec3MulQuat(&scaleOrientationPosition, &scalePosition, parentWorldOrientation); Vec3Add(&position, &scaleOrientationPosition, parentWorldPosition); } else { Vec3Copy(&scale, &pParticle->localScale); if (m_directionType == DIRECTION_FIXED) { QuatCopy(&orientation, &pParticle->localOrientation); } Vec3Copy(&position, &pParticle->localPosition); } // // 2. 粒子位置偏移量 // MATRIX4 mtxOrientation; if (m_directionType == DIRECTION_CAMERA) { MtxCopy(&mtxOrientation, &m_mtxFaceToCamera); if (m_offset < -EPSILON_E3 || m_offset > EPSILON_E3) { VEC3 offsetDirection; Vec3Sub(&offsetDirection, pCamera->GetPosition(), &position); Vec3Normalize(&offsetDirection); Vec3Ma(&position, &position, &offsetDirection, m_offset); } } else { QuatToMtxRotation(&mtxOrientation, &orientation); if (m_offset < -EPSILON_E3 || m_offset > EPSILON_E3) { VEC3 localDirection; VEC3 offsetDirection; Vec3Set(&localDirection, 0.0f, 0.0f, 1.0f); Vec3MulQuat(&offsetDirection, &localDirection, &orientation); Vec3Normalize(&offsetDirection); Vec3Ma(&position, &position, &offsetDirection, m_offset); } } // // 3. 计算粒子变换矩阵 // MATRIX4 mtxScale; MATRIX4 mtxRotate; MATRIX4 mtxRotateSelf; MATRIX4 mtxTranslate; MtxDefScale(&mtxScale, scale[0], scale[1], scale[2]); MtxDefTranslate(&mtxTranslate, position[0], position[1], position[2]); MtxDefRotateAxisAngle(&mtxRotateSelf, &axisz, pParticle->radian); MtxMul(&mtxRotate, &mtxRotateSelf, &mtxOrientation); MATRIX4 mtxSR; MATRIX4 mtxTransform; MtxMul(&mtxSR, &mtxScale, &mtxRotate); MtxMul(&mtxTransform, &mtxSR, &mtxTranslate); // // 4. 计算粒子纹理矩阵 // MATRIX4 mtxTexScale; MATRIX4 mtxTexTranslate; MATRIX4 mtxTexTransform; MtxDefScale(&mtxTexScale, pParticle->texSequenceScale[0], pParticle->texSequenceScale[1], 1.0f); MtxDefTranslate(&mtxTexTranslate, pParticle->texSequenceOffset[0] + pParticle->texScrollOffset[0], pParticle->texSequenceOffset[1] + pParticle->texScrollOffset[1], 0.0f); MtxMul(&mtxTexTransform, &mtxTexScale, &mtxTexTranslate); // // 5. 计算粒子顶点 // VEC3 desVertices[4]; VEC3 srcVertices[4] = { VEC3(-1.0f, 1.0f, 0.0f), VEC3(-1.0f, -1.0f, 0.0f), VEC3( 1.0f, -1.0f, 0.0f), VEC3( 1.0f, 1.0f, 0.0f), }; VEC2 texCoords[4] = { VEC2(pParticle->uvOffset[0] + 0.0f, pParticle->uvOffset[1] + 0.0f), VEC2(pParticle->uvOffset[0] + 0.0f, pParticle->uvOffset[1] + 1.0f), VEC2(pParticle->uvOffset[0] + 1.0f, pParticle->uvOffset[1] + 1.0f), VEC2(pParticle->uvOffset[0] + 1.0f, pParticle->uvOffset[1] + 0.0f), }; VEC3 localNormal, localBinormal; VEC3 worldNormal, worldBinormal; Vec3Set(&localNormal, 0.0f, 0.0f, 1.0f); Vec3Set(&localBinormal, 1.0f, 0.0f, 0.0f); Vec3MulMtx3x3(&worldNormal, &localNormal, &mtxTransform); Vec3MulMtx3x3(&worldBinormal, &localBinormal, &mtxTransform); Vec3MulMtx4x4(&desVertices[0], &srcVertices[0], &mtxTransform); Vec3MulMtx4x4(&desVertices[1], &srcVertices[1], &mtxTransform); Vec3MulMtx4x4(&desVertices[2], &srcVertices[2], &mtxTransform); Vec3MulMtx4x4(&desVertices[3], &srcVertices[3], &mtxTransform); Vec3Copy(&vertices[indexVertex].position, &desVertices[0]); Vec3Copy(&vertices[indexVertex].normal, &worldNormal); Vec3Copy(&vertices[indexVertex].binormal, &worldBinormal); Vec4Copy(&vertices[indexVertex].color, &pParticle->color); Vec2MulMtx4x4(&vertices[indexVertex].texCoordDiffuse, &texCoords[0], &mtxTexTransform); indexVertex++; Vec3Copy(&vertices[indexVertex].position, &desVertices[1]); Vec3Copy(&vertices[indexVertex].normal, &worldNormal); Vec3Copy(&vertices[indexVertex].binormal, &worldBinormal); Vec4Copy(&vertices[indexVertex].color, &pParticle->color); Vec2MulMtx4x4(&vertices[indexVertex].texCoordDiffuse, &texCoords[1], &mtxTexTransform); indexVertex++; Vec3Copy(&vertices[indexVertex].position, &desVertices[2]); Vec3Copy(&vertices[indexVertex].normal, &worldNormal); Vec3Copy(&vertices[indexVertex].binormal, &worldBinormal); Vec4Copy(&vertices[indexVertex].color, &pParticle->color); Vec2MulMtx4x4(&vertices[indexVertex].texCoordDiffuse, &texCoords[2], &mtxTexTransform); indexVertex++; Vec3Copy(&vertices[indexVertex].position, &desVertices[3]); Vec3Copy(&vertices[indexVertex].normal, &worldNormal); Vec3Copy(&vertices[indexVertex].binormal, &worldBinormal); Vec4Copy(&vertices[indexVertex].color, &pParticle->color); Vec2MulMtx4x4(&vertices[indexVertex].texCoordDiffuse, &texCoords[3], &mtxTexTransform); indexVertex++; pParticle = pParticle->pNext; } Renderer()->BindVBO(GL_ARRAY_BUFFER, m_vbo); Renderer()->UpdateVBO(GL_ARRAY_BUFFER, 0, 4 * numParticles * sizeof(*vertices), vertices); } SAFE_FREE(vertices); }