約 4,587,486 件
https://w.atwiki.jp/bambooflow/pages/38.html
9. サポート関数 9. サポート関数9.1. 回転関数 9.2. 質量(Mass)関数 9.3. 数学(Math)関数 9.4. エラーとメモリ関数 9.1. 回転関数 Rigid body orientations are represented with quaternions. A quaternion is four numbers [cos( theta /2),sin( theta /2)*u] where theta is a rotation angle and u is a unit length rotation axis. 剛体の方位は四元数で表わされる。シータが回転角度で、uがユニット長 さ回転軸である場合、四元数は[cos(θ/2)およびsin(θ/2)*u]の4つの数である。 Every rigid body also has a 3x3 rotation matrix that is derived from the quaternion. The rotation matrix and the quaternion always match. すべての剛体は、さらに四元数から得られる3x3回転マトリックスを 持っている。回転マトリックスおよび四元数は常に一致する。 Some information about quaternions 四元数に関するいくつかの情報 q and -q represent the same rotation. qと-qは同じ回転を表す。 The inverse of a quaternion is [ q[0] -q[1] -q[2] -q[3] ]. 四元数の逆は[q[0]-q[1]-q[2]-q[3]]。 The following are utility functions for dealing with rotation matrices and quaternions. 下記は、回転マトリックスおよび四元数に対処するためのユーティリィ ティ関数である。 void dRSetIdentity (dMatrix3 R); Set R to the identity matrix (i.e. no rotation). 単位行列(つまり回転はない)においてRを設定する。 void dRFromAxisAndAngle (dMatrix3 R, dReal ax, dReal ay, dReal az, dReal angle); Compute the rotation matrix R as a rotation of angle radians along the axis (ax,ay,az). 軸(ax, ay, az)に沿ったangleラジアンの回転として回転マトリックスRを計算する。 void dRFromEulerAngles (dMatrix3 R, dReal phi, dReal theta, dReal psi); Compute the rotation matrix R from the three Euler rotation angles. void dRFrom2Axes (dMatrix3 R, dReal ax, dReal ay, dReal az, dReal bx, dReal by, dReal bz); Compute the rotation matrix R from the two vectors `a (ax,ay,az) and `b (bx,by,bz). `a and `b are the desired x and y axes of the rotated coordinate system. If necessary, `a and `b will be made unit length, and `b will be projected so that it is perpendicular to `a . The desired z axis is the cross product of `a and `b . void dQSetIdentity (dQuaternion q); Set q to the identity rotation (i.e. no rotation). 単位行列(つまり回転はない)においてqを設定する。 void dQFromAxisAndAngle (dQuaternion q, dReal ax, dReal ay, dReal az, dReal angle); Compute q as a rotation of angle radians along the axis (ax,ay,az). 軸(ax, ay, az)に沿ったangleラジアンの回転として回転マトリックスqを計算する。 void dQMultiply0 (dQuaternion qa, const dQuaternion qb, const dQuaternion qc); void dQMultiply1 (dQuaternion qa, const dQuaternion qb, const dQuaternion qc); void dQMultiply2 (dQuaternion qa, const dQuaternion qb, const dQuaternion qc); void dQMultiply3 (dQuaternion qa, const dQuaternion qb, const dQuaternion qc); Set qa = qb*qc. This is that same as qa = rotation qc followed by rotation qb. The 0/1/2 versions are analogous to the multiply functions, i.e. 1 uses the inverse of qb, and 2 uses the inverse of qc. Option 3 uses the inverse of both. void dQtoR (const dQuaternion q, dMatrix3 R); Convert quaternion q to rotation matrix R. 四元数qを回転マトリックスRに変換する。 void dRtoQ (const dMatrix3 R, dQuaternion q); Convert rotation matrix R to quaternion q. 回転マトリックスRを四元数qに変換する。 void dWtoDQ (const dVector3 w, const dQuaternion q, dVector4 dq); Given an existing orientation q and an angular velocity vector w, return in dq the resulting dq/dt. 9.2. 質量(Mass)関数 The mass parameters of a rigid body are described by a dMass structure 剛体の質量パラメータはdMass構造体で記述される: typedef struct dMass { dReal mass; // 剛体の全体の質量 dVector4 c; // 剛体フレーム(x,y,z)の重心の位置 dMatrix3 I; // PORに関する剛体フレームの3x3慣性テンソル(inertia tensor) } dMass; The following functions operate on this structure 下記の関数はこの構造体で動作する: void dMassSetZero (dMass *); Set all the mass parameters to zero. 全てのmassパラメータをゼロに設定する。 void dMassSetParameters (dMass *, dReal themass, dReal cgx, dReal cgy, dReal cgz, dReal I11, dReal I22, dReal I33, dReal I12, dReal I13, dReal I23); Set the mass parameters to the given values. themass is the mass of the body. (cx,cy,cz) is the center of gravity position in the body frame. The Ixx values are the elements of the inertia matrix 与えられた値について質量パラメータを設定する。themassは剛体 の質量である。(cx,cy,cz)は剛体フレームの重心位置である。Ixx値は慣性マトリックスの要素である [ I11 I12 I13 ] [ I12 I22 I23 ] [ I13 I23 I33 ] void dMassSetSphere (dMass *, dReal density, dReal radius); void dMassSetSphereTotal (dMass *, dReal total_mass, dReal radius); Set the mass parameters to represent a sphere of the given radius and density, with the center of mass at (0,0,0) relative to the body. The first function accepts the density of the sphere, the second accepts the total mass of the sphere. 与えられた半径および密度の球体を表すために、剛体の相対的な (0,0,0)の重心で、質量パラメータを設定する。第1の関数は、球体の密度を受理し、第2に球体の質量の合計を受理する。 void dMassSetCappedCylinder (dMass *, dReal density, int direction, dReal radius, dReal length); void dMassSetCappedCylinderTotal (dMass *, dReal total_mass, int direction, dReal radius, dReal length); Set the mass parameters to represent a capped cylinder of the given parameters and density, with the center of mass at (0,0,0) relative to the body. The radius of the cylinder (and the spherical cap) is radius. The length of the cylinder (not counting the spherical cap) is length. The cylinder s long axis is oriented along the body s x, y or z axis according to the value of direction (1=x, 2=y, 3=z). The first function accepts the density of the object, the second accepts its total mass. void dMassSetCylinder (dMass *, dReal density, int direction, dReal radius, dReal length); void dMassSetCylinderTotal (dMass *, dReal total_mass, int direction, dReal radius, dReal length); Set the mass parameters to represent a flat-ended cylinder of the given parameters and density, with the center of mass at (0,0,0) relative to the body. The radius of the cylinder is radius. The length of the cylinder is length. The cylinder s long axis is oriented along the body s x, y or z axis according to the value of direction (1=x, 2=y, 3=z). The first function accepts the density of the object, the second accepts its total mass. パラメータと密度が与えられたフラットエンドのシリンダを表すために剛 体の相対的な(0,0,0)の重心で、質量パラメータを設定する。シリンダの半径はradiusである。シリンダの長さはlengthである。シリンダの 長い軸は、剛体のdirection(1=x,2=y,3=z)の値により、x,y,あるいはz軸に沿って適応される。第1の関数は、オブジェクトの密度 を受理する。第2は、その質量の合計を受理する。 void dMassSetBox (dMass *, dReal density, dReal lx, dReal ly, dReal lz); void dMassSetBoxTotal (dMass *, dReal total_mass, dReal lx, dReal ly, dReal lz); Set the mass parameters to represent a box of the given dimensions and density, with the center of mass at (0,0,0) relative to the body. The side lengths of the box along the x, y and z axes are lx, ly and lz. The first function accepts the density of the object, the second accepts its total mass. void dMassAdjust (dMass *, dReal newmass); Given mass parameters for some object, adjust them so the total mass is now newmass. This is useful when using the above functions to set the mass parameters for certain objects - they take the object density, not the total mass. オブジェクトに質量パラメータが与えられ、質量の合計が今の newmassであるようにそれらを調節する。オブジェクトのために質量パラメータをセットする上記の機能を使用する場合、これは有用です。それらは質量 の合計ではなく、オブジェクトの密度となる。 void dMassTranslate (dMass *, dReal x, dReal y, dReal z); Given mass parameters for some object, adjust them to represent the object displaced by (x,y,z) relative to the body frame. オブジェクトに質量パラメータを与える、剛体フレームの相対的な(x, y,z)に置き換えられたオブジェクトを表わすためにそれらを調整する。 void dMassRotate (dMass *, const dMatrix3 R); Given mass parameters for some object, adjust them to represent the object rotated by R relative to the body frame. void dMassAdd (dMass *a, const dMass *b); Add the mass b to the mass a. 9.3. 数学(Math)関数 [There are quite a lot of these, but they re not standardized enough to document yet]. 9.4. エラーとメモリ関数 [Document these later].
https://w.atwiki.jp/unitymemo/pages/18.html
private float speed = 0.07f; target = GameObject.Find("Player").transform; transform.rotation = Quaternion.Slerp( transform.rotation, Quaternion.LookRotation(target.position - transform.position), 0.07f); transform.position += transform.forward * speed;
https://w.atwiki.jp/katzmier/pages/10.html
自分自身の削除 オブジェクトが落下中かどうか オブジェクトを吹き飛ばす オブジェクトを指定方向に進ませる プレハブを発生させる(Inspector登録バージョン) プレハブを発生させる(Resources登録バージョン) 自分自身の削除 Destroy(this.gameObject); オブジェクトが落下中かどうか 参考:一方通行のコライダーを設定する、Platform Effector 2D void OnCollisionEnter2D(Collision2D coll){ var velocity = rigidbody.velocity; if(velocity.y = 0 ){ velocity.y = 6;//強制ジャンプ rigidbody.velocity = velocity; } } オブジェクトを吹き飛ばす var SkeletonRD GameObject; var SKRD GameObject; SKRD = Instantiate(SkeletonRD, Vector3(0,0,0), Quaternion.identity); SkeletonRD = GameObject.Find( SKELETONRD(Clone) ).gameObject; SkeletonRD.GetComponent(Rigidbody).AddForce(Vector3(0.0f, 100.0f, 0.0f), ForceMode.Impulse); オブジェクトを指定方向に進ませる 例:プレイヤーを向きながら飛んでくるミサイルvar Player GameObject;Player = GameObject.Find( Dimples ).gameObject; var v3 Vector3 = (Player.transform.position - this.transform.position);this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(Player.transform.position - this.transform.position), 0.1f);this.GetComponent(Rigidbody).AddForce(v3 * 0.1f * Time.deltaTime, ForceMode.Force); プレハブを発生させる(Inspector登録バージョン) var BoomPrefab GameObject; Inspectorでプレハブを登録しといてから Instantiate(BoomPrefab,Vector3(0,0,5.0f),Quaternion.identity); プレハブを発生させる(Resources登録バージョン) Projectビューに「Resources」フォルダを作成 「Resources」フォルダ配下にPrefabを置く Instantiate(Resources.Load( Detonator-Base ),Vector3(0,0,5.0f),Quaternion.identity); 参考http //hamken100.blogspot.jp/2012/04/unity-resourcesprefab.html 利点 リソースデータの呼び出しが簡潔になる。 動的に呼び出すデータを変更する仕組みが作りやすい。 欠点 スクリプトの再利用性がなくなる場合がある。 使わなくなったデータがキャッシュに残るので適当にUnloadしてやる必要がある。 Resources.UnloadUnusedAssets();
https://w.atwiki.jp/threejs/pages/100.html
更新日:2013-05-04, r58 Object3Dのサブクラス。 Mesh THREE.Object3D ┣ geometry THREE.Geometry ┃┣ vertices Array ┃┃┗ [i] THREE.Vector3 ┃┗ faces Array ┃ ┗ [i] THREE.Face4 (THREE.Face3) ┣ material THREE.Material ┃ ┣ position THREE.Vector3 ┣ rotation THREE.Vector3 ┣ quaternion THREE.Quaternion ┣ useQuaternion bool [false] ┗ scale THREE.Vector3
https://w.atwiki.jp/unitymemo/pages/59.html
オブジェクトの移動 Translateはローカル座標系で移動(相対移動) transform.Translate(2.0f * Vector3.right); グローバル座標系(絶対移動) transform.position += 2.0f * Vector3.right; オブジェクトの無効・有効 オブジェクトを有効に objects[i].SetActive(true); オブジェクトを無効に cube.SetActive(false); オブジェクトの状態を取得 bool test = game_object.activeSelf; オブジェクトの回転 オイラー角から Quaternionに変換して角度を指定 transform.rotation = Quaternion.Euler(45, 45, 0); オイラー角で角度を指定 transform.eulerAngles = new Vector3(45, 45, 0); オイラー角で回転角度を指定 transform.Rotate(10, 0, 0); transform.Rotate(0, 20, 0); transform.Rotate(0, 0, 30); 回転なしにする myTransform.rotation = Quaternion.identity; 他のオブジェクトの参照 名前からの参照 pos = GameObject.Find ("CamPos").transform; tag名からの参照 obj = GameObject.FindWithTag ("Player"); オブジェクトの無効・有効 オブジェクトを有効に objects[i].SetActive(true); オブジェクトを無効に cube.SetActive(false); オブジェクトの状態を取得 bool test = game_object.activeSelf;
https://w.atwiki.jp/ternita/
つい、センターボタンを iPhoneを購入して1月ほどのビギナーです。 そろそろ使い方も慣れてきた感じ。 ただ、何かの拍子につい、センターボタンを押してしまうんだよね。 なんでかな? アプリを閉じたい時とか、あとなんか、選択したい時なんだろうか。 クリックの感覚で押しちゃうのかな。 結構無意識に押してしまうようです。 何かやってる途中で、つい押しちゃってホーム画面に戻っちゃうのね。 そういえば、iPhoneを持つ前は、このホームボタンがボタンだと思わなかったのでした。 ただのデザイン的な凹みだと思ってて。 だってボタンが凹んでるなんて! これがボタンと知った時はビックリしたもの。 育毛に効果がある亜鉛の吸収を高める方法 亜鉛は、皮膚や毛髪を作るために重要な働きがある事から、アンチエイジングのために摂取する人が多い栄養素です。 亜鉛は、ビタミンCと一緒に摂取する事によって、吸収を高める事が出来ます。 亜鉛を多く含んでいる食品として有名なのが、牡蠣です。 牡蠣フライにレモンを絞ってふりかけるという食べ方は、亜鉛の吸収を高めるために、理想的な摂取方法と言えます。 育毛目的で亜鉛のサプリメントを使用する場合には、ビタミンCも同時に摂取するのが、有効な使用方法です。 私の後輩の頭皮改善 私は、某自動車製造工場に勤務している38才既婚者です、工場現場は、常に帽子又は、ヘルメットを着用するルールになっている為どうしても頭皮の通気性が悪く若くしてハゲてしまう方が多くいます、私自身はハゲてはいませんが、後輩で年齢30才独身の方が頭の天辺が薄くなっています、そこで頭皮改善として髪の毛の洗い方から専用育毛シャンプー又食生活の改善(脂っぽい食べ物を辞める)ことを実施し約6か月がたちますが効果は驚くほど発毛してくれました、やっぱり洗い方と食生活は大事であると思いました。 見た目の変化 私は2年前に大手の会社の無料お試し増毛をやってみました。 無料お試しだったので量は少なかったのですが見た目は結構変わった感じがしました。 なので増毛を続けてみようと思いましたがいきなり増毛をしてしまうと周りに見られて恥ずかしいのでちょっとづつ増やしていくことにしました。 1年間を費やして増やしていったので誰も気づかなかったです。 でも昔の写真などと比べてみると明らかに違います。 私の場合シャンプーを変えたと言いごまかしています!
https://w.atwiki.jp/opengl/pages/149.html
クォータニオンとクォータニオンを補間するには 『球面線形補間』を使います。 #pragma comment(linker, /SUBSYSTEM WINDOWS /ENTRY mainCRTStartup ) #include GL/freeglut/freeglut.h #include stdio.h #include math.h #define WIDTH 320 #define HEIGHT 240 #define PAI 3.14159 //黄色 GLfloat yellow[] = { 1.0, 1.0, 0.0, 1.0}; bool flag=true; float t=0.0f; struct Vector3f{ float x; float y; float z; }vec3d; //クォータニオン構造体 struct Quaternion{ float w; float x; float y; float z; }qua; //マトリクス構造体 struct MATRIX { union { struct { float _11, _12, _13, _14; float _21, _22, _23, _24; float _31, _32, _33, _34; float _41, _42, _43, _44; }; float mat_4x4[4][4]; float mat_16[16]; }; MATRIX(){//単位行列に初期化 for(int i=0;i 16;i++){ this- mat_16[i]=0; } this- _11=this- _22=this- _33=this- _44=1; } void PRINT(char* text){ printf( %s\n%f,%f,%f,%f\n%f,%f,%f,%f\n%f,%f,%f,%f\n%f,%f,%f,%f\n\n , text, this- _11,this- _21,this- _31,this- _41, this- _12,this- _22,this- _32,this- _42, this- _13,this- _23,this- _33,this- _43, this- _14,this- _24,this- _34,this- _44); } }; //任意軸回転をクォータニオンにする Quaternion RotateToQuaternion(Vector3f vAxis,float Angle) { Quaternion q; float radian = (float)(Angle * (PAI / 180.0) / 2.0); float s = sin(radian); q.w=cos(radian); q.x=vAxis.x*s; q.y=vAxis.y*s; q.z=vAxis.z*s; return q; } //クォータニオンを回転行列にする MATRIX QuaternionToMatrix(Quaternion q){ MATRIX ret; float sx = q.x * q.x; float sy = q.y * q.y; float sz = q.z * q.z; float cx = q.y * q.z; float cy = q.x * q.z; float cz = q.x * q.y; float wx = q.w * q.x; float wy = q.w * q.y; float wz = q.w * q.z; ret._11= 1.0f - 2.0f * (sy + sz); ret._12= 2.0f * (cz + wz); ret._13= 2.0f * (cy - wy); ret._21= 2.0f * (cz - wz); ret._22= 1.0f - 2.0f * (sx + sz); ret._23= 2.0f * (cx + wx); ret._31= 2.0f * (cy + wy); ret._32= 2.0f * (cx - wx); ret._33= 1.0f - 2.0f * (sx + sy); ret._41= 0.0f; ret._42= 0.0f; ret._43= 0.0f; return ret; } //回転行列をクォータニオンにする Quaternion MatrixToQuaternion(MATRIX mat){ Quaternion q; float s; float tr = mat._11 + mat._22 + mat._33 + 1.0f; if (tr = 1.0f) { s = 0.5f / sqrt(tr); q.w= 0.25f / s; q.x= (mat._23 - mat._32) * s; q.y= (mat._31 - mat._13) * s; q.z= (mat._12 - mat._21) * s; return q; }else{ float max; if(mat._22 mat._33){ max = mat._22; }else{ max = mat._33; } if (max mat._11) { s = sqrt(mat._11 - (mat._22 + mat._33) + 1.0f); float x = s * 0.5f; s = 0.5f / s; q.x= x; q.y= (mat._12 + mat._21) * s; q.z= (mat._31 + mat._13) * s; q.w= (mat._23 - mat._32) * s; return q; }else if (max == mat._22) { s = sqrt(mat._22 - (mat._33 + mat._11) + 1.0f); float y = s * 0.5f; s = 0.5f / s; q.x= (mat._12 + mat._21) * s; q.y= y; q.z= (mat._23 + mat._32) * s; q.w= (mat._31 - mat._13) * s; return q; }else{ s = sqrt(mat._33 - (mat._11 + mat._22) + 1.0f); float z = s * 0.5f; s = 0.5f / s; q.x= (mat._31 + mat._13) * s; q.y= (mat._23 + mat._32) * s; q.z= z; q.w= (mat._12 - mat._21) * s; return q; } } } //球面線形補間 Quaternion Spherical_Linear_Interpolation( Quaternion q1, Quaternion q2, float t) { Quaternion q; float qr = q1.w * q2.w + q1.x * q2.x + q1.y * q2.y + q1.z * q2.z; float ss = 1.0f - qr * qr; if (ss == 0.0f) { q.w = q1.w; q.x = q1.x; q.y = q1.y; q.z = q1.z; return q; } else { float sp = sqrt(ss); float ph = acos(qr); float pt = ph * t; float t1 = sin(pt) / sp; float t0 = sin(ph - pt) / sp; q.w = q1.w * t0 + q2.w * t1; q.x = q1.x * t0 + q2.x * t1; q.y = q1.y * t0 + q2.y * t1; q.z = q1.z * t0 + q2.z * t1; return q; } } MATRIX model; void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, WIDTH, HEIGHT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //視野角,アスペクト比(ウィンドウの幅/高さ),描画する範囲(最も近い距離,最も遠い距離) gluPerspective(30.0, (double)WIDTH / (double)HEIGHT, 1.0, 1000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(36.8f,1.0f,0.0f,0.0f); glGetFloatv(GL_MODELVIEW_MATRIX, model.mat_16[0]); Quaternion q1=MatrixToQuaternion(model); glLoadIdentity(); glRotatef(240.4f,0.0f,1.0f,0.0f); glGetFloatv(GL_MODELVIEW_MATRIX, model.mat_16[0]); Quaternion q2=MatrixToQuaternion(model); Quaternion q3=Spherical_Linear_Interpolation(q1,q2,t); MATRIX mat=QuaternionToMatrix(q3); glLoadIdentity(); gluLookAt(0.0,500.0,500.0, 0.0,0.0,0.0, 0.0,1.0,0.0); glMultMatrixf( mat.mat_16[0]); glMaterialfv(GL_FRONT, GL_DIFFUSE, yellow); glutSolidCube(150.0); glutSwapBuffers(); } void idle(void) { glutPostRedisplay(); } void Init(){ glClearColor(0.3f, 0.3f, 0.3f, 1.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } void timer(int value) { if(t 1.0f)flag=false; if(t 0.0f)flag=true; if(flag){t+=0.01f;}else{t-=0.01f;} glutTimerFunc(10 , timer , 0); } int main(int argc, char *argv[]) { glutInitWindowPosition(100, 100); glutInitWindowSize(WIDTH, HEIGHT); glutInit( argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutCreateWindow( 球面線形補間 ); glutDisplayFunc(display); glutIdleFunc(idle); glutTimerFunc(10 , timer , 0); Init(); glutMainLoop(); return 0; }
https://w.atwiki.jp/sampleisbest/pages/231.html
開発環境 Microsoft Visual C# 2010 Express (SP1) 実行環境 Microsoft Windows XP Home Edition (SP3) プロジェクトの種類 Windows Game (4.0) プロジェクト名 XnaSphere Game1.cs // XnaSphere5 - 再帰分割slerp+index using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace XnaSphere { class Game1 Game { GraphicsDeviceManager graphics; SpriteBatch sprite; SpriteFont font; BasicEffect effect; VertexBuffer vertexBuffer; IndexBuffer indexBuffer; List VertexPositionColor vtxList = new List VertexPositionColor (); List short idxList = new List short (); const int level = 4; // fps int sec; int draw = 0; int fps = 0; // カメラ int camLat = 0; int camLong = 90; float camDist = 5; public Game1() { graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; Content.RootDirectory = "Content"; IsMouseVisible = true; } protected override void LoadContent() { font = Content.Load SpriteFont ("SpriteFont1"); sprite = new SpriteBatch(GraphicsDevice); effect = new BasicEffect(GraphicsDevice); //effect.EnableDefaultLighting(); effect.Projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45), GraphicsDevice.Viewport.AspectRatio, 1, 100); // 頂点バッファ Vector3[] pos = { Vector3.Up, Vector3.Right, Vector3.Backward, Vector3.Left, Vector3.Forward, Vector3.Down }; int[] idx = { 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 1, 5, 2, 1, 5, 3, 2, 5, 4, 3, 5, 1, 4 }; for (int n = 0; n idx.Length; n += 3) { GenerateTriangle(level, pos[idx[n]], pos[idx[n + 1]], pos[idx[n + 2]]); } vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), vtxList.Count, BufferUsage.WriteOnly); vertexBuffer.SetData(vtxList.ToArray()); indexBuffer = new IndexBuffer(GraphicsDevice, typeof(short), idxList.Count, BufferUsage.WriteOnly); indexBuffer.SetData(idxList.ToArray()); base.LoadContent(); } void GenerateTriangle(int lv, Vector3 p1, Vector3 p2, Vector3 p3) { if (lv-- = 0) { AddVertex(p1); AddVertex(p2); AddVertex(p3); return; } Vector3 p4 = QV(Quaternion.Slerp(new Quaternion(p1, 0), new Quaternion(p2, 0), 0.5f)); Vector3 p5 = QV(Quaternion.Slerp(new Quaternion(p2, 0), new Quaternion(p3, 0), 0.5f)); Vector3 p6 = QV(Quaternion.Slerp(new Quaternion(p3, 0), new Quaternion(p1, 0), 0.5f)); GenerateTriangle(lv, p1, p4, p6); GenerateTriangle(lv, p2, p5, p4); GenerateTriangle(lv, p3, p6, p5); GenerateTriangle(lv, p4, p5, p6); } void AddVertex(Vector3 pos) { for (int n = 0; n vtxList.Count; n++) { if ((pos - vtxList[n].Position).Length() 0.00001f) { idxList.Add((short)n); return; } } vtxList.Add(new VertexPositionColor(pos, (vtxList.Count 1) == 0 ? Color.Red Color.Yellow)); idxList.Add((short)(vtxList.Count - 1)); } Vector3 QV(Quaternion q) { return new Vector3(q.X, q.Y, q.Z); } protected override void Update(GameTime gameTime) { KeyboardState kState = Keyboard.GetState(); if (kState.IsKeyDown(Keys.Escape)) Exit(); if (kState.IsKeyDown(Keys.Up)) camLat = Math.Min(camLat + 1, 89); if (kState.IsKeyDown(Keys.Down)) camLat = Math.Max(camLat - 1, -89); if (kState.IsKeyDown(Keys.Left)) camLong = (camLong + 1) % 360; if (kState.IsKeyDown(Keys.Right)) camLong = (camLong + 359) % 360; if (kState.IsKeyDown(Keys.PageUp)) camDist -= 0.1f; if (kState.IsKeyDown(Keys.PageDown)) camDist += 0.1f; base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.DepthStencilState = DepthStencilState.Default; // カメラ位置 float rad = MathHelper.ToRadians(camLat); float y = (float)Math.Sin(rad) * camDist; float r = (float)Math.Cos(rad) * camDist; rad = MathHelper.ToRadians(camLong); float x = (float)Math.Cos(rad) * r; float z = (float)Math.Sin(rad) * r; effect.View = Matrix.CreateLookAt(new Vector3(x, y, z), Vector3.Zero, Vector3.Up); GraphicsDevice.SetVertexBuffer(vertexBuffer); GraphicsDevice.Indices = indexBuffer; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { GraphicsDevice.RasterizerState = new RasterizerState { FillMode = FillMode.WireFrame }; effect.World = Matrix.CreateTranslation(-1, 0, 0); effect.VertexColorEnabled = false; pass.Apply(); GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexBuffer.VertexCount, 0, indexBuffer.IndexCount / 3); GraphicsDevice.RasterizerState = new RasterizerState { FillMode = FillMode.Solid }; effect.World = Matrix.CreateTranslation(1, 0, 0); effect.VertexColorEnabled = true; pass.Apply(); GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexBuffer.VertexCount, 0, indexBuffer.IndexCount / 3); } // fps draw++; if (gameTime.TotalGameTime.Seconds != sec) { fps = draw; draw = 0; sec = gameTime.TotalGameTime.Seconds; } sprite.Begin(); string text = String.Format( "fps={0} lat={1} long={2} dist={3 f1}", fps, camLat, camLong, camDist); sprite.DrawString(font, text, new Vector2(0, 0), Color.White); text = String.Format("lv={0} vtx={1} idx={2}", level, vertexBuffer.VertexCount, indexBuffer.IndexCount); sprite.DrawString(font, text, new Vector2(0, 20), Color.White); sprite.End(); base.Draw(gameTime); } } }
https://w.atwiki.jp/earthquakeinfo_en/pages/17.html
IF YOU NEED TO EVACUATE This is a summary information from a website (Japanese). http //i.2chblog.jp/archives/2389640.html Please note that these information below is not an official government statement. If you feel your house is not safe and need to evacate, please bring items as follows - Essentials Cash, Banks passbooks (Deposit book) and your passport and a radio with batteries if you can. Plastic bags to carry rubbish, and a plastic bottle to get water. Plastic wrap - you can use on the plates for food to save water, and you can treat your injuries such as to stop bleeding etc Cushion - use as a pillow, and use as a protection of your head Good shoes are better Use your bicycle rather than a car. You can avoid the traffic jam, and also it helps for emergency services. Carrying plastic bag and plastic wrap are highly recommended. If you can carry a cushion, that would be very helpful. Please watch out your feet and protect your head. Also, if you are in dying needs of water and cannot get hold of any, covering any plant or tree leaves overnight with plastic leaves will cause evaporation from the leaves to precipitate in the plastic bag, and you will have drinkable water. The entrance of the bag should be airtight with rubberbands etc. EVACUATION LOCATIONS TOKYO Tokyo Tokyo(on Google Maps) http //bit.ly/f07dPg
https://w.atwiki.jp/unitymemo/pages/67.html
弾(ミサイル)にスクリプトをaddしておく。 targetが敵のGameObject スムーズに敵の方へ回転し、transform.forward * speedだけ進む 敵との距離が0.1f以内になれば、敵に対して被弾処理を行う 敵が消滅している場合は自分も消滅する void Update () { if(target) { transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.transform.position - transform.position), 3f); transform.position += transform.forward * speed; if( Vector3.Distance( transform.position , target.transform.position ) =0.1f ) { if( target.GetComponent Enemy () ) { target.GetComponent Enemy ().takeDamage(atk); } GameObject.Destroy(this.gameObject); } } else { GameObject.Destroy(this.gameObject); } }