수안이의 컴퓨터 연구실

  • Mainpage
  • About Me
  • Tags
  • Metapage
  • Notice
  • Location
  • Keywords
  • Guestbook
  • Admin
  • Write an Article
  • Total | 1620959
  • Today | 339
  • Yesterday | 482

Web/Silverlight2007/07/10 10:38

SilverLight Introduction

출처 : http://www.codeproject.com/silverlight/silverlightintro.asp

3D Graphics in SilverLight

SilverLight Showing 3D Graphics (Rotating and Mouse-interactive) in Browser.

Introduction: What is SilverLight?

Alright, so you already heard a lot about SilverLight launch and that it is a Adobe Flash competitor etc. So I thought I would share some of my experiences with its early days. This article is a very basic introduction of what SilverLight is and shows one example of using 3D graphics in SilverLight.

So primarily Microsoft SilverLight is a development platform with the following key features:

  • Browser Plugin compatible with Mozilla Firefox, Apple Safari, Microsoft Internet Explorer, Opera
  • Supports ActiveX Wrapper Interfaces - so you can embed it in legacy applications

SilverLight Integrates with Browser

SilverLight Integrates with Browser. © suchit-tiwari.org

There are some more important features of SilverLight:

  • Incorporates Windows Presentation Foundation Core
  • Contains CLR (Common Language Runtime) and most important base classes from the .NET Framework
  • Supports programming in C#, VB, JScript, Ruby, Python
  • Embeds Communication Framework including WCF (Windows Communication Framework)
  • Comes with Data Framework including LINQ

In a nutshell, SilverLight can be modeled as a tetra-hedron with the following components.

SilverLight Tetra-hedron

SilverLight Tetra-hedron. © suchit-tiwari.org

For a more detailed component view, refer to the following pictorial overview of SilverLight. The MSDN site has a high resolution poster available.

SilverLight Developer Reference

SilverLight Developer Reference (Source: Microsoft MSDN Site)

What do you need to run this code?

You will need to install Microsoft SilverLight developer release from SilverLight Downloads.

  • Unzip the sources in a folder
  • Browse srtSilverLight.htm

3D Graphics Introduction

Now before we jump into explanation of the code, let's understand some basics of 3D graphics. The world in which we live is 3D. The computer screen in 2D. So when we have to visualize a 3D world on a 2D computer screen, we need to "take care" of the extra dimension. This "taking care" is called projection. The projections can be done using a Synthetic Camera Model.

In brief, the Synthetic Camera model assumes a virtual camera in a 3D world. The camera film is the computer screen. And whenever we take a picture using that camera, the picture on the film needs to be mapped onto the computer screen. The following figure shows this.

Synthetic Camera Model

Synthetic Camera Model. © suchit-tiwari.org

SilverLight provides a transformation matrix to achieve this camera modeling. The camera location is also called Point Of View (POV). Setting different POVs over a period of time can create beautiful animations. The film directors do that very nicely by swinging cameras over the cars and out of home windows. While you program this 3D world, it is pretty much like playing the director of the movie!

For a more detailed overview of Synthetic Camera Model, you can refer to this white paper.

Now let's understand how the 3D objects are represented in virtual world. There are many different ways of modeling 3D objects - polygonal, parametrics, procedural. These advanced topics are beyond the scope of this article. We will assume the polygonal modeling. Refer to the figure below.

3D Objects Representation

3D Objects Representation. © suchit-tiwari.org

The objects can be seen as made up of the vertices and their connecting edges that form the faces or polygons of the object. When we enter the code, you will understand how this modeling is done in SilverLight.

To understand 3D modeling theory, do the following:

  • Download eLearning Player
  • Save 3D Modeling Lecture on the local machine
  • Double click to Open/Play this local lecture

Code Explanation

Let's start with embedding SilverLight into your web page. Making this embedding cross-browser compatible is the crux of the starting step. This is simplified by reusing SilverLight.js script in the \js sub-folder. This file basically creates an HTML block for various browsers and creates the SilverLight object. Look for:

var AgControl = new ActiveXObject("AgControl.AgControl");

An XAML model is associated with this SilverLight object. This XAML file contains a shape definition for one ball object. This ball object is replicated for multiple instances.

File: srtSilverLight.htm
<body>
<div id="wpfe">
<div id="wpfeHost" class="host"> </div>
<script type="text/javascript">

Sys.Silverlight.createObjectEx(
{
source: 'assets/ball_n.xaml',
parentElement: document.getElementById("wpfeHost"),
id: 'wpfeBlock',
properties:
{
width:'500',
height:'500',
background:'white',
. . .
. . .

Once the SilverLight object is created, it is time to initialize the virtual world. Since the XAML model is associated with this scene, using JavaScript in SilverLight, you can extract individual XAML objects and create your JavaScript objects that are based on these XAML objects.

The following code creates the 4 balls around the Teta-hedron.

. . .
this._ballsO[0] = new WPFEBall(this._wpfeBlock, "wpfe_ball_0");

for (var i=1; i<this._N; i++)
this._ballsO[i] = this._ballsO[0].clone("wpfe_ball_" + i);
. . .

And the Teta-hedron is created using 3D modeling theory (with faces/polygons).

. . .
wall = new WPFEFace(this_._wpfeBlock, wpfeRoot,
[
[this.minx, 0, 0],
[this.maxx, 0, 0],
[(this.minx+this.maxx)/3, this.maxy*Math.tan(60*Math.PI/180)/3,
this.maxx*Math.tan(60*Math.PI/180)]
]
);
wall._elem.fill = "#99FF0000";
model.walls.shapes.push(wall);
. . .

The mathematics behind the tan(60), sin(6) etc is simple. It just calculates the lengths of the front and adjacent sides of the polygonal patches. Since Teta-hedron is based on an equilateral triangle, the angle of 60 appears in the code.

The mouse-drag-3D-rotate operation is standard JavaScript combined with POV.

function onMouseMove(sender, eventArgs)
{
if (!mouseData) return;
var pt = eventArgs.getPosition(null);
var dy = (pt.y - mouseData.e.y)/200;
var dx = (pt.x - mouseData.e.x)/200;
_wpfeTest.setPOV(mouseData.start.z + dy, mouseData.start.y + dx);
}

The changes in the POV cause the 3D view to be changed.

And that's it. Refer to the JavaScript and excellent OOP code by Alexey Gavrilov in the \js folder.

Resources

  • Microsoft SilverLight Downloads
  • Mix 2007 SilverLight Overview
  • Microsoft WCF
  • Microsoft LINQ
  • How 3D is Viewed on 2D Computer Screen?
  • 3D Objects Representation

Credits

The code from this article is based on a nice example from http://bubblemark.com/3d/silverlight1.1.htm.

Hope you enjoyed knowing a bit of SilverLight in this article. If you have any questions or suggestions, please post them here or drop me a line at srt@Suchit-Tiwari.Org or Suchit.Tiwari@Ge.com Your suggestions and comments are most welcome.

About .Suchit


Suchit is an Architect at GE India Innovation Center, Hyderabad.

He is the Architect of OPC Server for hardware devices of GE Sensing. These devices sense temperature, humidity, combustibles, fluid flow, pressure and various engineering parameters - primarily used in Industrial Automation & Process Control applications.

Interests: Computer Graphics, Mathematical Modeling, Scientific Applications Development.

He lives in Hyderabad India with his wife and 2 kidbots. Loves reading books if these 2 small buddies allow him to.

Homepage : http://www.Suchit-Tiwari.Org

Click here to view .Suchit's online profile.

"Silverlight" 카테고리의 다른 글
  • SilverLight Introduction (0)2007/07/10
  • Silverlight Architecture Overview (0)2007/06/21
  • Microsoft Silverlight 1.1 Development Reference (0)2007/05/03
2007/07/10 10:38 2007/07/10 10:38
Posted by webdizen
Tags Silverlight
No Trackback No Comment

Trackback URL : http://www.webdizen.net/blog/trackback/3071

Leave your greetings.

[로그인][오픈아이디란?]

«Prev  1 ... 177 178 179 180 181 182 183 184 185 ... 2998  Next»

RSS HanRSS
Blog Image
webdizen
이 곳은 컴퓨터에 대해 연구하고, 공유하고, 소통하기 위한 연구실입니다. 개인적으로는 OLAP, Data Mining, Semantic Web, Data Modeling에 대해서 연구하고 있습니다.

Categories

전체 (2998)
Webdizen (134)
Life (6)
Diary (16)
Blog (9)
IDEA (1)
Travel (10)
Book (14)
Photo (7)
Movie (7)
Music (13)
Leisure Sports (10)
Funny (5)
Hardware (119)
Software (120)
Windows (5)
Unix & Linux (119)
Installation (4)
Kernel (10)
System (34)
Develop (22)
X-Window (0)
Applicaton (31)
Security (4)
Framework (2)
Hadoop (2)
Programming (805)
Algorithm & Data Structure (1)
Assembly (38)
UNIX/Linux C (95)
C++ (128)
STL (4)
Java (38)
Win32 API (92)
ATL/COM (44)
MFC (151)
.NET (26)
WCF/WPF (4)
C# (28)
Network Programming (17)
Database Programming (12)
OpenGL / DirectX (13)
Multimedia Programming (0)
Game Programming (21)
Parallel Distributed Progra... (0)
Reverse Engineering (0)
Debugging (9)
Python (1)
Ruby (1)
Ruby on Rails (1)
QT (4)
GTK (0)
JSP (0)
PHP (6)
ASP.NET (6)
ASP (3)
Development (28)
Useful Library (2)
Data Modeling (0)
Database (105)
Oracle (4)
MSSQL (41)
MySQL (2)
Data Warehouse (2)
Data Mining (3)
Network (66)
Web (78)
DHTML (4)
XHTML (1)
Javascript (1)
CSS (1)
AJAX (9)
XML (11)
Flex (1)
Silverlight (3)
Security (91)
DoS (1)
Kernel (10)
Scanning (3)
Sniffing (0)
Spoofing (4)
Overflow (28)
Web (11)
Shell (10)
Format String (14)
Window (2)
Embedded (70)
Multimedia (27)
Mobile (14)
Graphic (24)
Management (633)
Knowledge (581)
Hadoop (0)

Notice

  • 메타 블로그 사이트에 등록
  • 새해 맞이 블로그의 변화
  • 블로그 명칭 변경
  • 도메인(www.webdizen.net) 구...
  • TEXTCUBE 1.6.1로 업그레이드...

Tags

  • 작업표시줄
  • INI
  • PHP
  • Website
  • 슬로코도
  • 화면 정보
  • 마주앙 스페셜
  • 윈져 프리미엄
  • Multi-Processor
  • 부론고등학교
  • 형상화
  • Browser detection
  • 객체 지향 모델링
  • 대학원
  • 천지관
  • ActionScript
  • 자연과학대학
  • AS400
  • Labs
  • 제2기숙사

Recent Articles

  • ASCII Code의 CRLF 제거 방법.
  • Hadoop 에서 c++ API 이용시....
  • Ubuntu Linux에서 Hadoop 구....
  • 내 심장을 한껏 뛰게한 "국가....
  • 스타 스키마 데이터베이스 설....

Recent Comments

  • ■ 온라인카지노 ▶ http://L....
    asdf 11/21
  • 그리고 혹시 해외여행자보험....
    kim 11/05
  • ★★실제 바다게임장과 똑같....
    asdf 11/04
  • sbsyama.co.to← 짱5000만당....
    asdf 11/04
  • ♡KicaZ??o(???) 바카라사....
    fdsf3fass 11/03

Recent Trackbacks

  • 파일 열기/저장하기 CFileDialog.
    은마군의 나태블록 02/11
  • World IT Show 2008.
    상우 :: Oranzie's BLOG 2008
  • cvs서버 설치하기.
    3인3색 2008
  • 속속 공개되는 Google Chart....
    PHP와 Web 2.0 2007
  • 마방진을 구하는 프로그램.
    Oranzie's BLOG 3 2007

Archive

  • 2009/09 (3)
  • 2009/08 (1)
  • 2009/03 (1)
  • 2009/02 (9)
  • 2009/01 (13)

Calendar

«   2009/11   »
일 월 화 수 목 금 토
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          

Bookmarks

    • Administration
      • IIS.NET
      • NTFAQ
      • OS의 모든 것
      • 리눅스포털
    • Database
      • SQL Server Central
      • SQL Team
    • Development
      • .NET Heaven
      • ASP Alliance
      • ASP.NET 2.0
      • Bullog.net
      • C# Corner
      • C++ (C PlusPlus.com)
      • C++ Reference
      • CodeGuru
      • CodePlex
      • DebugLab
      • Dev Articles
      • Devpia
      • DotNet Junkies
      • DotNet Zone
      • Driver Online
      • GOSU.NET
      • HOONS 닷넷
      • Joinc 팀블로그
      • KOSR
      • MSDN Home Page
      • OSR Online
      • Sky.ph - 개발자 커뮤니...
      • TAEYO.NET
      • The Code Project
      • WindowsClient.net
      • 김상욱의 개발자 Side
      • 조인시 위키
    • Human Networks
      • belief21c's e-space
      • I think I can
      • Invisible Rover's Blog :D
      • Rodman®
      • ■ Feel So Good~! ■
      • 까만 나비
      • 나를 가꾸는 시간.
      • 나만의 즐거움~~!
      • 단녕
      • 상우 :: Oranzie's BLOG
    • Information Technology
      • Microsoft TechNet
      • 지디넷코리아 - 글로벌...
    • Security
      • FoundStone
      • milw0rm
      • NewOrder
      • OpenRCE
      • Phrack.org
      • Reverse Engineering b1...
      • Reverse Engineering Team
      • RootKit
      • SecurityFocus
      • SecurityXploded by Nag...
      • Wow Hacker
      • Zone-H
Textcube
Louice Studio Inc.
Powered by Textcube. Original designed by Tistory.