Bezier curves : part III

posted on 21 Dec 2007 01:13 by xnanoob  in Math, Tutorials

เช่า อพาร์ตเมนต์ ห้องเช่า รายเดือน พหลโยธิน 24
โคสะนา : บริการห้องเช่า อพาร์ตเมนต์ ห้องเช่า รายเดือน พหลโยธิน 24 ใกล้เซ็นทรัลลาดพร้าว

สวัสดีค่า

จากเมื่อเย็นๆ ตัวอย่างที่แล้วได้ลองใช้ ไดร์ชู๊ตแบบ 2D เลื่อน sprite หรือใครอยากดูการ

"วางบอลแบบเทพ"  เพื่อให้เห็นภาพ กด ตรงนี้นะ

  
ภาพ แสดงไดร์ซู๊ตของซึบาสะ

แบบยังไงดีนะ ตัวอย่างที่แล้วไม่มีแกน Z
ทำให้ไดร์ซู๊ตออกจะแบนๆ หน่อย


[แบบว่าชอบรูปนี้ เลยเอามาลงอีกรอบ]



ภาพ แสดงไดร์ซู๊ตของซึบาสะ


ก้อเลยอยากได้ไดร์ซู๊ตแบบ 3D น่าจะสวยขึ้นอะ

Quadratic Bézier curves
  กันอีกรอบ

ก้องงๆ ว่า เบเซียร์จะใช้กับ 3D ได้ไหม เพราะในวิกิอ่านไม่ค่อยจาเข้าจาย

แต่ก้อไปมั่วๆ จากสมการด้านบน เรียกง่ายๆ ว่าสมการเอาไว้ทำไดร์ซู๊ตนะงิ

แปลงร่างได้เป็น code แบบลูกทุ่งๆ ดังนี้นะค่ะ

 // quadratic bezier curve
public Vector3 Quad(Vector3 pos1, Vector3 pos2, Vector3 pos3, float t) { return (1 - t) * (1 - t) * pos1 + 2 * t * (1 - t) * pos2 + t * t * pos3;

}


จังหวะแสดงผล

 

Model ball = Content.Load<Model>(@"ball");

โหลดโมเดลมาก่อนนะค่ะ

  graphics.GraphicsDevice.Clear( Color.CornflowerBlue );

 

// Copy any parent transforms.

Matrix[] transforms = new Matrix[ball.Bones.Count];

ball.CopyAbsoluteBoneTransformsTo( transforms );

// Draw the model. A model can have multiple meshes, so loop.

foreach (ModelMesh mesh in ball.Meshes)

{

// This is where the mesh orientation is set, as well as our camera and projection.

foreach (BasicEffect effect in mesh.Effects)

{

effect.EnableDefaultLighting();

effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY( modelRotation ) * Matrix.CreateTranslation( modelPosition ); effect.View = Matrix.CreateLookAt( cameraPosition, Vector3.Zero, Vector3.Up );

 

effect.Projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians( 45.0f ),

aspectRatio, 1.0f,100.0f );

}

// Draw the mesh, using the effects set above.

mesh.Draw();

}


แสดงผลโมเดล

ผลการทดลอง

อะนะ ปั่นคล้ายพี่เบ็คเลยเว้ย กู

อย่างไรถ้าพวกเกมส์ยิงจรวด แบบขีปนาวุธ วิ่งใส่ศัตรู ตัวนี้ก้อน่าจะทำให้ชีวิตง่ายขึ้น(มั่ง)

เฮือก  จบแระค่ะ

บายค่ะ งุงิ งุงิ

ปล. สำหรับ เรื่องโหลด model 3d ดูได้ตรงนี้มั่งนะ

บริการ : เช่าห้องอบรม ห้องสัมนา อบรมคอมพิวเตอร์ กด เลยนะค่ะ

Comment



smilebig smileopen-mounthed smileconfused smilesad smileangry smiletonguequestionembarrassedsurprised smilewinkdouble winkcry