Blog Code Forum

WebGL:WordPress

From Wiki.cyring.fr

(Difference between revisions)
Jump to: navigation, search
(functions.php)
Line 5: Line 5:
function gPrimitive( $atts ) {
function gPrimitive( $atts ) {
extract(shortcode_atts(array(
extract(shortcode_atts(array(
-
'gid' => 'cube.00000000',
+
'id' => 'canvas.00000000',
-
'vertices' => '
+
-
-0.5, -0.5, -0.5, // d
+
-
+0.5, -0.5, -0.5, // c
+
-
-0.5, +0.5, -0.5, // a
+
-
+0.5, +0.5, -0.5, // b
+
-
-0.5, -0.5, +0.5, // h
+
-
+0.5, -0.5, +0.5, // g
+
-
-0.5, +0.5, +0.5, // e
+
-
+0.5, +0.5, +0.5 // f
+
-
',
+
-
'indices' => '
+
-
0, 1, 3, 2, // d c b a
+
-
0, 4, 6, 2, // d h e a
+
-
0, 4, 5, 1, // d h g c
+
-
1, 5, 7, 3, // c g f b
+
-
3, 2, 6, 7 // b a e f
+
-
',
+
-
'colors' =>
+
-
'[
+
-
[1.0, 0.0, 0.0, 1.0], // Front face
+
-
[1.0, 1.0, 0.0, 1.0], // Back face
+
-
[0.0, 1.0, 0.0, 1.0], // Top face
+
-
[1.0, 0.5, 0.5, 1.0], // Bottom face
+
-
[1.0, 0.0, 1.0, 1.0], // Right face
+
-
[0.0, 0.0, 1.0, 1.0]  // Left face
+
-
]',
+
'style' => '',
'style' => '',
'width' => '640',
'width' => '640',
Line 42: Line 16:
$main = '<script type="text/javascript">'
$main = '<script type="text/javascript">'
-
. 'main("' . $gid . '",[' . $vertices . '],[' . $indices . '],' . $colors . ',' . $rgba .  ');'
+
. 'main("' . $id . '",' . $rgba .  ');'
. '</script>';
. '</script>';
$output = sprintf( '%s<canvas id="%s" style="%s" width="%s" height="%s"></canvas>%s',
$output = sprintf( '%s<canvas id="%s" style="%s" width="%s" height="%s"></canvas>%s',
-
    $output,     $gid,     $style,    $width,    $height,     $main );
+
    $output,     $id,       $style,    $width,    $height,     $main );
return($output);
return($output);
}
}

Revision as of 23:07, 9 February 2013

functions.php

  1. <?php
  2.  
  3. function gPrimitive( $atts ) {
  4. 	extract(shortcode_atts(array(
  5. 		'id'		=> 'canvas.00000000',
  6. 		'style'		=> '',
  7. 		'width'		=> '640',
  8. 		'height'	=> '540',
  9. 		'rgba'		=> '0.0, 0.0, 0.0, 1.0'), $atts));
  10.  
  11.  
  12. 	$output	= '<script type="text/javascript" src="' . get_stylesheet_directory_uri() . '/glMatrix-min.js"></script>'
  13. 		. '<script type="text/javascript" src="' . get_stylesheet_directory_uri() . '/primitive.js"></script>';
  14.  
  15. 	$main	= '<script type="text/javascript">'
  16. 		. 'main("' . $id . '",' . $rgba .  ');'
  17. 		. '</script>';
  18.  
  19. 	$output	= sprintf( '%s<canvas id="%s" style="%s" width="%s" height="%s"></canvas>%s',
  20. 			    $output,     $id,       $style,    $width,     $height,      $main );
  21. 	return($output);
  22. }


  1. function twentyten_setup() {
  2. 	add_shortcode( 'primitive', 'gPrimitive' );
  3. }
  4.  
  5. ?>
Personal tools